diff options
Diffstat (limited to 'clients')
-rw-r--r-- | clients/zctl/zctl.c | 238 | ||||
-rw-r--r-- | clients/zctl/zctl_cmds.ct | 10 |
2 files changed, 246 insertions, 2 deletions
diff --git a/clients/zctl/zctl.c b/clients/zctl/zctl.c index e48a651..9624550 100644 --- a/clients/zctl/zctl.c +++ b/clients/zctl/zctl.c @@ -660,6 +660,10 @@ load_subs(int argc, char *argv[]) { ZSubscription_t subs[SUBSATONCE],subs2[SUBSATONCE],unsubs[SUBSATONCE]; +#ifdef CMU_ZCTL_PUNT + ZSubscription_t punts[SUBSATONCE]; + int pind; +#endif FILE *fp; int ind,unind,lineno,i,retval,type; short wgport; @@ -695,7 +699,10 @@ load_subs(int argc, return; } - ind = unind = 0; +#ifdef CMU_ZCTL_PUNT + pind = +#endif + ind = unind = 0; lineno = 1; for (;;lineno++) { @@ -721,6 +728,11 @@ load_subs(int argc, if (*subline == '!') printf("(Un-subscription) Class %s instance %s recipient %s\n", subline+1, comma+1, comma2+1); +#ifdef CMU_ZCTL_PUNT + else if(*subline == '-') + printf("(Punted) Class %s instance %s recipient %s\n", + subline+1, comma+1, comma2+1); +#endif else printf("Class %s instance %s recipient %s\n", subline, comma+1, comma2+1); @@ -746,7 +758,27 @@ load_subs(int argc, /* XXX check malloc return */ (void) strcpy(unsubs[unind].zsub_recipient,comma2+1); unind++; - } else { + } else +#ifdef CMU_ZCTL_PUNT + if (*subline == '-') { /* a punt */ + if (type == UNSUB) + continue; + punts[pind].zsub_class = + (char *)malloc((unsigned)(strlen(subline)+1)); + /* XXX check malloc return */ + (void) strcpy(punts[pind].zsub_class,subline+1); + punts[pind].zsub_classinst = + (char *)malloc((unsigned)(strlen(comma+1)+1)); + /* XXX check malloc return */ + (void) strcpy(punts[pind].zsub_classinst,comma+1); + punts[pind].zsub_recipient = + (char *)malloc((unsigned)(strlen(comma2+1)+1)); + /* XXX check malloc return */ + (void) strcpy(punts[pind].zsub_recipient,comma2+1); + pind++; + } else +#endif + { subs[ind].zsub_class = (char *)malloc((unsigned)(strlen(subline)+1)); /* XXX check malloc return */ @@ -761,6 +793,24 @@ load_subs(int argc, (void) strcpy(subs[ind].zsub_recipient,comma2+1); ind++; } +#ifdef CMU_ZCTL_PUNT + if (pind == SUBSATONCE) { + fix_macros(punts,subs2,pind); + if (retval = ZPunt(subs2,pind,(u_short)wgport) != + ZERR_NONE) + { + ss_perror(sci_idx,retval, + "while punting"); + goto cleanup; + } + for (i=0;i<pind;i++) { + free(punts[i].zsub_class); + free(punts[i].zsub_classinst); + free(punts[i].zsub_recipient); + } + pind = 0; + } +#endif if (ind == SUBSATONCE) { fix_macros(subs,subs2,ind); if ((retval = (type == SUB)? @@ -815,6 +865,18 @@ load_subs(int argc, goto cleanup; } } +#ifdef CMU_ZCTL_PUNT + if (pind) { + fix_macros(punts,subs2,pind); + if (retval = ZPunt(subs2,pind,(u_short)wgport) != + ZERR_NONE) + { + ss_perror(sci_idx,retval, + "while punting"); + goto cleanup; + } + } +#endif } cleanup: for (i=0;i<ind;i++) { @@ -827,6 +889,13 @@ cleanup: free(unsubs[i].zsub_classinst); free(unsubs[i].zsub_recipient); } +#ifdef CMU_ZCTL_PUNT + for (i=0;i<pind;i++) { + free(punts[i].zsub_class); + free(punts[i].zsub_classinst); + free(punts[i].zsub_recipient); + } +#endif (void) fclose(fp); /* ignore errs--file is read-only */ return; @@ -980,3 +1049,168 @@ fix_macros2(char *src, char **dest) if (!strcmp(src,TOKEN_ME)) *dest = ZGetSender(); } + +do_punt(argc, argv) +int argc; +char **argv; +{ +#ifdef CMU_ZCTL_PUNT + char *class, *inst, *recip, *msg, *whoami = argv[0]; + int retval, punt; + short newport; + struct sockaddr_in newsin; + ZNotice_t notice; + + if (! strcmp(whoami, "punt")) punt = 1; + else punt = 0; + + switch (argc) { + case 2: + class = "message"; + inst = argv[1]; + recip = ""; + break; + case 3: + class = argv[1]; + inst = argv[2]; + recip = ""; + break; + case 4: + class = argv[1]; + inst = argv[2]; + recip = argv[3]; + if (*argv[3] == '*') /* fixed so realm punts would work (vs0r) */ + if (*(argv[3]+1) == '@') + if (!strcmp((char *)ZGetRealm(), (char *)ZExpandRealm(argv[3]+2))) + /*check local*/ + recip = ""; + break; + default: + fprintf(stderr, "Usages:\n"); + fprintf(stderr, "\t%s instance\n", whoami); + fprintf(stderr, "\t%s class instance\n", whoami); + fprintf(stderr, "\t%s class instance recipient\n", whoami); + return 1; + } + + retval = ZOpenPort((u_short *) 0); + if(retval != ZERR_NONE) { + com_err(whoami, retval, "while opening Zephyr port."); + return 1; + } + + newsin = ZGetDestAddr(); + if ((newport = ZGetWGPort()) == -1) { + fprintf(stderr, "%s: Can't find windowgram port\n", whoami); + return 1; + } + + newsin.sin_port = (unsigned short) newport; + if ((retval = ZSetDestAddr(&newsin)) != ZERR_NONE) { + com_err(whoami,retval,"while setting destination address"); + return 1; + } + + msg = (char *) malloc(strlen(class) + strlen(inst) + strlen(recip) + 4); + sprintf(msg, "%s%c%s%c%s", class, '\0', inst, '\0', recip); + + if (*recip == '*') + if (*(recip+1) == '@') + if (strcmp(recip+2, (char *)ZExpandRealm(recip+2))) + sprintf(msg, "%s%c%s%c%s", class, '\0', inst, '\0', + (char *)ZExpandRealm(recip+2)); + printf("%s <%s,%s,%s>\n", punt ? "Punting" : "Unpunting", + class, inst, *recip ? recip : "*"); + + memset((char *) ¬ice, 0, sizeof(ZNotice_t)); + notice.z_kind = UNSAFE; + notice.z_class = WG_CTL_CLASS; + notice.z_class_inst = WG_CTL_USER; + notice.z_recipient = ""; + notice.z_default_format = ""; + notice.z_opcode = (punt) ? "SUPPRESS" : "UNSUPPRESS"; + notice.z_port = 0; + notice.z_message = msg; + notice.z_message_len = strlen(class)+strlen(inst)+strlen(recip)+3; + + if ((retval = ZSendNotice(¬ice,ZNOAUTH)) != ZERR_NONE) + fprintf(stderr,"%s: while sending notice\n",whoami); + + free(msg); + + ZClosePort(); +#endif + return 0; +} + +list_punts(argc, argv) +int argc; +char **argv; +{ +#ifdef CMU_ZCTL_PUNT + ZNotice_t notice; + int retval, lensofar; + struct sockaddr_in old, to, from; + u_short ourport, zwgcport; + char *msg; + + ourport=0; + retval = ZOpenPort(&ourport); + if(retval != ZERR_NONE) { + com_err("zctl", retval, "while opening Zephyr port."); + return 1; + } + + old = ZGetDestAddr(); + to = old; + if ((zwgcport = ZGetWGPort()) == (u_short)-1) { + fprintf(stderr, "zctl: Can't find windowgram port\n"); + return 1; + } + + to.sin_port = (u_short) zwgcport; + if ((retval = ZSetDestAddr(&to)) != ZERR_NONE) { + com_err("zctl",retval,"while setting destination address"); + return 1; + } + + memset((char *) ¬ice, 0, sizeof(ZNotice_t)); + notice.z_kind = UNSAFE; + notice.z_class = WG_CTL_CLASS; + notice.z_class_inst = WG_CTL_USER; + notice.z_recipient = ""; + notice.z_default_format = ""; + notice.z_opcode = "LIST-SUPPRESSED" /*USER_LIST_SUPPRESSED*/; + notice.z_port = ourport; + notice.z_message = NULL; + notice.z_message_len = 0; + + if ((retval = ZSendNotice(¬ice,ZNOAUTH)) != ZERR_NONE) + com_err("zctl",retval,"while sending notice"); + + if ((retval = ZReceiveNotice(¬ice,&from)) != ZERR_NONE) + com_err("zctl",retval,"while receiving ack"); + + (void) ZFreeNotice(¬ice); + + if ((retval = ZReceiveNotice(¬ice,&from)) != ZERR_NONE) + com_err("zctl",retval,"while receiving notice"); + + notice.z_auth = ZCheckAuthentication(¬ice, &from); + + if ((retval = ZSetDestAddr(&old)) != ZERR_NONE) { + com_err("zctl",retval,"while resetting destination address"); + return 1; + } + + msg = (char *) malloc((notice.z_message_len+1) * sizeof(char)); + (void) strncpy(msg,notice.z_message, notice.z_message_len); + msg[notice.z_message_len]=(char)0; + printf("%s", msg); + (void) free(msg); + (void) ZFreeNotice(¬ice); + (void) ZClosePort(); + +#endif /* CMU_ZCTL_PUNT */ + return 0; +} diff --git a/clients/zctl/zctl_cmds.ct b/clients/zctl/zctl_cmds.ct index 374effc..2f7bbbb 100644 --- a/clients/zctl/zctl_cmds.ct +++ b/clients/zctl/zctl_cmds.ct @@ -84,5 +84,15 @@ request ss_quit, "Quit.", quit, exit, q; +#ifdef CMU_BACKWARD_COMPAT + request do_punt, "Ignore specified messages.", + punt; + request do_punt, "Stop ignoring specified messages.", + unpunt; + + request list_punts, "List current messages to ignore.", + list_punts, lp; + +#endif end; |