int main(int argc, char *argv[]) { int option; char *etypestr = NULL, *ccachestr = NULL, *keytab_name = NULL; char *sname = NULL; int canon = 0, unknown = 0; set_com_err_hook (extended_com_err_fn); prog = strrchr(argv[0], '/'); prog = prog ? (prog + 1) : argv[0]; while ((option = getopt(argc, argv, "uCc:e:hk:qS:")) != -1) { switch (option) { case 'C': canon = 1; break; case 'c': ccachestr = optarg; break; case 'e': etypestr = optarg; break; case 'h': xusage(); break; case 'k': keytab_name = optarg; break; case 'q': quiet = 1; break; case 'S': sname = optarg; if (unknown == 1) { fprintf(stderr, "Options -u and -S are mutually exclusive\n"); xusage(); } break; case 'u': unknown = 1; if (sname) { fprintf(stderr, "Options -u and -S are mutually exclusive\n"); xusage(); } break; default: xusage(); break; } } if ((argc - optind) < 1) xusage(); do_v5_kvno(argc - optind, argv + optind, ccachestr, etypestr, keytab_name, sname, canon, unknown); return 0; }
void ceo_krb5_init() { krb5_error_code retval; set_com_err_hook(com_err_hk); debug("krb5: initializing context"); retval = krb5_init_context(&context); if (retval) com_err(prog, retval, "while initializing krb5"); retval = krb5_set_default_realm(context, krb5_realm); if (retval) com_err(prog, retval, "while setting default realm"); }
/* * krb5_klog_init() - Initialize logging. * * This routine parses the syntax described above to specify destinations for * com_err(3) or krb5_klog_syslog() messages generated by the caller. * * Parameters: * kcontext - Kerberos context. * ename - Entity name as it is to appear in the profile. * whoami - Entity name as it is to appear in error output. * do_com_err - Take over com_err(3) processing. * * Implicit inputs: * stderr - This is where STDERR output goes. * * Implicit outputs: * log_nentries - Number of log entries, both valid and invalid. * log_control - List of entries (log_nentries long) which contains * data for klog_com_err_proc() to use to determine * where/how to send output. */ krb5_error_code krb5_klog_init(krb5_context kcontext, char *ename, char *whoami, krb5_boolean do_com_err) { const char *logging_profent[3]; const char *logging_defent[3]; char **logging_specs; int i, ngood; char *cp, *cp2; char savec = '\0'; int error; int do_openlog, log_facility; FILE *f; mode_t old_umask; /* Initialize */ do_openlog = 0; log_facility = 0; err_context = kcontext; /* * Look up [logging]-><ename> in the profile. If that doesn't * succeed, then look for [logging]->default. */ logging_profent[0] = "logging"; logging_profent[1] = ename; logging_profent[2] = (char *) NULL; logging_defent[0] = "logging"; logging_defent[1] = "default"; logging_defent[2] = (char *) NULL; logging_specs = (char **) NULL; ngood = 0; log_control.log_nentries = 0; if (!profile_get_values(kcontext->profile, logging_profent, &logging_specs) || !profile_get_values(kcontext->profile, logging_defent, &logging_specs)) { /* * We have a match, so we first count the number of elements */ for (log_control.log_nentries = 0; logging_specs[log_control.log_nentries]; log_control.log_nentries++); /* * Now allocate our structure. */ log_control.log_entries = (struct log_entry *) malloc(log_control.log_nentries * sizeof(struct log_entry)); if (log_control.log_entries) { /* * Scan through the list. */ for (i=0; i<log_control.log_nentries; i++) { log_control.log_entries[i].log_type = K_LOG_NONE; log_control.log_entries[i].log_2free = logging_specs[i]; /* * The format is: * <whitespace><data><whitespace> * so, trim off the leading and trailing whitespace here. */ for (cp = logging_specs[i]; isspace((int) *cp); cp++); for (cp2 = &logging_specs[i][strlen(logging_specs[i])-1]; isspace((int) *cp2); cp2--); cp2++; *cp2 = '\0'; /* * Is this a file? */ if (!strncasecmp(cp, "FILE", 4)) { /* * Check for append/overwrite, then open the file. */ if (cp[4] == ':' || cp[4] == '=') { log_control.log_entries[i].lfu_fopen_mode = (cp[4] == ':') ? "a+F" : "wF"; old_umask = umask(077); f = fopen(&cp[5], log_control.log_entries[i].lfu_fopen_mode); umask(old_umask); if (f) { char rotate_kw[128]; log_control.log_entries[i].lfu_filep = f; log_control.log_entries[i].log_type = K_LOG_FILE; log_control.log_entries[i].lfu_fname = &cp[5]; log_control.log_entries[i].lfu_rotate_period = K_LOG_DEF_FILE_ROTATE_PERIOD; log_control.log_entries[i].lfu_rotate_versions = K_LOG_DEF_FILE_ROTATE_VERSIONS; log_control.log_entries[i].lfu_last_rotated = time(0); /* * Now parse for ename_"rotate" = { * period = XXX * versions = 10 * } */ if (strlen(ename) + strlen("_rotate") < sizeof (rotate_kw)) { char *time; krb5_deltat dt; int vers; strcpy(rotate_kw, ename); strcat(rotate_kw, "_rotate"); if (!profile_get_string(kcontext->profile, "logging", rotate_kw, "period", NULL, &time)) { if (time != NULL) { if (!krb5_string_to_deltat(time, &dt)) { log_control.log_entries[i].lfu_rotate_period = (time_t) dt; } free(time); } } if (!profile_get_integer( kcontext->profile, "logging", rotate_kw, "versions", K_LOG_DEF_FILE_ROTATE_VERSIONS, &vers)) { log_control.log_entries[i].lfu_rotate_versions = vers; } } } else { fprintf(stderr, gettext("Couldn't open log file %s: %s\n"), &cp[5], error_message(errno)); continue; } } } #ifdef HAVE_SYSLOG /* * Is this a syslog? */ else if (!strncasecmp(cp, "SYSLOG", 6)) { error = 0; log_control.log_entries[i].lsu_facility = LOG_AUTH; log_control.log_entries[i].lsu_severity = LOG_ERR; /* * Is there a severify specified? */ if (cp[6] == ':') { /* * Find the end of the severity. */ cp2 = strchr(&cp[7], ':'); if (cp2) { savec = *cp2; *cp2 = '\0'; cp2++; } /* * Match a severity. */ if (!strcasecmp(&cp[7], "ERR")) { log_control.log_entries[i].lsu_severity = LOG_ERR; } #ifdef LOG_EMERG else if (!strcasecmp(&cp[7], "EMERG")) { log_control.log_entries[i].lsu_severity = LOG_EMERG; } #endif /* LOG_EMERG */ #ifdef LOG_ALERT else if (!strcasecmp(&cp[7], "ALERT")) { log_control.log_entries[i].lsu_severity = LOG_ALERT; } #endif /* LOG_ALERT */ #ifdef LOG_CRIT else if (!strcasecmp(&cp[7], "CRIT")) { log_control.log_entries[i].lsu_severity = LOG_CRIT; } #endif /* LOG_CRIT */ #ifdef LOG_WARNING else if (!strcasecmp(&cp[7], "WARNING")) { log_control.log_entries[i].lsu_severity = LOG_WARNING; } #endif /* LOG_WARNING */ #ifdef LOG_NOTICE else if (!strcasecmp(&cp[7], "NOTICE")) { log_control.log_entries[i].lsu_severity = LOG_NOTICE; } #endif /* LOG_NOTICE */ #ifdef LOG_INFO else if (!strcasecmp(&cp[7], "INFO")) { log_control.log_entries[i].lsu_severity = LOG_INFO; } #endif /* LOG_INFO */ #ifdef LOG_DEBUG else if (!strcasecmp(&cp[7], "DEBUG")) { log_control.log_entries[i].lsu_severity = LOG_DEBUG; } #endif /* LOG_DEBUG */ else error = 1; /* * If there is a facility present, then parse that. */ if (cp2) { if (!strcasecmp(cp2, "AUTH")) { log_control.log_entries[i].lsu_facility = LOG_AUTH; } else if (!strcasecmp(cp2, "KERN")) { log_control.log_entries[i].lsu_facility = LOG_KERN; } else if (!strcasecmp(cp2, "USER")) { log_control.log_entries[i].lsu_facility = LOG_USER; } else if (!strcasecmp(cp2, "MAIL")) { log_control.log_entries[i].lsu_facility = LOG_MAIL; } else if (!strcasecmp(cp2, "DAEMON")) { log_control.log_entries[i].lsu_facility = LOG_DAEMON; } else if (!strcasecmp(cp2, "LPR")) { log_control.log_entries[i].lsu_facility = LOG_LPR; } else if (!strcasecmp(cp2, "NEWS")) { log_control.log_entries[i].lsu_facility = LOG_NEWS; } else if (!strcasecmp(cp2, "UUCP")) { log_control.log_entries[i].lsu_facility = LOG_UUCP; } else if (!strcasecmp(cp2, "CRON")) { log_control.log_entries[i].lsu_facility = LOG_CRON; } else if (!strcasecmp(cp2, "LOCAL0")) { log_control.log_entries[i].lsu_facility = LOG_LOCAL0; } else if (!strcasecmp(cp2, "LOCAL1")) { log_control.log_entries[i].lsu_facility = LOG_LOCAL1; } else if (!strcasecmp(cp2, "LOCAL2")) { log_control.log_entries[i].lsu_facility = LOG_LOCAL2; } else if (!strcasecmp(cp2, "LOCAL3")) { log_control.log_entries[i].lsu_facility = LOG_LOCAL3; } else if (!strcasecmp(cp2, "LOCAL4")) { log_control.log_entries[i].lsu_facility = LOG_LOCAL4; } else if (!strcasecmp(cp2, "LOCAL5")) { log_control.log_entries[i].lsu_facility = LOG_LOCAL5; } else if (!strcasecmp(cp2, "LOCAL6")) { log_control.log_entries[i].lsu_facility = LOG_LOCAL6; } else if (!strcasecmp(cp2, "LOCAL7")) { log_control.log_entries[i].lsu_facility = LOG_LOCAL7; } cp2--; *cp2 = savec; } } if (!error) { log_control.log_entries[i].log_type = K_LOG_SYSLOG; do_openlog = 1; log_facility = log_control.log_entries[i].lsu_facility; } } #endif /* HAVE_SYSLOG */ /* * Is this a standard error specification? */ else if (!strcasecmp(cp, "STDERR")) { log_control.log_entries[i].lfu_filep = fdopen(fileno(stderr), "a+F"); if (log_control.log_entries[i].lfu_filep) { log_control.log_entries[i].log_type = K_LOG_STDERR; log_control.log_entries[i].lfu_fname = "standard error"; } } /* * Is this a specification of the console? */ else if (!strcasecmp(cp, "CONSOLE")) { log_control.log_entries[i].ldu_filep = CONSOLE_OPEN("a+F"); if (log_control.log_entries[i].ldu_filep) { log_control.log_entries[i].log_type = K_LOG_CONSOLE; log_control.log_entries[i].ldu_devname = "console"; } } /* * Is this a specification of a device? */ else if (!strncasecmp(cp, "DEVICE", 6)) { /* * We handle devices very similarly to files. */ if (cp[6] == '=') { log_control.log_entries[i].ldu_filep = DEVICE_OPEN(&cp[7], "wF"); if (log_control.log_entries[i].ldu_filep) { log_control.log_entries[i].log_type = K_LOG_DEVICE; log_control.log_entries[i].ldu_devname = &cp[7]; } } } /* * See if we successfully parsed this specification. */ if (log_control.log_entries[i].log_type == K_LOG_NONE) { fprintf(stderr, krb5_log_error_table(LSPEC_PARSE_ERR_1), whoami, cp); fprintf(stderr, krb5_log_error_table(LSPEC_PARSE_ERR_2), whoami); } else ngood++; } } /* * If we didn't find anything, then free our lists. */ if (ngood == 0) { for (i=0; i<log_control.log_nentries; i++) free(logging_specs[i]); } free(logging_specs); } /* * If we didn't find anything, go for the default which is to log to * the system log. */ if (ngood == 0) { if (log_control.log_entries) free(log_control.log_entries); log_control.log_entries = &def_log_entry; log_control.log_entries->log_type = K_LOG_SYSLOG; log_control.log_entries->log_2free = (krb5_pointer) NULL; log_facility = log_control.log_entries->lsu_facility = LOG_AUTH; log_control.log_entries->lsu_severity = LOG_ERR; do_openlog = 1; log_control.log_nentries = 1; } if (log_control.log_nentries) { log_control.log_whoami = (char *) malloc(strlen(whoami)+1); if (log_control.log_whoami) strcpy(log_control.log_whoami, whoami); log_control.log_hostname = (char *) malloc(MAXHOSTNAMELEN + 1); if (log_control.log_hostname) { gethostname(log_control.log_hostname, MAXHOSTNAMELEN); log_control.log_hostname[MAXHOSTNAMELEN] = '\0'; } #ifdef HAVE_OPENLOG if (do_openlog) { openlog(whoami, LOG_NDELAY|LOG_PID, log_facility); log_control.log_opened = 1; } #endif /* HAVE_OPENLOG */ if (do_com_err) (void) set_com_err_hook(klog_com_err_proc); } return((log_control.log_nentries) ? 0 : ENOENT); }
int main(int argc, char *argv[]) { void (*old_hook)(const char *, long, const char *, va_list); int use_menu = 1, k_errno; char buf[BUFSIZ]; if ((whoami = strrchr(argv[0], '/')) == NULL) whoami = argv[0]; else whoami++; if (!(current_li = malloc(sizeof(List_info)))) { sprintf(buf, ": allocating list info"); goto punt; } else { current_li->acl_type = NULL; current_li->acl_name = NULL; current_li->desc = NULL; current_li->modtime = NULL; current_li->modby = NULL; current_li->modwith = NULL; } username = mrcl_krb_user(); if (!username) exit(1); if (mrcl_connect(NULL, "mailmaint", 2, 1)) exit(2); initscr(); if ((LINES < 24) || (COLS < 60)) { display_buff("Display window too small.\n\n"); sprintf(buf, "Current window parameters are (%d lines, %d columns)\n", LINES, COLS); display_buff(buf); display_buff("Please resize your window\n"); display_buff("to at least 24 lines and 60 columns.\n"); exit(0); } raw(); noecho(); old_hook = set_com_err_hook(menu_err_hook); position[0] = oldpos[0] = 1; level = 0; pack_main_menu(); pack_help_menu(); display_menu(main_menu); get_main_input(); cls(); endwin(); set_com_err_hook(old_hook); free_menu(main_menu); free_menu(help_menu); if (current_li->acl_type) free(current_li->acl_type); if (current_li->acl_name) free(current_li->acl_name); if (current_li->desc) free(current_li->desc); if (current_li->modtime) free(current_li->modtime); if (current_li->modby) free(current_li->modby); if (current_li->modwith) free(current_li->modwith); free(current_li); mr_disconnect(); exit(0); punt: com_err(whoami, status, "%s", buf); exit(1); }
int main(int argc, char **argv) { int status, i, listener; time_t tardy; char *port, *p; extern char *database; struct stat stbuf; struct utsname uts; fd_set readfds, writefds, xreadfds, xwritefds; int nfds, counter = 0; whoami = argv[0]; /* * Error handler init. */ mr_init(); set_com_err_hook(mr_com_err); setvbuf(stderr, NULL, _IOLBF, BUFSIZ); port = strchr(MOIRA_SERVER, ':') + 1; for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-db") && i + 1 < argc) { database = argv[i + 1]; i++; } else if (!strcmp(argv[i], "-p") && i + 1 < argc) { port = argv[i + 1]; i++; } else { com_err(whoami, 0, "Usage: moirad [-db database][-p port]"); exit(1); } } status = krb5_init_context(&context); if (status) { com_err(whoami, status, "Initializing krb5 context."); exit(1); } status = krb5_get_default_realm(context, &krb_realm); if (status) { com_err(whoami, status, "Getting default Kerberos realm."); exit(1); } /* * Database initialization. Only init if database should be open. */ if (stat(MOIRA_MOTD_FILE, &stbuf) != 0) { if ((status = mr_open_database())) { com_err(whoami, status, "trying to open database."); exit(1); } sanity_check_database(); } else { dormant = ASLEEP; com_err(whoami, 0, "sleeping, not opening database"); } sanity_check_queries(); /* * Get moira server hostname for authentication */ if (uname(&uts) < 0) { com_err(whoami, errno, "Unable to get local hostname"); exit(1); } host = canonicalize_hostname(xstrdup(uts.nodename)); for (p = host; *p && *p != '.'; p++) { if (isupper(*p)) *p = tolower(*p); } *p = '\0'; /* * Set up client array handler. */ nclients = 0; clientssize = 10; clients = xmalloc(clientssize * sizeof(client *)); mr_setup_signals(); journal = fopen(JOURNAL, "a"); if (!journal) { com_err(whoami, errno, "opening journal file"); exit(1); } /* * Establish template connection. */ listener = mr_listen(port); if (listener == -1) { com_err(whoami, MR_ABORTED, "trying to create listening connection"); exit(1); } FD_ZERO(&xreadfds); FD_ZERO(&xwritefds); FD_SET(listener, &xreadfds); nfds = listener + 1; com_err(whoami, 0, "started (pid %d)", getpid()); com_err(whoami, 0, rcsid); if (dormant != ASLEEP) send_zgram("MOIRA", "server started"); else send_zgram("MOIRA", "server started, but database closed"); /* * Run until shut down. */ while (!takedown) { int i; struct timeval timeout = {60, 0}; /* 1 minute */ /* If we're supposed to go down and we can, do it */ if (((dormant == AWAKE) && (nclients == 0) && (stat(MOIRA_MOTD_FILE, &stbuf) == 0)) || (dormant == SLEEPY)) { mr_close_database(); com_err(whoami, 0, "database closed"); mr_setup_signals(); send_zgram("MOIRA", "database closed"); dormant = ASLEEP; } /* Block until something happens. */ memcpy(&readfds, &xreadfds, sizeof(readfds)); memcpy(&writefds, &xwritefds, sizeof(writefds)); if (select(nfds, &readfds, &writefds, NULL, &timeout) == -1) { if (errno != EINTR) com_err(whoami, errno, "in select"); continue; } if (takedown) break; if (child_exited_abnormally) { critical_alert(whoami, "moirad", "%d: child exits with signal %d status %d", child_pid, child_signal, child_status); child_exited_abnormally = 0; } time(&now); tardy = now - 30 * 60; /* If we're asleep and we should wake up, do it */ if ((dormant == ASLEEP) && (stat(MOIRA_MOTD_FILE, &stbuf) == -1) && (errno == ENOENT)) { mr_open_database(); com_err(whoami, 0, "database open"); mr_setup_signals(); send_zgram("MOIRA", "database open again"); dormant = AWAKE; } /* Handle any new connections */ if (FD_ISSET(listener, &readfds)) { int newconn, addrlen = sizeof(struct sockaddr_in); struct sockaddr_in addr; client *cp; newconn = accept(listener, (struct sockaddr *)&addr, &addrlen); if (newconn == -1) com_err(whoami, errno, "accepting new connection"); else if (newconn > 0) { if (newconn + 1 > nfds) nfds = newconn + 1; FD_SET(newconn, &xreadfds); /* Add a new client to the array */ nclients++; if (nclients > clientssize) { clientssize = 2 * clientssize; clients = xrealloc(clients, clientssize * sizeof(client *)); } clients[nclients - 1] = cp = xmalloc(sizeof(client)); memset(cp, 0, sizeof(client)); cp->con = newconn; cp->id = counter++; cp->last_time_used = now; cp->haddr = addr; cp->tuplessize = 1; cp->tuples = xmalloc(sizeof(mr_params)); memset(cp->tuples, 0, sizeof(mr_params)); cp->state = CL_ACCEPTING; cp->version = 2; cur_client = cp; com_err(whoami, 0, "New connection from %s port %d (now %d client%s)", inet_ntoa(cp->haddr.sin_addr), (int)ntohs(cp->haddr.sin_port), nclients, nclients != 1 ? "s" : ""); } } /* Handle any existing connections. */ for (i = 0; i < nclients; i++) { cur_client = clients[i]; if (FD_ISSET(clients[i]->con, &writefds)) { client_write(clients[i]); if (!clients[i]->ntuples) { FD_CLR(clients[i]->con, &xwritefds); FD_SET(clients[i]->con, &xreadfds); } clients[i]->last_time_used = now; } if (FD_ISSET(clients[i]->con, &readfds)) { if (clients[i]->state == CL_ACCEPTING) { switch(mr_cont_accept(clients[i]->con, &clients[i]->hsbuf, &clients[i]->hslen)) { case -1: break; case 0: clients[i]->state = CL_CLOSING; break; default: clients[i]->state = CL_ACTIVE; clients[i]->hsbuf = NULL; break; } } else { client_read(clients[i]); if (clients[i]->ntuples) { FD_CLR(clients[i]->con, &xreadfds); FD_SET(clients[i]->con, &xwritefds); } clients[i]->last_time_used = now; } } if (clients[i]->last_time_used < tardy) { com_err(whoami, 0, "Shutting down connection due to inactivity"); clients[i]->state = CL_CLOSING; } if (clients[i]->state == CL_CLOSING) { client *old; com_err(whoami, 0, "Closed connection (now %d client%s, " "%d queries)", nclients - 1, nclients != 2 ? "s" : "", newqueries); shutdown(clients[i]->con, 2); close(clients[i]->con); FD_CLR(clients[i]->con, &xreadfds); FD_CLR(clients[i]->con, &xwritefds); free_rtn_tuples(clients[i]); free(clients[i]->tuples); if (clients[i]->hsbuf) free(clients[i]->hsbuf); old = clients[i]; clients[i] = clients[--nclients]; free(old); } cur_client = NULL; if (takedown) break; } } com_err(whoami, 0, "%s", takedown); if (dormant != ASLEEP) mr_close_database(); send_zgram("MOIRA", takedown); return 0; }
int main(int argc, char **argv) { char *str, *p; size_t len; struct _dt *d; struct utsname name; int s, conn; struct sigaction sa; FILE *pid_file; char *pid_path = NULL; whoami = strrchr(argv[0], '/'); if (whoami) whoami++; else whoami = argv[0]; /* interpret arguments here */ if (argc != 1) { fprintf(stderr, "Usage: %s\n", whoami); exit(1); } if (!config_lookup("nofork")) { if (fork()) exit(0); setsid(); } uname(&name); hostname = name.nodename; umask(0022); mr_init(); sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; sa.sa_handler = child_handler; sigaction(SIGCHLD, &sa, NULL); /* If the config file contains a line "user username", the * daemon will run with that user's UID. */ if ((p = config_lookup("user"))) { struct passwd *pw; pw = getpwnam(p); if (!pw) { com_err(whoami, errno, "Unable to find user %s\n", p); exit(1); } uid = pw->pw_uid; } /* If the config file contains a line "port portname", the daemon * will listen on the named port rather than SERVICE_NAME ("moira_update") */ if (!(p = config_lookup("port"))) p = SERVICE_NAME; s = mr_listen(p); if (s == -1) { com_err(whoami, errno, "creating listening socket"); exit(1); } set_com_err_hook(syslog_com_err_proc); openlog(whoami, LOG_PID, LOG_DAEMON); if ((pid_path = malloc(strlen(PIDFILEPATH) + strlen(whoami) + 6)) != NULL) { sprintf(pid_path, "%s/%s.pid", PIDFILEPATH, whoami); pid_file = fopen(pid_path, "w"); if (pid_file) { fprintf(pid_file, "%d\n", getpid ()); fclose(pid_file); } else { com_err(whoami, errno, "Unable to write PID file %s", pid_path); exit(1); } free(pid_path); } else { com_err(whoami, errno, "Could not allocate memory for pidfile path"); exit(1); } /* now loop waiting for connections */ while (1) { struct sockaddr_in client; long len; char *buf; conn = mr_accept(s, &client); if (conn == -1) { com_err(whoami, errno, "accepting on listening socket"); exit(1); } else if (conn == 0) continue; if (config_lookup("nofork") || (fork() <= 0)) break; close(conn); } /* If the config file contains a line "chroot /dir/name", the * daemon will run chrooted to that directory. */ if ((p = config_lookup("chroot"))) { if (chroot(p) < 0) { com_err(whoami, errno, "unable to chroot to %s", p); exit(1); } } com_err(whoami, 0, "got connection"); while (1) { char *cp, *str; size_t len; int code; code = recv_string(conn, &str, &len); if (code) { com_err(whoami, code, "receiving command"); close(conn); exit(1); } cp = strchr(str, ' '); if (cp) *cp = '\0'; for (d = dispatch_table; d->str; d++) { if (!strcmp(d->str, str)) { if (cp) *cp = ' '; (d->proc)(conn, str); goto ok; } } com_err(whoami, 0, "unknown request received: %s", str); code = send_int(conn, MR_UNKNOWN_PROC); if (code) com_err(whoami, code, "sending UNKNOWN_PROC"); ok: free(str); } }
int main(int argc, char *argv[]) { krb5_error_code ret; char *name, tmp[BUFSIZ]; int c, mode; setlocale(LC_ALL, ""); progname = GET_PROGNAME(argv[0]); set_com_err_hook(extended_com_err_fn); name = NULL; mode = DEFAULT; /* V = version so v can be used for verbose later if desired. */ while ((c = getopt(argc, argv, "dfetKsnacki45lAVC")) != -1) { switch (c) { case 'd': show_adtype = 1; break; case 'f': show_flags = 1; break; case 'e': show_etype = 1; break; case 't': show_time = 1; break; case 'K': show_keys = 1; break; case 's': status_only = 1; break; case 'n': no_resolve = 1; break; case 'a': show_addresses = 1; break; case 'c': if (mode != DEFAULT) usage(); mode = CCACHE; break; case 'k': if (mode != DEFAULT) usage(); mode = KEYTAB; break; case 'i': use_client_keytab = 1; break; case '4': fprintf(stderr, _("Kerberos 4 is no longer supported\n")); exit(3); break; case '5': break; case 'l': list_all = 1; break; case 'A': show_all = 1; break; case 'C': show_config = 1; break; case 'V': print_version = 1; break; default: usage(); break; } } if (no_resolve && !show_addresses) usage(); if (mode == DEFAULT || mode == CCACHE) { if (show_time || show_keys) usage(); if ((show_all && list_all) || (status_only && list_all)) usage(); } else { if (show_flags || status_only || show_addresses || show_all || list_all) usage(); } if (argc - optind > 1) { fprintf(stderr, _("Extra arguments (starting with \"%s\").\n"), argv[optind + 1]); usage(); } if (print_version) { #ifdef _WIN32 /* No access to autoconf vars; fix somehow. */ printf("Kerberos for Windows\n"); #else printf(_("%s version %s\n"), PACKAGE_NAME, PACKAGE_VERSION); #endif exit(0); } name = (optind == argc - 1) ? argv[optind] : NULL; now = time(0); if (!krb5_timestamp_to_sfstring(now, tmp, 20, NULL) || !krb5_timestamp_to_sfstring(now, tmp, sizeof(tmp), NULL)) timestamp_width = (int)strlen(tmp); else timestamp_width = 15; ret = krb5_init_context(&context); if (ret) { com_err(progname, ret, _("while initializing krb5")); exit(1); } if (list_all) list_all_ccaches(); else if (show_all) show_all_ccaches(); else if (mode == DEFAULT || mode == CCACHE) do_ccache_name(name); else do_keytab(name); return 0; }
com_err_handler_t reset_com_err_hook() { return set_com_err_hook(NULL); }