void send_zgram(char *inst, char *msg) { #ifdef HAVE_ZEPHYR ZNotice_t znotice; memset(&znotice, 0, sizeof(znotice)); znotice.z_kind = UNSAFE; znotice.z_class = "MOIRA"; znotice.z_class_inst = inst; znotice.z_default_format = "MOIRA $instance on $fromhost:\n $message\n"; ZInitialize(); znotice.z_message = msg; znotice.z_message_len = strlen(msg) + 1; znotice.z_opcode = ""; znotice.z_recipient = ""; ZSendNotice(&znotice, ZNOAUTH); #else char *buf; buf = malloc(9 + strlen(inst) + strlen(msg)); if (buf) { sprintf(buf, "MOIRA: %s %s", inst, msg); syslog(LOG_ERR, "%s", buf); free(buf); } #endif }
int main(int argc, char *argv[]) { Code_t ret; char hostname[NS_MAXDNAME]; int optchar; struct servent *sp; if ((ret = ZInitialize()) != ZERR_NONE) { com_err("zstat", ret, "initializing"); exit(-1); } if ((ret = ZOpenPort((u_short *)0)) != ZERR_NONE) { com_err("zstat", ret, "opening port"); exit(-1); } while ((optchar = getopt(argc, argv, "sh")) != EOF) { switch(optchar) { case 's': serveronly++; break; case 'h': hmonly++; break; case '?': default: usage(argv[0]); exit(1); } } if (serveronly && hmonly) { fprintf(stderr,"Only one of -s and -h may be specified\n"); exit(1); } sp = getservbyname(SERVER_SVCNAME,"udp"); srv_port = (sp) ? sp->s_port : SERVER_SVC_FALLBACK; if (optind == argc) { if (gethostname(hostname, sizeof(hostname)) < 0) { com_err("zstat",errno,"while finding hostname"); exit(-1); } do_stat(hostname); exit(0); } for (;optind<argc;optind++) do_stat(argv[optind]); exit(0); }
void owl_zephyr_finish_initialization(const owl_io_dispatch *d, void *data) { Code_t code; char *perl; GSource *event_source; owl_select_remove_io_dispatch(d); ZClosePort(); if ((code = ZInitialize()) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(code)); return; } if ((code = ZOpenPort(NULL)) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(code)); return; } event_source = owl_zephyr_event_source_new(ZGetFD()); g_source_attach(event_source, NULL); g_source_unref(event_source); owl_global_set_havezephyr(&g); if(g.load_initial_subs) { owl_zephyr_load_initial_subs(); } while(deferred_subs != NULL) { owl_sub_list *subs = deferred_subs->data; owl_function_debugmsg("Loading %d deferred subs.", subs->nsubs); owl_zephyr_loadsubs_helper(subs->subs, subs->nsubs); deferred_subs = g_list_delete_link(deferred_subs, deferred_subs); g_free(subs); } /* zlog in if we need to */ if (owl_global_is_startuplogin(&g)) { owl_function_debugmsg("startup: doing zlog in"); owl_zephyr_zlog_in(); } /* check pseudo-logins if we need to */ if (owl_global_is_pseudologins(&g)) { owl_function_debugmsg("startup: checking pseudo-logins"); owl_function_zephyr_buddy_check(0); } perl = owl_perlconfig_execute("BarnOwl::Zephyr::_zephyr_startup()"); g_free(perl); }
void owl_zephyr_finish_initialization(owl_dispatch *d) { Code_t code; owl_select_remove_dispatch(d->fd); ZClosePort(); if ((code = ZInitialize()) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(code)); return; } if ((code = ZOpenPort(NULL)) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(code)); return; } d = owl_malloc(sizeof(owl_dispatch)); d->fd = ZGetFD(); d->cfunc = &owl_zephyr_process_events; d->destroy = NULL; owl_select_add_dispatch(d); owl_global_set_havezephyr(&g); if(g.load_initial_subs) { owl_zephyr_load_initial_subs(); } while(deferred_subs != NULL) { owl_sub_list *subs = deferred_subs->data; owl_function_debugmsg("Loading %d deferred subs.", subs->nsubs); owl_zephyr_loadsubs_helper(subs->subs, subs->nsubs); deferred_subs = g_list_delete_link(deferred_subs, deferred_subs); owl_free(subs); } /* zlog in if we need to */ if (owl_global_is_startuplogin(&g)) { owl_function_debugmsg("startup: doing zlog in"); owl_zephyr_zlog_in(); } }
int main(int argc, char *argv[]) { register char *cp; char *realm; ZSubscription_t subs[SUBSATONCE]; ZLocations_t locations; FILE *fp = NULL; struct passwd *pwd; char anyonename[BUFSIZ],name[BUFSIZ],cleanname[BUFSIZ],*envptr; char *comment_ptr; int onoff = ON,quiet = 0,justlist = 0,useronly = 0, filenamed = 0; int retval,arg,ind,one,numlocs,i; int wgport = 0; if ((retval = ZInitialize()) != ZERR_NONE) { com_err(argv[0],retval,"initializing"); exit (1); } for (arg=1;arg<argc;arg++) { if (!strcmp(argv[arg],"on")) { onoff = ON; continue; } if (!strcmp(argv[arg],"off")) { onoff = OFF; continue; } if (argv[arg][0] == '-') { char opt = argv[arg][1]; if (opt == 0 || argv[arg][2] != 0) goto usage; switch (argv[arg][1]) { case 'q': quiet = 1; break; case 'l': justlist = 1; break; case 'f': if (arg == argc-1) { fprintf(stderr,"No file name specified\n"); goto usage; } (void) strcpy(anyonename,argv[++arg]); filenamed = 1; break; case 'u': if (arg == argc-1) { fprintf(stderr,"No username specified\n"); goto usage; } (void) strcpy(cleanname,argv[++arg]); useronly = 1; break; default: goto usage; } continue; } usage: fprintf(stderr,"Usage: %s [on|off] [-q | -l] [-f file | -u username]\n", argv[0]); exit (1); } if (quiet && justlist) { fprintf(stderr,"-q and -l cannot both be used\n"); goto usage; } if (useronly && filenamed) { fprintf(stderr,"-u and -f cannot both be used\n"); goto usage; } if (!justlist) if ((wgport = ZGetWGPort()) == -1) { com_err(argv[0],errno,"while getting WindowGram port"); exit(1); } if (!useronly) { /* If no filename specified, get the default */ if (!filenamed) { envptr = getenv("HOME"); if (envptr) (void) strcpy(anyonename,envptr); else { if (!(pwd = getpwuid((int) getuid()))) { fprintf(stderr,"You are not listed in the password file.\n"); exit (1); } (void) strcpy(anyonename,pwd->pw_dir); } (void) strcat(anyonename,"/.anyone"); } /* if the filename is "-", read stdin */ if (strcmp(anyonename,"-") == 0) { fp = stdin; } else if (!(fp = fopen(anyonename,"r"))) { fprintf(stderr,"Can't open %s for input\n",anyonename); exit (1); } } ind = 0; for (;;) { if (!useronly) { if (!fgets(cleanname,sizeof cleanname,fp)) break; if (cleanname[0] == '#' || cleanname[0] == '\0' || cleanname[0] == '\n') continue; /* ignore comment and empty lines */ comment_ptr = strchr(cleanname, '#'); if (comment_ptr) *comment_ptr = '\0'; /* Ignore from # onwards */ /* Get rid of old-style nol entries, just in case */ cp = cleanname + strlen(cleanname) - 1; *cp = '\0'; while(*--cp == ' ') *cp = '\0'; if (*cleanname == '@' || !*cleanname) continue; } else if (ind) break; /* only do the one name */ subs[ind].zsub_class = LOGIN_CLASS; (void) strcpy(name,cleanname); if (!strchr(name,'@')) { cp = name + strlen(name); *cp++ = '@'; (void) strcpy(cp,ZGetRealm()); } cp = strchr(name,'@'); if (cp[0] && strcmp(cp+1,ZGetRealm())) { realm = cp + 1; *cp = '\0'; if ((subs[ind].zsub_classinst = malloc((unsigned)(strlen(name) + strlen(realm) + 2))) == NULL) { fprintf (stderr, "znol: out of memory"); exit (1); } (void) sprintf(subs[ind].zsub_classinst, "%s@%s", name, realm); (void) strcpy(name, subs[ind].zsub_classinst); if ((subs[ind].zsub_recipient = malloc((unsigned)(strlen(realm)+2))) == NULL) { fprintf (stderr, "znol: out of memory"); exit (1); } (void) sprintf(subs[ind++].zsub_recipient, "@%s", realm); } else { if ((subs[ind].zsub_classinst = malloc((unsigned)(strlen(name)+1))) == NULL) { fprintf (stderr, "znol: out of memory"); exit (1); } (void) strcpy(subs[ind].zsub_classinst, name); subs[ind++].zsub_recipient = ""; } if (!quiet && onoff == ON) { if ((retval = ZLocateUser(name,&numlocs,ZAUTH)) != ZERR_NONE) { com_err(argv[0],retval,"locating user"); exit(1); } one = 1; if (numlocs) { for (i=0;i<numlocs;i++) { if ((retval = ZGetLocations(&locations,&one)) != ZERR_NONE) { com_err(argv[0],retval, "getting location"); continue; } if (one != 1) { printf("%s: internal failure while getting location\n",argv[0]); exit(1); } printf("%s: %s\t%s\t%s\n",cleanname, locations.host, locations.tty, locations.time); } } } if (ind == SUBSATONCE) { if (!justlist) if ((retval = (onoff==ON)? ZSubscribeToSansDefaults(subs,ind, (u_short)wgport): ZUnsubscribeTo(subs,ind,(u_short)wgport)) != ZERR_NONE) { com_err(argv[0],retval,(onoff==ON)? "subscribing": "unsubscribing"); exit(1); } for (ind=0;ind<SUBSATONCE;ind++) { if (subs[ind].zsub_recipient[0] != '\0') free(subs[ind].zsub_recipient); free(subs[ind].zsub_classinst); } ind = 0; } } if (ind && !justlist) if ((retval = (onoff==ON)? ZSubscribeToSansDefaults(subs,ind,(u_short)wgport): ZUnsubscribeTo(subs,ind,(u_short)wgport)) != ZERR_NONE) { com_err(argv[0],retval,(onoff==ON)? "subscribing": "unsubscribing"); exit(1); } if (!useronly) (void) fclose(fp); /* file is open read-only, ignore errs */ exit(0); }