1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It contains code for the "zctl" command.
4 * Created by: Robert French
6 * $Id: zctl.c 2333 2009-03-22 18:30:19Z kcr $
8 * Copyright (c) 1987,1988 by the Massachusetts Institute of Technology.
9 * For copying and distribution information, see the file
14 #include <zephyr/zephyr.h>
20 static const char rcsid_zctl_c[] = "$Id: zctl.c 2333 2009-03-22 18:30:19Z kcr $";
28 #define USERS_SUBS "/.zephyr.subs"
29 #define OLD_SUBS "/.subscriptions"
31 #define TOKEN_HOSTNAME "%host%"
32 #define TOKEN_CANONNAME "%canon%"
33 #define TOKEN_ME "%me%"
34 #define TOKEN_WILD "*"
45 char subsname[BUFSIZ];
46 char ourhost[MAXHOSTNAMELEN],ourhostcanon[MAXHOSTNAMELEN];
48 extern ss_request_table zctl_cmds;
50 int purge_subs(register ZSubscription_t *, int);
51 void add_file(short, ZSubscription_t *, int);
52 void del_file(short, ZSubscription_t *, int);
53 void fix_macros(ZSubscription_t *, ZSubscription_t *, int);
54 void fix_macros2(char *, char **);
55 int make_exist(char *);
63 char ssline[BUFSIZ],oldsubsname[BUFSIZ],*envptr,*tty = NULL;
65 #ifdef HAVE_SYS_UTSNAME
69 if ((retval = ZInitialize()) != ZERR_NONE) {
70 com_err(argv[0],retval,"while initializing");
74 /* Set hostname and tty for locations. If we support X, use the
75 * DISPLAY environment variable for the tty name. */
76 #ifndef X_DISPLAY_MISSING
77 tty = getenv("DISPLAY");
79 if ((retval = ZInitLocationInfo(NULL, tty)) != ZERR_NONE)
80 com_err(argv[0], retval, "initializing location information");
82 envptr = getenv("ZEPHYR_SUBS");
84 strcpy(subsname,envptr);
86 envptr = getenv("HOME");
88 strcpy(subsname,envptr);
90 if (!(pwd = getpwuid((int) getuid()))) {
91 fprintf(stderr,"Who are you?\n");
95 strcpy(subsname,pwd->pw_dir);
97 strcpy(oldsubsname,subsname);
98 strcat(oldsubsname,OLD_SUBS);
99 strcat(subsname,USERS_SUBS);
100 if (!access(oldsubsname,F_OK) && access(subsname, F_OK)) {
101 /* only if old one exists and new one does not exist */
102 printf("The .subscriptions file in your home directory is now being used as\n.zephyr.subs . I will rename it to .zephyr.subs for you.\n");
103 if (rename(oldsubsname,subsname))
104 com_err(argv[0], errno, "renaming .subscriptions");
108 #ifdef HAVE_SYS_UTSNAME
110 strcpy(ourhost, name.nodename);
112 if (gethostname(ourhost,MAXHOSTNAMELEN) == -1) {
113 com_err(argv[0],errno,"while getting host name");
118 if (!(hent = gethostbyname(ourhost))) {
119 fprintf(stderr,"%s: Can't resolve hostname %s; %s may be "
120 "wrong in subscriptions\n",argv[0],ourhost,
122 strncpy(ourhostcanon,ourhost,sizeof(ourhostcanon)-1);
124 strncpy(ourhostcanon,hent->h_name,sizeof(ourhostcanon)-1);
126 sci_idx = ss_create_invocation("zctl","",0,&zctl_cmds,&code);
128 ss_perror(sci_idx,code,"while creating invocation");
135 (void) sprintf(ssline+strlen(ssline),"%s ",argv[i]);
136 ssline[strlen(ssline)-1] = '\0';
137 code = ss_execute_line(sci_idx,ssline);
139 fprintf (stderr, "%s: %s: %s\n",
140 argv[0], error_message (code), ssline);
144 printf("ZCTL $Revision: 2333 $ (Protocol %s%d.%d) - Type '?' for a list of commands.\n\n",
146 ZVERSIONMAJOR,ZVERSIONMINOR);
157 fprintf(stderr,"Usage: %s filename\n",argv[0]);
162 printf("Current file: %s\n",subsname);
164 (void) strcpy(subsname,argv[1]);
168 flush_locations(int argc,
174 fprintf(stderr,"Usage: %s\n",argv[0]);
178 if ((retval = ZFlushMyLocations()) != ZERR_NONE)
179 ss_perror(sci_idx,retval,"while flushing locations");
183 wgc_control(int argc,
188 struct sockaddr_in newsin;
191 newsin = ZGetDestAddr();
194 fprintf(stderr,"Usage: %s\n",argv[0]);
198 if ((newport = ZGetWGPort()) == -1) {
199 ss_perror(sci_idx,errno,"while getting WindowGram port");
203 newsin.sin_port = (u_short) newport;
204 if ((retval = ZSetDestAddr(&newsin)) != ZERR_NONE) {
205 ss_perror(sci_idx,retval,"while setting destination address");
209 (void) memset((char *)¬ice, 0, sizeof(notice));
210 notice.z_kind = UNSAFE;
212 notice.z_class = WG_CTL_CLASS;
213 notice.z_class_inst = WG_CTL_USER;
215 if (!strcmp(argv[0],"wg_read"))
216 notice.z_opcode = USER_REREAD;
217 if (!strcmp(argv[0],"wg_shutdown"))
218 notice.z_opcode = USER_SHUTDOWN;
219 if (!strcmp(argv[0],"wg_startup"))
220 notice.z_opcode = USER_STARTUP;
221 if (!strcmp(argv[0],"wg_exit"))
222 notice.z_opcode = USER_EXIT;
223 if (!notice.z_opcode) {
225 "unknown WindowGram client control command %s\n",
230 notice.z_recipient = "";
231 notice.z_default_format = "";
232 notice.z_message_len = 0;
234 if ((retval = ZSendNotice(¬ice,ZNOAUTH)) != ZERR_NONE)
235 ss_perror(sci_idx,retval,"while sending notice");
237 if ((retval = ZInitialize()) != ZERR_NONE)
238 ss_perror(sci_idx,retval,
239 "while reinitializing");
250 fprintf(stderr,"Usage: %s\n",argv[0]);
254 (void) memset((char *)¬ice, 0, sizeof(notice));
255 notice.z_kind = HMCTL;
257 notice.z_class = HM_CTL_CLASS;
258 notice.z_class_inst = HM_CTL_CLIENT;
260 if (!strcmp(argv[0],"hm_flush"))
261 notice.z_opcode = CLIENT_FLUSH;
262 if (!strcmp(argv[0],"new_server"))
263 notice.z_opcode = CLIENT_NEW_SERVER;
264 if (!notice.z_opcode) {
265 fprintf(stderr, "unknown HostManager control command %s\n",
270 notice.z_recipient = "";
271 notice.z_default_format = "";
272 notice.z_message_len = 0;
274 if ((retval = ZSendNotice(¬ice,ZNOAUTH)) != ZERR_NONE)
275 ss_perror(sci_idx,retval,"while sending notice");
286 fprintf(stderr,"Usage: %s <varname> <varname> ...\n",argv[0]);
290 for (i=1;i<argc;i++) {
291 value = ZGetVariable(argv[i]);
293 printf("%s: %s\n",argv[i],value);
295 printf("%s: not defined\n",argv[i]);
300 set_var(int argc, char *argv[])
302 int retval,setting_exp,i;
303 char *exp_level = NULL;
308 fprintf(stderr,"Usage: %s <varname> [value]\n",
315 if (!strcasecmp(argv[1],"exposure")) {
318 fprintf(stderr,"An exposure setting must be specified.\n");
321 exp_level = (char *)0;
322 if (!strcasecmp(argv[2],EXPOSE_NONE))
323 exp_level = EXPOSE_NONE;
324 if (!strcasecmp(argv[2],EXPOSE_OPSTAFF))
325 exp_level = EXPOSE_OPSTAFF;
326 if (!strcasecmp(argv[2],EXPOSE_REALMVIS))
327 exp_level = EXPOSE_REALMVIS;
328 if (!strcasecmp(argv[2],EXPOSE_REALMANN))
329 exp_level = EXPOSE_REALMANN;
330 if (!strcasecmp(argv[2],EXPOSE_NETVIS))
331 exp_level = EXPOSE_NETVIS;
332 if (!strcasecmp(argv[2],EXPOSE_NETANN))
333 exp_level = EXPOSE_NETANN;
335 fprintf(stderr,"The exposure setting must be one of:\n");
336 fprintf(stderr,"%s, %s, %s, %s, %s, %s.\n",
347 retval = ZSetVariable(argv[1],"");
349 (void) strcpy(varcat,argv[2]);
350 for (i=3;i<argc;i++) {
351 (void) strcat(varcat," ");
352 (void) strcat(varcat,argv[i]);
354 retval = ZSetVariable(argv[1],varcat);
357 if (retval != ZERR_NONE) {
358 ss_perror(sci_idx,retval,"while setting variable value");
362 /* Side-effects? Naw, us? */
365 if ((retval = ZSetLocation(exp_level)) != ZERR_NONE)
366 ss_perror(sci_idx,retval,"while changing exposure status");
367 if (!strcmp(exp_level,EXPOSE_NONE)) {
368 newargv[0] = "wg_shutdown";
369 wgc_control(1,newargv);
371 newargv[0] = "wg_startup";
372 wgc_control(1,newargv);
382 char *exp_level = NULL;
386 fprintf(stderr, "Usage: %s\n",argv[0]);
389 if (!strcmp(argv[0],"unhide"))
390 exp_level = EXPOSE_REALMVIS;
392 exp_level = EXPOSE_OPSTAFF;
393 if ((retval = ZSetLocation(exp_level)) != ZERR_NONE)
394 ss_perror(sci_idx,retval,"while changing exposure status");
405 fprintf(stderr,"Usage: %s <varname> [<varname> ... ]\n",
411 if ((retval = ZUnsetVariable(argv[i])) != ZERR_NONE)
412 ss_perror(sci_idx,retval,
413 "while unsetting variable value");
417 cancel_subs(int argc,
424 fprintf(stderr,"Usage: %s\n",argv[0]);
428 if ((wgport = ZGetWGPort()) == -1) {
429 ss_perror(sci_idx,errno,"while finding WindowGram port");
432 if ((retval = ZCancelSubscriptions((u_short)wgport)) != ZERR_NONE)
433 ss_perror(sci_idx,retval,"while cancelling subscriptions");
442 ZSubscription_t sub,sub2;
444 if (argc > 4 || argc < 3) {
445 fprintf(stderr,"Usage: %s class instance [*]\n",argv[0]);
449 sub.zsub_class = argv[1];
450 sub.zsub_classinst = argv[2];
451 sub.zsub_recipient = (argc == 3)?ZGetSender():argv[3];
453 fix_macros(&sub,&sub2,1);
455 if ((wgport = ZGetWGPort()) == -1) {
456 ss_perror(sci_idx,errno,"while finding WindowGram port");
460 retval = (*argv[0] == 's') ?
461 ZSubscribeToSansDefaults(&sub2,1,(u_short)wgport) :
462 ZUnsubscribeTo(&sub2,1,(u_short)wgport);
464 if (retval != ZERR_NONE)
465 ss_perror(sci_idx,retval,"while subscribing");
475 if (argc > 4 || argc < 3) {
476 fprintf(stderr,"Usage: %s class instance [*]\n",argv[0]);
480 if (argv[1][0] == '!') {
482 (!strcmp(argv[0],"add_unsubscription") ||
483 !strcmp(argv[0],"add_un") ||
484 !strcmp(argv[0],"delete_unsubscription") ||
485 !strcmp(argv[0],"del_un")) ?
486 "Do not use `!' as the first character of a class.\n\tIt is automatically added before modifying the subscription file." :
487 "Do not use `!' as the first character of a class.\n\tIt is reserved for internal use with un-subscriptions.");
490 sub.zsub_class = argv[1];
491 sub.zsub_classinst = argv[2];
492 sub.zsub_recipient = (argc == 3)?TOKEN_ME:argv[3];
494 if (make_exist(subsname))
496 if ((wgport = ZGetWGPort()) == -1) {
497 ss_perror(sci_idx,errno,"while finding WindowGram port");
501 if (!strcmp(argv[0],"add"))
502 add_file(wgport,&sub,0);
503 else if (!strcmp(argv[0],"add_unsubscription") ||
504 !strcmp(argv[0],"add_un"))
505 add_file(wgport,&sub,1);
506 else if (!strcmp(argv[0],"delete") ||
507 !strcmp(argv[0],"del") ||
508 !strcmp(argv[0],"dl"))
509 del_file(wgport,&sub,0);
510 else if (!strcmp(argv[0],"delete_unsubscription") ||
511 !strcmp(argv[0],"del_un")) {
512 del_file(wgport,&sub,1);
514 ss_perror(sci_idx,0,"unknown command name");
519 add_file(short wgport,
520 ZSubscription_t *subs,
525 ZSubscription_t sub2;
528 (void) purge_subs(subs,ALL); /* remove copies in the subs file */
529 if (!(fp = fopen(subsname,"a"))) {
530 (void) sprintf(errbuf,"while opening %s for append",subsname);
531 ss_perror(sci_idx,errno,errbuf);
534 fprintf(fp,"%s%s,%s,%s\n",
536 subs->zsub_class, subs->zsub_classinst, subs->zsub_recipient);
537 if (fclose(fp) == EOF) {
538 (void) sprintf(errbuf, "while closing %s", subsname);
539 ss_perror(sci_idx, errno, errbuf);
542 fix_macros(subs,&sub2,1);
544 ? ZUnsubscribeTo(&sub2,1,(u_short)wgport)
545 : ZSubscribeToSansDefaults(&sub2,1,(u_short)wgport));
547 ss_perror(sci_idx,retval,
548 unsub ? "while unsubscribing" :
549 "while subscribing");
554 del_file(short wgport,
555 register ZSubscription_t *subs,
558 ZSubscription_t sub2;
561 retval = purge_subs(subs, unsub ? UNSUBONLY : SUBONLY);
564 if (retval == NOT_REMOVED)
566 "Couldn't find %sclass %s instance %s recipient %s in\n\tfile %s\n",
567 unsub ? "un-subscription " : "",
568 subs->zsub_class, subs->zsub_classinst,
569 subs->zsub_recipient, subsname);
570 fix_macros(subs,&sub2,1);
571 if ((retval = ZUnsubscribeTo(&sub2,1,(u_short)wgport)) !=
573 ss_perror(sci_idx,retval,"while unsubscribing");
578 purge_subs(register ZSubscription_t *subs,
582 char errbuf[BUFSIZ],subline[BUFSIZ];
583 char backup[BUFSIZ],ourline[BUFSIZ];
584 int delflag = NOT_REMOVED;
593 ss_perror(sci_idx,0,"internal error in purge_subs");
597 (void) sprintf(ourline,"%s,%s,%s",
599 subs->zsub_classinst,
600 subs->zsub_recipient);
602 if (!(fp = fopen(subsname,"r"))) {
603 (void) sprintf(errbuf,"while opening %s for read",subsname);
604 ss_perror(sci_idx,errno,errbuf);
607 (void) strcpy(backup, subsname);
608 (void) strcat(backup, ".temp");
609 (void) unlink(backup);
610 if (!(fpout = fopen(backup,"w"))) {
611 (void) sprintf(errbuf,"while opening %s for writing",backup);
612 ss_perror(sci_idx,errno,errbuf);
617 if (!fgets(subline,sizeof subline,fp))
620 subline[strlen(subline)-1] = '\0'; /* nuke newline */
623 keep = strcmp(subline,ourline);
626 keep = (*subline != '!' || strcmp(subline+1,ourline));
629 keep = (strcmp(subline,ourline) &&
630 (*subline != '!' || strcmp(subline+1,
635 fputs(subline, fpout);
636 if (ferror(fpout) || (fputc('\n', fpout) == EOF)) {
637 (void) sprintf(errbuf, "while writing to %s",
639 ss_perror(sci_idx, errno, errbuf);
644 (void) fclose(fp); /* open read-only, ignore errs */
645 if (fclose(fpout) == EOF) {
646 (void) sprintf(errbuf, "while closing %s",backup);
647 ss_perror(sci_idx, errno, errbuf);
650 if (rename(backup,subsname) == -1) {
651 (void) sprintf(errbuf,"while renaming %s to %s\n",
653 ss_perror(sci_idx,errno,errbuf);
663 ZSubscription_t subs[SUBSATONCE],subs2[SUBSATONCE],unsubs[SUBSATONCE];
665 ZSubscription_t punts[SUBSATONCE];
669 int ind,unind,lineno,i,retval,type;
671 char *comma,*comma2,*file,subline[BUFSIZ];
674 fprintf(stderr,"Usage: %s [file]\n",argv[0]);
681 if (!strcmp(argv[0],"list") || !strcmp(argv[0],"ls"))
687 if ((wgport = ZGetWGPort()) == -1) {
688 ss_perror(sci_idx,errno,
689 "while finding WindowGram port");
693 file = (argc == 1) ? subsname : argv[1];
695 fp = fopen(file,"r");
698 ss_perror(sci_idx,errno,
699 "while loading subscription file");
710 if (!fgets(subline,sizeof subline,fp))
712 if (*subline == '#' || !*subline)
714 subline[strlen(subline)-1] = '\0'; /* nuke newline */
715 comma = strchr(subline,',');
717 comma2 = strchr(comma+1,',');
720 if (!comma || !comma2) {
722 "Malformed subscription at line %d of %s:\n%s\n",
723 lineno,file,subline);
730 printf("(Un-subscription) Class %s instance %s recipient %s\n",
731 subline+1, comma+1, comma2+1);
733 else if(*subline == '-')
734 printf("(Punted) Class %s instance %s recipient %s\n",
735 subline+1, comma+1, comma2+1);
738 printf("Class %s instance %s recipient %s\n",
739 subline, comma+1, comma2+1);
742 if (*subline == '!') { /* an un-subscription */
743 /* if we are explicitly un-subscribing to
744 the contents of a subscription file, ignore
745 any un-subscriptions in that file */
748 unsubs[unind].zsub_class =
749 (char *)malloc((unsigned)(strlen(subline)));
750 /* XXX check malloc return */
751 /* skip the leading '!' */
752 (void) strcpy(unsubs[unind].zsub_class,subline+1);
753 unsubs[unind].zsub_classinst =
754 (char *)malloc((unsigned)(strlen(comma+1)+1));
755 /* XXX check malloc return */
756 (void) strcpy(unsubs[unind].zsub_classinst,comma+1);
757 unsubs[unind].zsub_recipient =
758 (char *)malloc((unsigned)(strlen(comma2+1)+1));
759 /* XXX check malloc return */
760 (void) strcpy(unsubs[unind].zsub_recipient,comma2+1);
764 if (*subline == '-') { /* a punt */
767 punts[pind].zsub_class =
768 (char *)malloc((unsigned)(strlen(subline)+1));
769 /* XXX check malloc return */
770 (void) strcpy(punts[pind].zsub_class,subline+1);
771 punts[pind].zsub_classinst =
772 (char *)malloc((unsigned)(strlen(comma+1)+1));
773 /* XXX check malloc return */
774 (void) strcpy(punts[pind].zsub_classinst,comma+1);
775 punts[pind].zsub_recipient =
776 (char *)malloc((unsigned)(strlen(comma2+1)+1));
777 /* XXX check malloc return */
778 (void) strcpy(punts[pind].zsub_recipient,comma2+1);
783 subs[ind].zsub_class =
784 (char *)malloc((unsigned)(strlen(subline)+1));
785 /* XXX check malloc return */
786 (void) strcpy(subs[ind].zsub_class,subline);
787 subs[ind].zsub_classinst =
788 (char *)malloc((unsigned)(strlen(comma+1)+1));
789 /* XXX check malloc return */
790 (void) strcpy(subs[ind].zsub_classinst,comma+1);
791 subs[ind].zsub_recipient =
792 (char *)malloc((unsigned)(strlen(comma2+1)+1));
793 /* XXX check malloc return */
794 (void) strcpy(subs[ind].zsub_recipient,comma2+1);
798 if (pind == SUBSATONCE) {
799 fix_macros(punts,subs2,pind);
800 if (retval = ZPunt(subs2,pind,(u_short)wgport) !=
803 ss_perror(sci_idx,retval,
807 for (i=0;i<pind;i++) {
808 free(punts[i].zsub_class);
809 free(punts[i].zsub_classinst);
810 free(punts[i].zsub_recipient);
815 if (ind == SUBSATONCE) {
816 fix_macros(subs,subs2,ind);
817 if ((retval = (type == SUB)?
818 ZSubscribeTo(subs2,ind,(u_short)wgport):
819 ZUnsubscribeTo(subs2,ind,(u_short)wgport)) !=
821 ss_perror(sci_idx,retval,(type == SUB)?
823 "while unsubscribing");
826 for (i=0;i<ind;i++) {
827 free(subs[i].zsub_class);
828 free(subs[i].zsub_classinst);
829 free(subs[i].zsub_recipient);
833 if (unind == SUBSATONCE) {
834 fix_macros(unsubs,subs2,unind);
835 if ((retval = ZUnsubscribeTo(subs2,unind,(u_short)wgport)) != ZERR_NONE) {
836 ss_perror(sci_idx,retval,
837 "while unsubscribing to un-subscriptions");
840 for (i=0;i<unind;i++) {
841 free(unsubs[i].zsub_class);
842 free(unsubs[i].zsub_classinst);
843 free(unsubs[i].zsub_recipient);
850 /* even if we have no subscriptions, be sure to send
851 an empty packet to trigger the default subscriptions */
852 fix_macros(subs,subs2,ind);
853 if ((retval = (type == SUB)?ZSubscribeTo(subs2,ind,(u_short)wgport):
854 ZUnsubscribeTo(subs2,ind,(u_short)wgport)) != ZERR_NONE) {
855 ss_perror(sci_idx,retval,(type == SUB)?
857 "while unsubscribing");
861 fix_macros(unsubs,subs2,unind);
863 ZUnsubscribeTo(subs2,unind,(u_short)wgport)) != ZERR_NONE) {
864 ss_perror(sci_idx,retval,
865 "while unsubscribing to un-subscriptions");
871 fix_macros(punts,subs2,pind);
872 if (retval = ZPunt(subs2,pind,(u_short)wgport) !=
875 ss_perror(sci_idx,retval,
883 for (i=0;i<ind;i++) {
884 free(subs[i].zsub_class);
885 free(subs[i].zsub_classinst);
886 free(subs[i].zsub_recipient);
888 for (i=0;i<unind;i++) {
889 free(unsubs[i].zsub_class);
890 free(unsubs[i].zsub_classinst);
891 free(unsubs[i].zsub_recipient);
894 for (i=0;i<pind;i++) {
895 free(punts[i].zsub_class);
896 free(punts[i].zsub_classinst);
897 free(punts[i].zsub_recipient);
901 (void) fclose(fp); /* ignore errs--file is read-only */
911 ZSubscription_t subs;
912 int i,nsubs,retval,save,one,defs;
920 if (!strcmp(argv[0],"save"))
922 else if (!strcmp(argv[0], "defaults") || !strcmp(argv[0], "defs"))
925 if (argc != 1 && !(save && argc == 2)) {
926 fprintf(stderr,"Usage: %s%s\n",argv[0],save?" [filename]":"");
931 if ((wgport = ZGetWGPort()) == -1) {
932 ss_perror(sci_idx,errno,
933 "while finding WindowGram port");
938 retval = ZRetrieveDefaultSubscriptions(&nsubs);
940 retval = ZRetrieveSubscriptions((u_short)wgport,&nsubs);
942 if (retval == ZERR_TOOMANYSUBS) {
943 fprintf(stderr,"Too many subscriptions -- some have not been returned.\n");
945 fprintf(stderr,"Save aborted.\n");
950 if (retval != ZERR_NONE) {
951 ss_perror(sci_idx,retval,"retrieving subscriptions");
956 file = (argc == 1)?subsname:argv[1];
957 (void) strcpy(backup,file);
958 (void) strcat(backup,".temp");
959 if (!(fp = fopen(backup,"w"))) {
960 (void) sprintf(errbuf,"while opening %s for write",
962 ss_perror(sci_idx,errno,errbuf);
967 for (i=0;i<nsubs;i++) {
969 if ((retval = ZGetSubscriptions(&subs,&one)) != ZERR_NONE) {
970 ss_perror(sci_idx,retval,"while getting subscription");
972 fprintf(stderr,"Subscriptions file not modified\n");
974 (void) unlink(backup);
979 fprintf(fp,"%s,%s,%s\n",subs.zsub_class,
980 subs.zsub_classinst, subs.zsub_recipient);
982 printf("Class %s Instance %s Recipient %s\n",
983 subs.zsub_class, subs.zsub_classinst,
984 subs.zsub_recipient);
988 if (fclose(fp) == EOF) {
989 (void) sprintf(errbuf, "while closing %s", backup);
990 ss_perror(sci_idx, errno, errbuf);
993 if (rename(backup,file) == -1) {
994 (void) sprintf(errbuf,"while renaming %s to %s",
996 ss_perror(sci_idx,retval,errbuf);
997 (void) unlink(backup);
1003 make_exist(char *filename)
1005 char errbuf[BUFSIZ];
1008 if (!access(filename,F_OK))
1011 if (!(fpout = fopen(filename,"w"))) {
1012 (void) sprintf(errbuf,"while opening %s for write",filename);
1013 ss_perror(sci_idx,errno,errbuf);
1017 if (fclose(fpout) == EOF) {
1018 (void) sprintf(errbuf, "while closing %s", filename);
1019 ss_perror(sci_idx, errno, errbuf);
1026 fix_macros(ZSubscription_t *subs,
1027 ZSubscription_t *subs2,
1032 for (i=0;i<num;i++) {
1034 fix_macros2(subs[i].zsub_class,&subs2[i].zsub_class);
1035 fix_macros2(subs[i].zsub_classinst,&subs2[i].zsub_classinst);
1036 fix_macros2(subs[i].zsub_recipient,&subs2[i].zsub_recipient);
1041 fix_macros2(char *src, char **dest)
1043 if (!strcmp(src,TOKEN_HOSTNAME)) {
1047 if (!strcmp(src,TOKEN_CANONNAME)) {
1048 *dest = ourhostcanon;
1051 if (!strcmp(src,TOKEN_ME))
1052 *dest = ZGetSender();
1056 do_punt(int argc, char **argv)
1058 #ifdef CMU_ZCTL_PUNT
1059 char *class, *inst, *recip, *msg, *whoami = argv[0];
1062 struct sockaddr_in newsin;
1065 if (! strcmp(whoami, "punt")) punt = 1;
1083 if (*argv[3] == '*') /* fixed so realm punts would work (vs0r) */
1084 if (*(argv[3]+1) == '@')
1085 if (!strcmp((char *)ZGetRealm(), (char *)ZExpandRealm(argv[3]+2)))
1090 fprintf(stderr, "Usages:\n");
1091 fprintf(stderr, "\t%s instance\n", whoami);
1092 fprintf(stderr, "\t%s class instance\n", whoami);
1093 fprintf(stderr, "\t%s class instance recipient\n", whoami);
1097 retval = ZOpenPort((u_short *) 0);
1098 if(retval != ZERR_NONE) {
1099 com_err(whoami, retval, "while opening Zephyr port.");
1103 newsin = ZGetDestAddr();
1104 if ((newport = ZGetWGPort()) == -1) {
1105 fprintf(stderr, "%s: Can't find windowgram port\n", whoami);
1109 newsin.sin_port = (unsigned short) newport;
1110 if ((retval = ZSetDestAddr(&newsin)) != ZERR_NONE) {
1111 com_err(whoami,retval,"while setting destination address");
1115 msg = (char *) malloc(strlen(class) + strlen(inst) + strlen(recip) + 4);
1116 sprintf(msg, "%s%c%s%c%s", class, '\0', inst, '\0', recip);
1119 if (*(recip+1) == '@')
1120 if (strcmp(recip+2, (char *)ZExpandRealm(recip+2)))
1121 sprintf(msg, "%s%c%s%c%s", class, '\0', inst, '\0',
1122 (char *)ZExpandRealm(recip+2));
1123 printf("%s <%s,%s,%s>\n", punt ? "Punting" : "Unpunting",
1124 class, inst, *recip ? recip : "*");
1126 memset((char *) ¬ice, 0, sizeof(ZNotice_t));
1127 notice.z_kind = UNSAFE;
1128 notice.z_class = WG_CTL_CLASS;
1129 notice.z_class_inst = WG_CTL_USER;
1130 notice.z_recipient = "";
1131 notice.z_default_format = "";
1132 notice.z_opcode = (punt) ? "SUPPRESS" : "UNSUPPRESS";
1134 notice.z_message = msg;
1135 notice.z_message_len = strlen(class)+strlen(inst)+strlen(recip)+3;
1137 if ((retval = ZSendNotice(¬ice,ZNOAUTH)) != ZERR_NONE)
1138 fprintf(stderr,"%s: while sending notice\n",whoami);
1148 list_punts(int argc, char **argv)
1150 #ifdef CMU_ZCTL_PUNT
1152 int retval, lensofar;
1153 struct sockaddr_in old, to, from;
1154 u_short ourport, zwgcport;
1158 retval = ZOpenPort(&ourport);
1159 if(retval != ZERR_NONE) {
1160 com_err("zctl", retval, "while opening Zephyr port.");
1164 old = ZGetDestAddr();
1166 if ((zwgcport = ZGetWGPort()) == (u_short)-1) {
1167 fprintf(stderr, "zctl: Can't find windowgram port\n");
1171 to.sin_port = (u_short) zwgcport;
1172 if ((retval = ZSetDestAddr(&to)) != ZERR_NONE) {
1173 com_err("zctl",retval,"while setting destination address");
1177 memset((char *) ¬ice, 0, sizeof(ZNotice_t));
1178 notice.z_kind = UNSAFE;
1179 notice.z_class = WG_CTL_CLASS;
1180 notice.z_class_inst = WG_CTL_USER;
1181 notice.z_recipient = "";
1182 notice.z_default_format = "";
1183 notice.z_opcode = "LIST-SUPPRESSED" /*USER_LIST_SUPPRESSED*/;
1184 notice.z_port = ourport;
1185 notice.z_message = NULL;
1186 notice.z_message_len = 0;
1188 if ((retval = ZSendNotice(¬ice,ZNOAUTH)) != ZERR_NONE)
1189 com_err("zctl",retval,"while sending notice");
1191 if ((retval = ZReceiveNotice(¬ice,&from)) != ZERR_NONE)
1192 com_err("zctl",retval,"while receiving ack");
1194 (void) ZFreeNotice(¬ice);
1196 if ((retval = ZReceiveNotice(¬ice,&from)) != ZERR_NONE)
1197 com_err("zctl",retval,"while receiving notice");
1199 notice.z_auth = ZCheckAuthentication(¬ice, &from);
1201 if ((retval = ZSetDestAddr(&old)) != ZERR_NONE) {
1202 com_err("zctl",retval,"while resetting destination address");
1206 msg = (char *) malloc((notice.z_message_len+1) * sizeof(char));
1207 (void) strncpy(msg,notice.z_message, notice.z_message_len);
1208 msg[notice.z_message_len]=(char)0;
1211 (void) ZFreeNotice(¬ice);
1212 (void) ZClosePort();
1214 #endif /* CMU_ZCTL_PUNT */