int main(int argc, char **argv) { int status; Menu *menu; char *motd, **arg; struct sigaction act; if (!(program_name = strrchr(argv[0], '/'))) program_name = argv[0]; else program_name++; program_name = strdup(program_name); whoami = strdup(program_name); /* used by menu.c, ugh !!! */ user = mrcl_krb_user(); if (!user) exit(1); verbose = TRUE; arg = argv; moira_server = NULL; while (++arg - argv < argc) { if (**arg == '-') { if (!strcmp(*arg, "-nomenu")) { #ifdef HAVE_CURSES use_menu = FALSE; #else ; #endif } else if (!strcmp(*arg, "-menu")) { #ifdef HAVE_CURSES use_menu = TRUE; #else fprintf(stderr, "%s: No curses support. -menu option ignored\n", whoami); #endif } else if (!strcmp(*arg, "-db")) if (arg - argv < argc - 1) { ++arg; moira_server = *arg; } else Usage(); else Usage(); } } if (mrcl_connect(moira_server, program_name, QUERY_VERSION, 0) != MRCL_SUCCESS) exit(1); if ((status = mr_krb5_auth(program_name))) { if (status == MR_UNKNOWN_PROC) status = mr_auth(program_name); if (status) { if (status == MR_USER_AUTH) { char buf[BUFSIZ]; com_err(program_name, status, "\nPress [RETURN] to continue"); fgets(buf, BUFSIZ, stdin); } else ErrorExit("\nAuthorization failed -- please run kinit", status); } } /* * These signals should not be set until just before we fire up the menu * system. */ sigemptyset(&act.sa_mask); act.sa_flags = 0; act.sa_handler = Signal_Handler; sigaction(SIGHUP, &act, NULL); sigaction(SIGQUIT, &act, NULL); #ifdef HAVE_CURSES if (use_menu) sigaction(SIGINT, &act, NULL); else #endif { act.sa_handler = CatchInterrupt; sigaction(SIGINT, &act, NULL); } menu = &namespace_menu; #ifdef HAVE_CURSES if (use_menu) /* Start menus that execute program */ { Start_paging(); Start_menu(menu); Stop_paging(); } else /* Start program without menus. */ #endif Start_no_menu(menu); mr_disconnect(); exit(0); }
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; /* general purpose exit status */ int q_argc; /* argc for mr_query */ char *q_argv[U_END]; /* argv for mr_query */ char *motd; /* determine Moira server status */ int got_one = 0; /* Have we got a shell yet? */ int windowsflg = 0, unixflg = 0; char **arg = argv; char *server = NULL, *shell = NULL; if ((whoami = strrchr(argv[0], '/')) == NULL) whoami = argv[0]; else whoami++; /* parse our command line options */ while (++arg - argv < argc) { if (**arg == '-') { if (argis("w", "winshell")) windowsflg++; else if (argis("u", "unixshell")) unixflg++; else if (argis("s", "shell")) { if (arg - argv < argc - 1) { ++arg; shell = *arg; } else usage(); } else if (argis("db", "database")) { if (arg - argv < argc - 1) { ++arg; server = *arg; } else usage(); } } else if (username == NULL) username = *arg; else usage(); } if (!username) { username = mrcl_krb_user(); if (!username) exit(1); } if (!unixflg && !windowsflg) unixflg++; if (unixflg && windowsflg) usage(); if (mrcl_connect(server, "chsh", 14, 1) != MRCL_SUCCESS) exit(1); /* First, do an access check */ q_argv[USH_NAME] = username; q_argv[USH_SHELL] = "junk"; q_argc = USH_END; if ((status = mr_access("update_user_shell", q_argc, q_argv))) { com_err(whoami, status, "; shell not\nchanged."); exit(2); } printf("Changing login shell for %s.\n", username); /* Display current information */ q_argv[NAME] = username; q_argc = NAME + 1; if ((status = mr_query("get_finger_by_login", q_argc, q_argv, get_fmodtime, username))) { com_err(whoami, status, "while getting user information."); exit(2); } if (unixflg) { if ((status = mr_query("get_user_account_by_login", q_argc, q_argv, get_shell, username))) { com_err(whoami, status, "while getting user information."); exit(2); } if (!shell) { /* Ask for new shell */ while (!got_one) { shell = malloc(MAXPATHLEN); if (!shell) exit(1); printf("New shell: "); if (!fgets(shell, MAXPATHLEN, stdin)) exit(0); got_one = (strlen(shell) > 1); } shell[strlen(shell) - 1] = 0; /* trim newline */ } /* Make sure we have a valid shell. This routine could exit */ check_shell(shell); /* Change shell */ printf("Changing shell to %s...\n", shell); q_argv[USH_NAME] = username; q_argv[USH_SHELL] = shell; q_argc = USH_END; if ((status = mr_query("update_user_shell", q_argc, q_argv, NULL, NULL))) { com_err(whoami, status, "while changing shell."); exit(2); } printf("Shell successfully changed.\n"); } else if (windowsflg) { if ((status = mr_query("get_user_account_by_login", q_argc, q_argv, get_winshell, username))) { com_err(whoami, status, "while getting user information."); exit(2); } if (!shell) { /* Ask for new Windows shell */ while(!got_one) { shell = malloc(MAXPATHLEN); if (!shell) exit(1); printf("New Windows shell: "); if (!fgets(shell, MAXPATHLEN, stdin)) exit(0); got_one = (strlen(shell) > 1); } shell[strlen(shell) - 1] = 0; /* strip off newline */ } /* Change shell */ printf("Changing Windows shell to %s...\n", shell); q_argv[USH_NAME] = username; q_argv[USH_SHELL] = shell; q_argc = USH_END; if ((status = mr_query("update_user_windows_shell", q_argc, q_argv, NULL, NULL))) { com_err(whoami, status, "while changing Windows shell."); exit(2); } printf("Windows shell successfully changed.\n"); } mr_disconnect(); return 0; }