int DeleteMember(int argc, char **argv) { char *args[10]; int status; if (GetMemberInfo("delete", args) == SUB_ERROR) return DM_NORMAL; if (Confirm("Are you sure you want to delete this member?")) { if ((status = do_mr_query("delete_member_from_list", CountArgs(args), args, NULL, NULL))) { if ((status == MR_STRING || status == MR_NO_MATCH) && !strcmp(args[LM_TYPE], "KERBEROS")) { char *canon; mrcl_validate_kerberos_member(args[LM_MEMBER], &canon); if (mrcl_get_message()) { free(args[LM_MEMBER]); args[LM_MEMBER] = canon; if (do_mr_query("delete_member_from_list", CountArgs(args), args, NULL, NULL) == MR_SUCCESS) { Put_message(mrcl_get_message()); status = MR_SUCCESS; } } } else if ((status == MR_MACHINE || status == MR_NO_MATCH) && !strcmp(args[LM_TYPE], "MACHINE")) { char *canon; canon = canonicalize_hostname(args[LM_MEMBER]); args[LM_MEMBER] = canon; if (do_mr_query("delete_member_from_list", CountArgs(args), args, NULL, NULL) == MR_SUCCESS) status = MR_SUCCESS; } } if (status) com_err(program_name, status, " in DeleteMember"); else Put_message("Deletion Completed."); } else Put_message("Deletion has been Aborted."); FreeInfo(args); return DM_NORMAL; }
int AddACL(int argc, char **argv) { char *info[MAX_ARGS_SIZE], **args; int stat; argv[1] = canonicalize_hostname(strdup(argv[1])); if (!(stat = do_mr_query("get_acl", 2, argv + 1, NULL, NULL))) { Put_message ("An ACL for that host and target already exists."); free(argv[1]); return DM_NORMAL; } else if (stat != MR_NO_MATCH) { com_err(program_name, stat, " in AddACL"); free(argv[1]); return DM_NORMAL; } args = AskACLInfo(SetDefaults(info, argv[1], argv[2])); free(argv[1]); if (!args) { Put_message("Aborted."); return DM_NORMAL; } if ((stat = do_mr_query("add_acl", CountArgs(args), args, NULL, NULL))) com_err(program_name, stat, " in AddACL"); FreeInfo(info); return DM_NORMAL; }
int AddPrintSrv(int argc, char **argv) { char *info[MAX_ARGS_SIZE], **args, *name; int stat; name = canonicalize_hostname(strdup(argv[1])); if (!(stat = do_mr_query("get_print_server", 1, &name, NULL, NULL))) { Put_message ("A print server record for that host already exists."); free(name); return DM_NORMAL; } else if (stat != MR_NO_MATCH) { com_err(program_name, stat, " in AddPrintSrv"); free(name); return DM_NORMAL; } args = AskPrintSrvInfo(SetPrintSrvDefaults(info, name)); free(name); if (!args) { Put_message("Aborted."); return DM_NORMAL; } if ((stat = do_mr_query("add_print_server", CountArgs(args), args, NULL, NULL))) com_err(program_name, stat, " in AddPrintSrv"); FreeInfo(info); return DM_NORMAL; }
void ListMembersByType(char *type, int tags) { char temp_buf[BUFSIZ]; int status; char *args[10]; args[0] = current_list; args[1] = NULL; found_some = FALSE; if ((status = do_mr_query(tags ? "get_tagged_members_of_list" : "get_members_of_list", CountArgs(args), args, PrintByType, type))) com_err(program_name, status, " in ListMembersByType"); if (!found_some) { if (!type) Put_message("List is empty (no members)."); else { sprintf(temp_buf, "No %s Members", type); Put_message(temp_buf); } } }
int AddPrn(int argc, char **argv) { char *info[MAX_ARGS_SIZE], **args; int stat; if (!ValidName(argv[1])) return DM_NORMAL; if (!(stat = do_mr_query("get_printer", 1, argv + 1, NULL, NULL)) || !(stat = do_mr_query("get_printer_by_duplexname", 1, argv + 1, NULL, NULL))) { Put_message ("A Printer by that name already exists."); return DM_NORMAL; } else if (stat != MR_NO_MATCH) { com_err(program_name, stat, " in AddPrn"); return DM_NORMAL; } args = AskPrnInfo(SetDefaults(info, argv[1]), FALSE); if (!args) { Put_message("Aborted."); return DM_NORMAL; } if ((stat = do_mr_query("add_printer", CountArgs(args), args, NULL, NULL))) com_err(program_name, stat, " in AddPrn"); if (stat == MR_SUCCESS && strcasecmp(info[PRN_HOSTNAME], "[NONE]")) { char *hwargv[2], *hwaddr, *s, *d; hwaddr = strdup(""); if (GetValueFromUser("Hardware ethernet address", &hwaddr) == SUB_ERROR) return DM_NORMAL; s = d = hwaddr; do { if (*s != ':') *d++ = *s; } while (*s++); hwargv[0] = info[PRN_HOSTNAME]; hwargv[1] = hwaddr; stat = do_mr_query("add_host_hwaddr", 2, hwargv, NULL, NULL); if (stat != MR_SUCCESS) com_err(program_name, stat, " in add_host_hwaddr"); } FreeInfo(info); return DM_NORMAL; }
int AddMember(int argc, char **argv) { char *args[10], temp_buf[BUFSIZ], *p; int status; struct mqelem *mailhubs, *elem; if (GetMemberInfo("add", args) == SUB_ERROR) return DM_NORMAL; if (!strcmp(args[LM_TYPE], "STRING")) { status = mrcl_validate_string_member(args[LM_MEMBER]); if (status != MRCL_SUCCESS) Put_message(mrcl_get_message()); if (status == MRCL_REJECT) return DM_NORMAL; } else if (!strcmp(args[LM_TYPE], "KERBEROS")) { char *canon; status = mrcl_validate_kerberos_member(args[LM_MEMBER], &canon); if (mrcl_get_message()) Put_message(mrcl_get_message()); if (status == MRCL_REJECT) return DM_NORMAL; free(args[LM_MEMBER]); args[LM_MEMBER] = canon; } else if (!strcmp(args[LM_TYPE], "MACHINE")) { char *canon; canon = canonicalize_hostname(strdup(args[LM_MEMBER])); free(args[LM_MEMBER]); args[LM_MEMBER] = canon; } if ((status = do_mr_query("add_member_to_list", CountArgs(args), args, NULL, NULL)) != MR_SUCCESS) { if (status == MR_EXISTS) { sprintf(temp_buf, "The %s %s is already a member of LIST %s.", args[LM_TYPE], args[LM_MEMBER], args[LM_LIST]); Put_message(temp_buf); } else com_err(program_name, status, " in AddMember"); } FreeInfo(args); return DM_NORMAL; }
void ChangePrn(char **info, Bool one_item) { int stat; if (!AskPrnInfo(info, TRUE)) { Put_message("Aborted."); return; } if ((stat = do_mr_query("update_printer", CountArgs(info), info, NULL, NULL))) com_err(program_name, stat, " in ChngPrn"); else Put_message("Printer successfully updated."); }
int CheckIfAce(char *name, char *type, Bool verbose) { char *args[2], buf[BUFSIZ], **info; struct mqelem *local, *elem; int status; elem = NULL; args[0] = type; args[1] = name; switch ((status = do_mr_query("get_ace_use", 2, args, StoreInfo, &elem))) { case MR_NO_MATCH: return DM_NORMAL; case MR_SUCCESS: local = elem = QueueTop(elem); info = local->q_data; if (QueueCount(elem) == 1 && !strcmp(info[0], "LIST") && !strcmp(info[1], name)) { FreeQueue(elem); return DM_NORMAL; } if (verbose) { sprintf(buf, "%s %s %s", type, name, "is the ACE for the following data objects:"); Put_message(buf); Put_message(""); for (; local != NULL; local = local->q_forw) { info = local->q_data; if (!strcmp(info[0], "LIST") && !strcmp(info[1], name)) continue; Print(CountArgs(info), info, NULL); } Put_message(""); Put_message("The ACE for each of these items must be changed before"); sprintf(buf, "the %s %s can be deleted.\n", type, name); Put_message(buf); } break; default: com_err(program_name, status, " in CheckIfAce (get_ace_use)."); return SUB_ERROR; } FreeQueue(elem); return SUB_ERROR; }
void ChangePrintSrvLoop(char **info, Bool one) { int stat; if (!AskPrintSrvInfo(info)) return; if ((stat = do_mr_query("update_print_server", CountArgs(info), info, NULL, NULL))) com_err(program_name, stat, " in ChangePrintSrv"); FreeInfo(info); return; }
static void RealChangeFS(char **info, Bool junk) { int stat; char **args; extern Menu nfsphys_menu; args = AskFSInfo(info, TRUE); if (!args) { Put_message("Aborted."); return; } stat = do_mr_query("update_filesys", CountArgs(args), args, NULL, NULL); switch (stat) { case MR_NFS: Put_message("That NFS filesystem is not exported."); if (YesNoQuestion("Fix this now (Y/N)", TRUE) == TRUE) { Do_menu(&nfsphys_menu, 0, NULL); if (YesNoQuestion("Retry filesystem update now (Y/N)", TRUE) == TRUE) { if ((stat = do_mr_query("update_filesys", CountArgs(args), args, NULL, NULL))) com_err(program_name, stat, " filesystem not updated"); else Put_message("filesystem sucessfully updated."); } } break; case MR_SUCCESS: break; default: com_err(program_name, stat, " in UpdateFS"); } }
static void RealUpdateNFSService(char **info, Bool junk) { char **args; int stat; if (!(args = AskNFSInfo(info))) { Put_message("Aborted."); return; } if ((stat = do_mr_query("update_nfsphys", CountArgs(args), args, NULL, NULL))) com_err(program_name, stat, " in RealUpdateNFSService"); }
//Conctructor for commandline object. Pass it the argv[] and argc parameters //fills the elements map with the options and arguements (by calling Handle function) CommandLine::CommandLine(char** args,int numargs) { //DEBUG output DEBUGPRINT("Entering CommandLine Constructor..."); clgood=true;//set this to true initially argcount=NULL; //assign pointers to NULL bool retval=Handle(args,numargs);//handle the arguments and options if(retval==0) { //A problem occurred clgood=false;//set flag throw CommandLineException();//throw an exception } CountArgs(); }
int AddNFSService(int argc, char **argv) { char **add_args, *args[10]; char *info[MAX_ARGS_SIZE]; int stat; args[0] = canonicalize_hostname(strdup(argv[1])); args[1] = strdup(DEFAULT_DIR); if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR) return DM_NORMAL; if (!ValidName(args[0]) || !ValidName(args[1])) return DM_NORMAL; if (!(stat = do_mr_query("get_nfsphys", 2, args, NULL, NULL))) stat = MR_EXISTS; if (stat != MR_NO_MATCH) { com_err(program_name, stat, " in get_nfsphys."); return DM_NORMAL; } info[NFS_NAME] = strdup(args[0]); info[NFS_DIR] = args[1]; /* already saved. */ info[NFS_DEVICE] = strdup(DEFAULT_DEVICE); info[NFS_STATUS] = strdup(DEFAULT_STATUS); info[NFS_ALLOC] = strdup(DEFAULT_ALLOC); info[NFS_SIZE] = strdup(DEFAULT_SIZE); info[NFS_MODBY] = info[NFS_MODWITH] = info[NFS_MODTIME] = NULL; info[NFS_END] = NULL; if (!(add_args = AskNFSInfo(info))) { Put_message("Aborted."); return DM_NORMAL; } if ((stat = do_mr_query("add_nfsphys", CountArgs(add_args), add_args, NULL, NULL))) com_err(program_name, stat, " in AdsNFSService"); FreeInfo(info); free(args[0]); return DM_NORMAL; }
static void RealDeleteNFSService(char **info, Bool one_item) { char temp_buf[BUFSIZ], *args[10]; struct mqelem *elem = NULL; int stat; sprintf(temp_buf, "Are you sure that you want to delete the %s directory on %s", info[NFS_DIR], info[NFS_NAME]); /* * Check to be sure that it is not used by any of the nfs packs. */ if (!one_item || Confirm(temp_buf)) { args[0] = info[NFS_NAME]; args[1] = info[NFS_DIR]; args[2] = NULL; switch ((stat = do_mr_query("get_filesys_by_nfsphys", CountArgs(args), args, StoreInfo, &elem))) { case MR_NO_MATCH: /* it is unused, delete it. */ if ((stat = do_mr_query("delete_nfsphys", 2, info, NULL, NULL))) com_err(program_name, stat, " in DeleteNFSService"); else Put_message("Physical Filesystem Deleted."); break; case MR_SUCCESS: /* it is used, print filesys's that use it. */ elem = QueueTop(elem); Put_message("The following fileystems are using this partition,"); Put_message("and must be removed before it can be deleted."); Put_message(""); Loop(elem, FSPartPrint); FreeQueue(elem); Put_message(""); break; default: com_err(program_name, stat, " while checking usage of partition"); } } else Put_message("Physical filesystem not deleted."); }
int AddNewUser(int argc, char **argv) { int status; char **args, *info[MAX_ARGS_SIZE]; if (!(args = AskUserInfo(SetUserDefaults(info), FALSE))) { Put_message("Aborted."); return DM_NORMAL; } if ((status = do_mr_query("add_user_account", CountArgs(args), args, NULL, NULL))) com_err(program_name, status, " in add_user_account"); else Put_message("New user added to database."); FreeInfo(args); return DM_NORMAL; }
static void RealUpdateList(char **info, Bool junk) { int stat; char **args; struct mqelem *elem = NULL; if (!(args = AskListInfo(info, TRUE))) { Put_message("Aborted."); return; } /* * If the new list name is less than 8 characters, make sure it doesn't * collide with a username. */ if ((strlen(args[2]) <= 8) && do_mr_query("get_user_account_by_login", 1, args + 1, StoreInfo, &elem) != MR_NO_MATCH) { char buf[256]; sprintf(buf, "\nA user by the name `%s' already exists in the database.", args[1]); Put_message(buf); Loop(QueueTop(elem), FreeInfo); FreeQueue(elem); if (YesNoQuestion("Do you still want to rename this list to that name", FALSE) != TRUE) { Put_message("List ** NOT ** Updated."); return; } } if ((stat = do_mr_query("update_list", CountArgs(args), args, NULL, NULL)) != MR_SUCCESS) { com_err(program_name, stat, " in UpdateList."); Put_message("List ** NOT ** Updated."); } else Put_message("List successfully updated."); }
static void RealUpdateUser(char **info, Bool junk) { int status; char error_buf[BUFSIZ]; char **args = AskUserInfo(info, TRUE); if (!args) { Put_message("Aborted."); return; } /* Subtract 2 from CountArgs() because affiliation fields are returned by * get query but aren't exposed to update query. */ if ((status = do_mr_query("update_user_account", CountArgs(args) - 2, args, NULL, NULL))) { com_err(program_name, status, " in ModifyFields"); sprintf(error_buf, "User %s not updated due to errors.", info[NAME]); Put_message(error_buf); } }
int TagMember(int argc, char **argv) { char *args[10]; int status; if (GetMemberInfo("tag", args) == SUB_ERROR) return DM_NORMAL; args[LM_TAG] = strdup(""); if (GetValueFromUser("Tag" , &args[LM_TAG]) == SUB_ERROR) { Put_message("Aborted."); return DM_NORMAL; } args[LM_TAG_END] = NULL; /* NULL terminate this list. */ if ((status = do_mr_query("tag_member_of_list", CountArgs(args), args, NULL, NULL))) com_err(program_name, status, " in TagMember"); FreeInfo(args); return DM_NORMAL; }
void RealDeleteFSAlias(char **info, Bool one_item) { int stat; char temp_buf[BUFSIZ]; /* * Deletions are performed if the user hits 'y' on a list of multiple * filesystem, or if the user confirms on a unique alias. */ sprintf(temp_buf, "Are you sure that you want to delete the filesystem alias %s", info[ALIAS_NAME]); if (!one_item || Confirm(temp_buf)) { if ((stat = do_mr_query("delete_alias", CountArgs(info), info, NULL, NULL))) com_err(program_name, stat, " filesystem alias not deleted."); else Put_message("Filesystem alias deleted."); } else Put_message("Filesystem alias not deleted."); }
static void RealDeactivateUser(char **info, Bool one_item) { int status; char txt_buf[BUFSIZ]; char *qargs[2], **args; struct mqelem *elem = NULL; if (one_item) { sprintf(txt_buf, "Deactivate user %s (y/n)", info[NAME]); if (YesNoQuestion(txt_buf, FALSE) != TRUE) return; } qargs[0] = info[NAME]; qargs[1] = "3"; if ((status = do_mr_query("update_user_status", 2, qargs, NULL, NULL))) { com_err(program_name, status, " in update_user_status"); sprintf(txt_buf, "User %s not deactivated due to errors.", info[NAME]); Put_message(txt_buf); } else if (YesNoQuestion("Also deactivate matching list and filesystem (y/n)", FALSE) == TRUE) { status = do_mr_query("get_list_info", 1, &(info[NAME]), StoreInfo, &elem); if (status == MR_SUCCESS) { args = QueueTop(elem)->q_data; free(args[L_ACTIVE]); args[L_ACTIVE] = strdup("0"); FreeAndClear(&args[L_MODTIME], TRUE); FreeAndClear(&args[L_MODBY], TRUE); FreeAndClear(&args[L_MODWITH], TRUE); SlipInNewName(args, strdup(args[L_NAME])); if ((status = do_mr_query("update_list", CountArgs(args), args, NULL, NULL))) { com_err(program_name, status, " updating list, " "not deactivating list or filesystem"); FreeInfo(args); FreeQueue(elem); return; } FreeInfo(args); FreeQueue(elem); elem = NULL; } else if (status != MR_NO_MATCH) { com_err(program_name, status, " getting list info, " "not deactivating list or filesystem"); return; } if ((status = do_mr_query("get_filesys_by_label", 1, &(info[NAME]), StoreInfo, &elem))) { com_err(program_name, status, " getting filsys info, " "not deactivating filesystem"); return; } args = QueueTop(elem)->q_data; free(args[FS_TYPE]); args[FS_TYPE] = strdup("ERR"); free(args[FS_COMMENTS]); args[FS_COMMENTS] = strdup("Locker disabled; call 3-1325 for help"); FreeAndClear(&args[FS_MODTIME], TRUE); FreeAndClear(&args[FS_MODBY], TRUE); FreeAndClear(&args[FS_MODWITH], TRUE); SlipInNewName(args, strdup(args[FS_NAME])); if ((status = do_mr_query("update_filesys", CountArgs(args), args, NULL, NULL))) { com_err(program_name, status, " updating filesystem, " "not deactivating filesystem"); FreeInfo(args); FreeQueue(elem); return; } FreeInfo(args); FreeQueue(elem); } }
int main( int argc, char *argv[]) { char **myargv; char *aLine; char *firstdir = ""; #ifdef MUST_DISABLE_SIGFPE signal(SIGFPE, SIG_IGN); #endif #ifdef MUST_DISABLE_FPMASK fpsetmask(0); #endif /* initialize locale settings according to localeconv(3) */ setlocale(LC_ALL, ""); #if defined(WIN32) && !defined(__CYGWIN__) setmode(fileno(stdout), O_BINARY); setmode(fileno(stdin), O_BINARY); #endif #if defined(HAVE_LIBINTL_H) && defined(BUILD_LIBINTL) bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); textdomain(GETTEXT_PACKAGE); #endif if (argc == 1) { PrintUsage(""); return 0; } if (((argc == 2) || (argc == 3)) && !strcmp("-", argv[1])) { #if HAVE_GETRUSAGE struct rusage myusage; struct timeval starttime; struct timeval currenttime; gettimeofday(&starttime, NULL); #endif RemoteMode = 1; if ((argc == 3) && strcmp("", argv[2])) { if ( #ifdef HAVE_GETUID getuid() #else 1 #endif == 0) { #ifdef HAVE_CHROOT if (chroot(argv[2]) != 0){ fprintf(stderr, "ERROR: chroot %s: %s\n", argv[2],rrd_strerror(errno)); exit(errno); } ChangeRoot = 1; firstdir = "/"; #else fprintf(stderr, "ERROR: change root is not supported by your OS " "or at least by this copy of rrdtool\n"); exit(1); #endif } else { firstdir = argv[2]; } } if (strcmp(firstdir, "")) { if (chdir(firstdir) != 0){ fprintf(stderr, "ERROR: chdir %s %s\n", firstdir,rrd_strerror(errno)); exit(errno); } } while (fgetslong(&aLine, stdin)) { char *aLineOrig = aLine; if ((argc = CountArgs(aLine)) == 0) { free(aLine); printf("ERROR: not enough arguments\n"); continue; } if ((myargv = (char **) malloc((argc + 1) * sizeof(char *))) == NULL) { perror("malloc"); exit(1); } if ((argc = CreateArgs(argv[0], aLine, myargv)) < 0) { printf("ERROR: creating arguments\n"); } else { if ( HandleInputLine(argc, myargv, stdout) == 0 ){ #if HAVE_GETRUSAGE getrusage(RUSAGE_SELF, &myusage); gettimeofday(¤ttime, NULL); printf("OK u:%1.2f s:%1.2f r:%1.2f\n", (double) myusage.ru_utime.tv_sec + (double) myusage.ru_utime.tv_usec / 1000000.0, (double) myusage.ru_stime.tv_sec + (double) myusage.ru_stime.tv_usec / 1000000.0, (double) (currenttime.tv_sec - starttime.tv_sec) + (double) (currenttime.tv_usec - starttime.tv_usec) / 1000000.0); #else printf("OK\n"); #endif } } fflush(stdout); /* this is important for pipes to work */ free(myargv); free(aLineOrig); } } else if (argc == 2) { PrintUsage(argv[1]); exit(0); } else if (argc == 3 && !strcmp(argv[1], "help")) { PrintUsage(argv[2]); exit(0); } else { exit(HandleInputLine(argc, argv, stderr)); } return 0; }
int AddList(int argc, char **argv) { static char *info[MAX_ARGS_SIZE], **add_args; int status, ret_code = SUB_NORMAL; struct mqelem *elem = NULL; if (!ValidName(argv[1])) return DM_NORMAL; status = do_mr_query("get_list_info", 1, argv + 1, NULL, NULL); if (status != MR_NO_MATCH) { if (status == MR_SUCCESS) Put_message("This list already exists."); else com_err(program_name, status, " in AddList."); return SUB_ERROR; } if (status = mr_access("add_list", L_MODTIME, SetDefaults(info, argv[1]))) { com_err(program_name, status, " in AddList."); return SUB_ERROR; } /* * If the listname is less than 8 characters, make sure it doesn't * collide with a username. */ if ((strlen(argv[1]) <= 8) && do_mr_query("get_user_account_by_login", 1, argv + 1, StoreInfo, &elem) != MR_NO_MATCH) { char buf[256]; sprintf(buf, "\nA user by the name `%s' already exists in the database.", argv[1]); Put_message(buf); Loop(QueueTop(elem), FreeInfo); FreeQueue(elem); if (YesNoQuestion("Create a list with the same name", FALSE) != TRUE) return SUB_ERROR; } if (!(add_args = AskListInfo(SetDefaults(info, argv[1]), FALSE))) { Put_message("Aborted."); return SUB_ERROR; } if ((status = do_mr_query("add_list", CountArgs(add_args), add_args, NULL, NULL)) != MR_SUCCESS) { com_err(program_name, status, " in AddList."); Put_message("List Not Created."); ret_code = SUB_ERROR; } if (atoi(add_args[L_MAILMAN])) { char mailman_address[256], buf[1024]; status = do_mr_query("get_list_info", 1, add_args, StoreInfo, &elem); if (status) com_err(program_name, status, "while retrieving list information."); else { strcpy(mailman_address, add_args[0]); strcat(mailman_address, "@"); strcat(mailman_address, ((char **)elem->q_data)[L_MAILMAN_SERVER]); sprintf(buf, "Add STRING %s to LIST %s", mailman_address, add_args[0]); if (YesNoQuestion(buf, TRUE) == TRUE) { char *args[3]; args[0] = add_args[0]; args[1] = "STRING"; args[2] = mailman_address; status = do_mr_query("add_member_to_list", CountArgs(args), args, NULL, NULL); if (status) com_err(program_name, status, "while adding member to list."); } } } FreeInfo(info); return ret_code; }
int RegisterUser(int argc, char **argv) { char *args[MAX_ARGS_SIZE]; char *login, *potype = NULL; char temp_buf[BUFSIZ]; int status, i; for (i = 0; i < MAX_ARGS_SIZE; i++) args[i] = NULL; Put_message("This function has NO kerberos support, so strange things"); Put_message("may happen if you use it to register a user."); switch (YesNoQuestion("Do you know the users UID Number (y/n)", FALSE)) { case TRUE: Prompt_input("What is the UID number of the user? ", temp_buf, BUFSIZ); args[0] = strdup(temp_buf); break; case FALSE: if (!(args[0] = GetUidNumberFromName())) return DM_NORMAL; break; default: return DM_NORMAL; } sprintf(temp_buf, "u%s", args[0]); login = strdup(temp_buf); if (GetValueFromUser("Login name for this user? ", &login) == SUB_ERROR) { args[1] = login; FreeInfo(args); /* This work because the NULL temination is ok. */ return DM_NORMAL; } Put_message("KERBEROS code not added, did not reserve name with kerberos."); args[1] = login; sprintf(temp_buf, "EXCHANGE"); potype = strdup(temp_buf); if (GetValueFromUser("P.O. Box Type for this user? ", &potype) == SUB_ERROR) { args[2] = potype; FreeInfo(args); return DM_NORMAL; } if (strcmp(potype, "POP") && strcmp(potype, "IMAP") && strcmp(potype, "EXCHANGE")) { sprintf(temp_buf, "Unknown P.O. Box type."); Put_message(temp_buf); FreeInfo(args); return DM_NORMAL; } args[2] = potype; args[3] = NULL; switch ((status = do_mr_query("register_user", CountArgs(args), args, NULL, NULL))) { case MR_SUCCESS: sprintf(temp_buf, "User %s successfully registered.", login); Put_message(temp_buf); SetUserPassword(login); break; case MR_IN_USE: GiveBackLogin(login); sprintf(temp_buf, "The username %s is already in use.", login); Put_message(temp_buf); break; default: com_err(program_name, status, " in register_user"); break; } FreeInfo(args); return DM_NORMAL; }
int AddFS(int argc, char **argv) { char *info[MAX_ARGS_SIZE], **args, buf[BUFSIZ]; int stat; extern Menu nfsphys_menu; if (!ValidName(argv[1])) return DM_NORMAL; if (!(stat = do_mr_query("get_filesys_by_label", 1, argv + 1, NULL, NULL))) { Put_message ("A Filesystem by that name already exists."); return DM_NORMAL; } else if (stat != MR_NO_MATCH) { com_err(program_name, stat, " in AddFS"); return DM_NORMAL; } if (!(args = AskFSInfo(SetDefaults(info, argv[1]), FALSE))) { Put_message("Aborted."); return DM_NORMAL; } stat = do_mr_query("add_filesys", CountArgs(args), args, NULL, NULL); switch (stat) { case MR_NFS: Put_message("That NFS filesystem is not exported."); if (YesNoQuestion("Fix this now (Y/N)", TRUE) == TRUE) { Do_menu(&nfsphys_menu, 0, NULL); if (YesNoQuestion("Retry filesystem creation now (Y/N)", TRUE) == TRUE) { if ((stat = do_mr_query("add_filesys", CountArgs(args), args, NULL, NULL))) com_err(program_name, stat, " in AddFS"); else Put_message("Created."); } } break; case MR_SUCCESS: break; default: com_err(program_name, stat, " in AddFS"); } if (stat == MR_SUCCESS && !strcasecmp(info[FS_L_TYPE], "HOMEDIR")) { static char *val[] = {"def_quota", NULL}; static char *def_quota = NULL; char *argv[Q_QUOTA + 1]; struct mqelem *top = NULL; if (!def_quota) { stat = do_mr_query("get_value", CountArgs(val), val, StoreInfo, &top); if (stat != MR_SUCCESS) com_err(program_name, stat, " getting default quota"); else { top = QueueTop(top); def_quota = strdup(((char **)top->q_data)[0]); FreeQueue(top); } } if (def_quota) { sprintf(buf, "Give user %s a quota of %s on filesys %s (Y/N)", info[FS_NAME], def_quota, info[FS_NAME]); if (YesNoQuestion(buf, 1) == TRUE) { argv[Q_NAME] = argv[Q_FILESYS] = info[FS_NAME]; if (!strcmp(info[FS_TYPE], "NFS")) argv[Q_TYPE] = "USER"; else argv[Q_TYPE] = "ANY"; argv[Q_QUOTA] = def_quota; if ((stat = do_mr_query("add_quota", Q_QUOTA + 1, argv, NULL, NULL))) com_err(program_name, stat, " while adding quota"); } } } else if (stat == MR_SUCCESS) { if (YesNoQuestion("Assign a quota on this filesystem (Y/N)", 1) == TRUE) { parsed_argc = 1; parsed_argv[0] = info[FS_NAME]; AddQuota(parsed_argc, parsed_argv); } } FreeInfo(info); return DM_NORMAL; }
int RemoveMembersOfList(char *name, Bool verbose) { char buf[BUFSIZ], *args[10]; struct mqelem *local, *elem = NULL; int status, members; /* * Get the members of this list. */ status = do_mr_query("get_members_of_list", 1, &name, StoreInfo, &elem); if (status == MR_NO_MATCH) return SUB_NORMAL; if (status) { com_err(program_name, status, " in DeleteList (get_members_of_list)."); return SUB_ERROR; } /* * If verbose mode, then ask the user if we should delete. */ local = elem = QueueTop(elem); if (!(members = QueueCount(elem))) return SUB_NORMAL; if (verbose) { sprintf(buf, "List %s has %d member%s:", name, QueueCount(elem), ((members == 1) ? "" : "s")); Put_message(buf); Put_message(" "); /* Blank Line. */ while (local) { char **info = local->q_data; Print(CountArgs(info), info, NULL); local = local->q_forw; } Put_message(" "); /* Blank Line. */ sprintf(buf, "Remove th%s member%s from list %s? ", ((members == 1) ? "is" : "ese"), ((members == 1) ? "" : "s"), name); if (YesNoQuestion(buf, FALSE) != TRUE) { Put_message("Aborting..."); FreeQueue(elem); return SUB_ERROR; } } /* * Perform The Removal. */ local = elem; args[0] = name; while (local) { char **info = local->q_data; args[1] = info[0]; args[2] = info[1]; if ((status = do_mr_query("delete_member_from_list", 3, args, NULL, NULL))) { com_err(program_name, status, " in delete_member\nAborting\n"); FreeQueue(elem); return SUB_ERROR; } local = local->q_forw; } return SUB_NORMAL; }
void AttemptToDeleteList(char **list_info, Bool ask_first) { int status; struct mqelem *local, *member_of; char *name = list_info[L_NAME]; member_of = NULL; /* * Attempt delete. - will only work if: * 1) This list has no members. * 2) This list in a member of no other lists. * 3) This list is not an ace of another object. */ switch ((status = do_mr_query("delete_list", 1, &name, NULL, NULL))) { case MR_SUCCESS: Put_message("List Sucessfully Deleted."); CheckAce(list_info[L_ACE_TYPE], list_info[L_ACE_NAME], ask_first); break; case MR_IN_USE: /* * This list is in use. Try to find out why, * and for the cases where we have a good idea of * what to do we will query and then do it. */ if ((CheckIfAce(name, "list", ask_first) != SUB_NORMAL) || (RemoveItemFromLists(name, "list", &member_of, ask_first) != SUB_NORMAL)) break; /* * If the list is it's own ACL, then make the person performing * the delete the owner before removing this person from the list */ if (!strcmp(list_info[L_ACE_TYPE], "LIST") && !strcmp(list_info[L_ACE_NAME], list_info[L_NAME])) { free(list_info[L_ACE_TYPE]); free(list_info[L_ACE_NAME]); list_info[L_ACE_TYPE] = strdup("USER"); list_info[L_ACE_NAME] = strdup(user); SlipInNewName(list_info, strdup(list_info[L_NAME])); if ((status = do_mr_query("update_list", CountArgs(list_info) - 3, list_info, NULL, NULL)) != MR_SUCCESS) { com_err(program_name, status, " while updating list owner"); Put_message("List may be only partly deleted."); } } if ((RemoveMembersOfList(name, ask_first) == SUB_NORMAL) && (RealDeleteList(name) == SUB_NORMAL)) { /* if... */ CheckAce(list_info[L_ACE_TYPE], list_info[L_ACE_NAME], ask_first); local = QueueTop(member_of); while (local) { char **info = local->q_data; if (CheckListForDeletion(info[LM_LIST], ask_first) == SUB_ERROR) break; local = local->q_forw; } FreeQueue(member_of); } break; default: com_err(program_name, status, " in DeleteList (delete_list)."); break; } }