int GetUserByReservation(int argc, char **argv) { int stat; struct mqelem *elem = NULL, *top; char buf[BUFSIZ]; switch (stat = do_mr_query("get_user_by_reservation", 1, &argv[1], StoreInfo, &elem)) { case MR_SUCCESS: break; case MR_STRING: sprintf(buf, "The reservation %s is not valid.", argv[1]); Put_message(buf); PrintReservationTypes(); return DM_NORMAL; default: com_err(program_name, stat, " in GetUserByReservation."); return DM_NORMAL; } top = elem = QueueTop(elem); Put_message(""); while (elem) { char **info = elem->q_data; sprintf(buf, "User: %s", info[0]); Put_message(buf); elem = elem->q_forw; } FreeQueue(QueueTop(top)); return DM_NORMAL; }
int GetKrbmap(int argc, char **argv) { int stat; struct mqelem *elem = NULL, *top; char buf[BUFSIZ]; if ((stat = do_mr_query("get_kerberos_user_map", 2, &argv[1], StoreInfo, &elem))) { com_err(program_name, stat, " in GetKrbMap."); return DM_NORMAL; } top = elem = QueueTop(elem); Put_message(""); while (elem) { char **info = elem->q_data; sprintf(buf, "User: %-9s Principal: %s", info[KMAP_USER], info[KMAP_PRINCIPAL]); Put_message(buf); elem = elem->q_forw; } FreeQueue(QueueTop(top)); return DM_NORMAL; }
void PrintReservationTypes(void) { int stat; struct mqelem *elem = NULL, *top; char buf[BUFSIZ]; char *qargs[2]; Put_message("Valid types of reservations are: "); Put_message(""); qargs[0] = "*"; qargs[1] = "RESERVE"; qargs[2] = "*"; if ((stat = do_mr_query("get_alias", 3, &qargs[0], StoreInfo, &elem))) { com_err(program_name, stat, "in PrintReservationTypes."); } top = elem = QueueTop(elem); while (elem) { char **info = elem->q_data; sprintf(buf, "%s", info[2]); Put_message(buf); elem = elem->q_forw; } FreeQueue(QueueTop(top)); }
int GetUserReservations(int argc, char **argv) { int stat; struct mqelem *elem = NULL, *top; char buf[BUFSIZ]; if ((stat = do_mr_query("get_user_reservations", 1, &argv[1], StoreInfo, &elem))) { com_err(program_name, stat, " in GetUserReservations."); return DM_NORMAL; } top = elem = QueueTop(elem); Put_message(""); if (!elem) Put_message("No reservations for that user."); while (elem) { char **info = elem->q_data; sprintf(buf, "Reservation: %s", info[0]); Put_message(buf); elem = elem->q_forw; } FreeQueue(QueueTop(top)); return DM_NORMAL; }
int AddFSToGroup(int argc, char **argv) { int stat, count; struct mqelem *elem = NULL; char buf[BUFSIZ], *args[5], *bufp; if ((stat = do_mr_query("get_fsgroup_members", 1, argv + 1, StoreInfo, &elem))) { if (stat != MR_NO_MATCH) com_err(program_name, stat, " in AddFSToGroup"); } if (elem == NULL) { args[0] = argv[1]; args[1] = argv[2]; args[2] = "M"; stat = do_mr_query("add_filesys_to_fsgroup", 3, args, NULL, NULL); if (stat) com_err(program_name, stat, " in AddFSToGroup"); return DM_NORMAL; } elem = QueueTop(elem); fsgCount = 1; Loop(elem, PrintFSGMembers); sprintf(buf, "%d", QueueCount(elem)); bufp = strdup(buf); if (GetValueFromUser("Enter number of filesystem it should follow " "(0 to make it first):", &bufp) == SUB_ERROR) return DM_NORMAL; count = atoi(bufp); free(bufp); args[2] = SortAfter(elem, count); FreeQueue(QueueTop(elem)); args[0] = argv[1]; args[1] = argv[2]; stat = do_mr_query("add_filesys_to_fsgroup", 3, args, NULL, NULL); if (stat == MR_EXISTS) { Put_message("That filesystem is already a member of the group."); Put_message("Use the order command if you want to change the " "sorting order."); } else if (stat) com_err(program_name, stat, " in AddFSToGroup"); return DM_NORMAL; }
int UpdateNFSService(int argc, char **argv) { int stat; struct mqelem *elem = NULL; char *args[10]; if (!ValidName(argv[1])) return DM_NORMAL; args[0] = canonicalize_hostname(strdup(argv[1])); args[1] = strdup(DEFAULT_DIR); if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR) return DM_NORMAL; if ((stat = do_mr_query("get_nfsphys", 2, args, StoreInfo, &elem))) { com_err(program_name, stat, " in UpdateNFSService."); return DM_NORMAL; } free(args[0]); free(args[1]); /* stop memory leaks. */ elem = QueueTop(elem); QueryLoop(elem, UpdatePrint, RealUpdateNFSService, "Update NFS Service for"); FreeQueue(elem); return DM_NORMAL; }
int ShowNFSService(int argc, char **argv) { int stat; struct mqelem *elem = NULL; char *args[10]; if (!ValidName(argv[1])) return DM_NORMAL; args[0] = canonicalize_hostname(strdup(argv[1])); args[1] = strdup(DEFAULT_DIR); if (GetValueFromUser("Directory:", &args[1]) == SUB_ERROR) return DM_NORMAL; if ((stat = do_mr_query("get_nfsphys", 2, args, StoreInfo, &elem))) com_err(program_name, stat, " in ShowNFSServices."); free(args[0]); free(args[1]); /* prevents memory leaks. */ elem = QueueTop(elem); Loop(elem, (void (*)(char **)) PrintNFSInfo); FreeQueue(elem); return DM_NORMAL; }
static struct mqelem *GetFSInfo(int type, char *name) { int stat; struct mqelem *elem = NULL; char *args[5]; switch (type) { case LABEL: if ((stat = do_mr_query("get_filesys_by_label", 1, &name, StoreInfo, &elem))) { com_err(program_name, stat, " in GetFSInfo"); return NULL; } break; case MACHINE: if ((stat = do_mr_query("get_filesys_by_machine", 1, &name, StoreInfo, &elem))) { com_err(program_name, stat, " in GetFSInfo"); return NULL; } break; case GROUP: if ((stat = do_mr_query("get_filesys_by_group", 1, &name, StoreInfo, &elem))) { com_err(program_name, stat, " in GetFSInfo"); return NULL; } break; case ALIAS: case ALIAS_CHECK: args[ALIAS_NAME] = name; args[ALIAS_TYPE] = FS_ALIAS_TYPE; args[ALIAS_TRANS] = "*"; if ((stat = do_mr_query("get_alias", 3, args, StoreInfo, &elem))) { if (type != ALIAS_CHECK || stat != MR_NO_MATCH) com_err(program_name, stat, " in get_alias."); return NULL; } break; case FS_ALIASES: args[ALIAS_NAME] = "*"; args[ALIAS_TYPE] = FS_ALIAS_TYPE; args[ALIAS_TRANS] = name; if ((stat = do_mr_query("get_alias", 3, args, StoreInfo, &elem))) { if (stat != MR_NO_MATCH) com_err(program_name, stat, " in get_alias."); return NULL; } break; } return QueueTop(elem); }
int DeleteList(int argc, char *argv[]) { char buf[BUFSIZ]; struct mqelem *top, *list; int status; Bool one_list; list = NULL; switch ((status = do_mr_query("get_list_info", 1, argv + 1, StoreInfo, &list))) { case MR_SUCCESS: break; case MR_NO_MATCH: case MR_LIST: Put_message("There is no list that matches that name."); return DM_NORMAL; default: com_err(program_name, status, " in DeleteList (get_list_info)."); return DM_NORMAL; } top = list = QueueTop(list); one_list = (QueueCount(list) == 1); while (list) { char **info = list->q_data; if (one_list) { sprintf(buf, "Are you sure that you want to delete the list %s", info[L_NAME]); if (Confirm(buf)) AttemptToDeleteList(info, TRUE); } else { sprintf(buf, "Delete the list %s", info[L_NAME]); switch (YesNoQuestion(buf, FALSE)) { case TRUE: AttemptToDeleteList(info, TRUE); break; case FALSE: break; default: Put_message("Aborting..."); FreeQueue(top); return DM_QUIT; } } list = list->q_forw; } FreeQueue(top); return DM_NORMAL; }
int CreateFSAlias(int argc, char **argv) { int stat; struct mqelem *elem, *top; char *args[MAX_ARGS_SIZE], buf[BUFSIZ], **info; elem = NULL; if (!ValidName(argv[1])) return DM_NORMAL; args[ALIAS_NAME] = strdup(argv[1]); args[ALIAS_TYPE] = strdup(FS_ALIAS_TYPE); args[ALIAS_TRANS] = strdup("*"); /* * Check to see if this alias already exists in the database, if so then * print out values, free memory used and then exit. */ if (!(stat = do_mr_query("get_alias", 3, args, StoreInfo, &elem))) { top = elem = QueueTop(elem); while (elem) { info = elem->q_data; sprintf(buf, "The alias: %s currently describes the filesystem %s", info[ALIAS_NAME], info[ALIAS_TRANS]); Put_message(buf); elem = elem->q_forw; } FreeQueue(top); return DM_NORMAL; } else if (stat != MR_NO_MATCH) { com_err(program_name, stat, " in CreateFSAlias."); return DM_NORMAL; } args[ALIAS_TRANS] = strdup(""); args[ALIAS_END] = NULL; if (GetValueFromUser("Which filesystem will this alias point to?", &args[ALIAS_TRANS]) == SUB_ERROR) return DM_NORMAL; if ((stat = do_mr_query("add_alias", 3, args, NULL, NULL))) com_err(program_name, stat, " in CreateFSAlias."); FreeInfo(args); return DM_NORMAL; }
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; }
int ShowClients(int argc, char **argv) { int status; struct mqelem *elem = NULL; if ((status = do_mr_query("_list_users", 0, NULL, StoreInfo, &elem))) { com_err(program_name, status, " in ShowClients"); return DM_NORMAL; } Loop(QueueTop(elem), PrintClients); FreeQueue(elem); return DM_NORMAL; }
int TableStats(int argc, char **argv) { int status; struct mqelem *elem = NULL; if ((status = do_mr_query("get_all_table_stats", 0, NULL, StoreInfo, &elem))) { com_err(program_name, status, " in TableStats"); return DM_NORMAL; } Loop(QueueTop(elem), PrintStats); FreeQueue(elem); return DM_NORMAL; }
struct mqelem *GetListInfo(int type, char *name1, char *name2) { char *args[2]; struct mqelem *elem = NULL; int status; switch (type) { case LIST: args[0] = name1; if ((status = do_mr_query("get_list_info", 1, args, StoreInfo, &elem))) { com_err(program_name, status, " in get_list_info"); return NULL; } break; case MEMBERS: args[0] = name1; if ((status = do_mr_query("get_members_of_list", 1, args, StoreInfo, &elem))) { com_err(program_name, status, " in get_members_of_list"); return NULL; } break; case GLOM: args[0] = name1; args[1] = name2; if (!strcmp(name1, "MACHINE")) args[1] = canonicalize_hostname(strdup(name2)); if ((status = do_mr_query("get_lists_of_member", 2, args, StoreInfo, &elem))) { com_err(program_name, status, " in get_list_of_members"); return NULL; } break; case ACE_USE: args[0] = name1; args[1] = name2; if ((status = do_mr_query("get_ace_use", 2, args, StoreInfo, &elem))) { com_err(program_name, status, " in get_ace_use"); return NULL; } break; } return QueueTop(elem); }
static struct mqelem *GetPrnInfo(char *name, int how) { int stat; struct mqelem *elem = NULL; switch (how) { case BY_NAME: stat = do_mr_query("get_printer", 1, &name, StoreInfo, &elem); if (stat == MR_NO_MATCH) { stat = do_mr_query("get_printer_by_duplexname", 1, &name, StoreInfo, &elem); } break; case BY_ETHERNET: stat = do_mr_query("get_printer_by_ethernet", 1, &name, StoreInfo, &elem); break; case BY_HOSTNAME: name = canonicalize_hostname(strdup(name)); stat = do_mr_query("get_printer_by_hostname", 1, &name, StoreInfo, &elem); free(name); break; case BY_RM: name = canonicalize_hostname(strdup(name)); stat = do_mr_query("get_printer_by_rm", 1, &name, StoreInfo, &elem); free(name); break; case BY_LOCATION: stat = do_mr_query("get_printer_by_location", 1, &name, StoreInfo, &elem); break; case BY_CONTACT: stat = do_mr_query("get_printer_by_contact", 1, &name, StoreInfo, &elem); break; } if (stat) { com_err(program_name, stat, " in GetPrnInfo"); return NULL; } return QueueTop(elem); }
struct mqelem *GetUserBySponsor(char *type, char *name) { char *args[2]; struct mqelem *elem = NULL; int status; args[0] = type; args[1] = name; if ((status = do_mr_query("get_user_account_by_sponsor", 2, args, StoreInfo, &elem))) { com_err(program_name, status, " in get_user_account_by_sponsor"); return NULL; } return QueueTop(elem); }
static char *GetUidNumberFromName(void) { char *args[5], *uid, first[BUFSIZ], last[BUFSIZ]; int status; struct mqelem *top = NULL; if (!Prompt_input("First Name: ", first, BUFSIZ)) return NULL; if (!Prompt_input("Last Name: ", last, BUFSIZ)) return NULL; FixCase(first); FixCase(last); args[0] = first; args[1] = last; switch ((status = do_mr_query("get_user_account_by_name", 2, args, StoreInfo, &top))) { case MR_SUCCESS: break; case MR_NO_MATCH: Put_message("There is no user in the database with that name."); return NULL; default: com_err(program_name, status, " in get_account_user_by_name."); return NULL; } top = QueueTop(top); if (QueueCount(top) == 1) /* This is a unique name. */ { char **info = top->q_data; Put_message("User ID Number retrieved for the user: "******""); PrintUserName(info); uid = strdup(info[U_UID]); FreeQueue(top); return strdup(uid); } Put_message("That name is not unique, choose the user that you want."); uid = ChooseUser(top); FreeQueue(top); return uid; }
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."); }
static struct mqelem *GetACLInfo(char *host, char *target) { int stat; struct mqelem *elem = NULL; char *argv[2]; argv[0] = canonicalize_hostname(strdup(host)); argv[1] = target; stat = do_mr_query("get_acl", 2, argv, StoreInfo, &elem); free(argv[0]); if (stat) { com_err(program_name, stat, " in GetACLInfo"); return NULL; } return QueueTop(elem); }
int ShowAlias(int argc, char **argv) { int status; char *info[4]; struct mqelem *elem = NULL; info[0] = argv[1]; info[1] = argv[2]; info[2] = "*"; if ((status = do_mr_query("get_alias", 3, info, StoreInfo, &elem))) { com_err(program_name, status, " in ShowAlias"); return DM_NORMAL; } Loop(QueueTop(elem), PrintAlias); FreeQueue(elem); 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."); }
int GetPrintSrv(int argc, char **argv) { int stat; struct mqelem *elem = NULL, *top; char *name; name = canonicalize_hostname(strdup(argv[1])); stat = do_mr_query("get_print_server", 1, &name, StoreInfo, &elem); if (stat) { com_err(program_name, stat, " in GetPrintSrv"); return DM_NORMAL; } top = QueueTop(elem); Loop(top, (void (*)(char **)) PrintPrintSrvInfo); FreeQueue(top); /* clean the queue. */ return DM_NORMAL; }
static char *PrintPrnInfo(char **info) { char buf[BUFSIZ]; int status, banner = atoi(info[PRN_BANNER]); struct mqelem *elem = NULL; if (!info) /* If no informaion */ { Put_message("PrintPrnInfo called with null info!"); return NULL; } Put_message(""); sprintf(buf, "Printer: %-18s Duplex queue: %-17s Status: %-10s", info[PRN_NAME], *info[PRN_DUPLEXNAME] ? info[PRN_DUPLEXNAME] : "[none]", PrnState(atoi(info[PRN_STATUS]))); Put_message(buf); sprintf(buf, "Duplex by Default: %-8s Hold by Default: %-18s", atoi(info[PRN_DUPLEXDEFAULT]) ? "yes" : "no", atoi(info[PRN_HOLDDEFAULT]) ? "yes" : "no"); Put_message(buf); sprintf(buf, "Type: %-10s Hardware type: %-10s", info[PRN_TYPE], info[PRN_HWTYPE]); Put_message(buf); sprintf(buf, "Printer hostname: %s", info[PRN_HOSTNAME]); Put_message(buf); status = do_mr_query("get_host_hwaddr_mapping", 1, &info[PRN_HOSTNAME], StoreInfo, &elem); if (status) { if (status != MR_NO_MATCH) com_err(program_name, status, " looking up hardware addresses"); else Put_message("Hardware Addresses: none"); } else { hwaddrbuf[0] = 0; Loop(QueueTop(elem), (void (*)(char **)) PrintHWAddrs); FreeQueue(elem); Put_message(hwaddrbuf); } sprintf(buf, "Printer log host: %s", info[PRN_LOGHOST]); Put_message(buf); sprintf(buf, "Spool host: %s", info[PRN_RM]); Put_message(buf); sprintf(buf, "Remote Printer Name: %-38s Banner page: %s", info[PRN_RP], banner ? ( banner == PRN_BANNER_FIRST ? "Yes" : "Last" ) : "No"); Put_message(buf); sprintf(buf, "Authentication: %-3s Price/page: %-3s Quota Server: %s", atoi(info[PRN_KA]) ? "yes" : "no", info[PRN_PC], info[PRN_RQ]); Put_message(buf); sprintf(buf, "Restrict list: %-23s LPC ACL: %-23s", info[PRN_AC], info[PRN_LPC_ACL]); Put_message(buf); sprintf(buf, "Report list: %-23s", info[PRN_REPORT_LIST]); Put_message(buf); sprintf(buf, "Location: %s", info[PRN_LOCATION]); Put_message(buf); sprintf(buf, "Contact: %s", info[PRN_CONTACT]); Put_message(buf); sprintf(buf, MOD_FORMAT, info[PRN_MODBY], info[PRN_MODTIME], info[PRN_MODWITH]); Put_message(buf); return info[PRN_NAME]; }
static char *PrintFSInfo(char **info) { char print_buf[BUFSIZ]; struct mqelem *top; FORMFEED; if (!strcmp(info[FS_TYPE], "FSGROUP") || !strcmp(info[FS_TYPE], "MUL")) { int stat; struct mqelem *elem = NULL; if (!strcmp(info[FS_TYPE], "MUL")) sprintf(print_buf, "%20s Multiple Filesystem: %s", " ", info[FS_NAME]); else sprintf(print_buf, "%20s Filesystem Group: %s", " ", info[FS_NAME]); Put_message(print_buf); top = GetFSInfo(FS_ALIASES, info[FS_NAME]); if (top != NULL) { *aliasbuf = 0; Loop(top, (void (*)(char **))PrintFSAliasList); Put_message(aliasbuf); FreeQueue(top); /* clean the queue. */ } sprintf(print_buf, "Comments: %s", info[FS_COMMENTS]); Put_message(print_buf); sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME], info[FS_MODWITH]); Put_message(print_buf); Put_message("Containing the filesystems (in order):"); if ((stat = do_mr_query("get_fsgroup_members", 1, &info[FS_NAME], StoreInfo, &elem))) { if (stat == MR_NO_MATCH) Put_message(" [no members]"); else com_err(program_name, stat, " in PrintFSInfo"); } else { fsgCount = 1; Loop(QueueTop(elem), PrintFSGMembers); FreeQueue(elem); } } else { sprintf(print_buf, "%20s Filesystem: %s", " ", info[FS_NAME]); Put_message(print_buf); top = GetFSInfo(FS_ALIASES, info[FS_NAME]); if (top != NULL) { *aliasbuf = 0; Loop(top, (void (*)(char **))PrintFSAliasList); Put_message(aliasbuf); FreeQueue(top); /* clean the queue. */ } sprintf(print_buf, "Type: %-40s Machine: %-15s", info[FS_TYPE], info[FS_MACHINE]); Put_message(print_buf); sprintf(print_buf, "Default Access: %-2s Packname: %-17s Mountpoint %s ", info[FS_ACCESS], info[FS_PACK], info[FS_M_POINT]); Put_message(print_buf); sprintf(print_buf, "Comments: %s", info[FS_COMMENTS]); Put_message(print_buf); sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s", info[FS_OWNER], info[FS_OWNERS]); Put_message(print_buf); sprintf(print_buf, "Update Fileserver: %-27s Locker Type: %s", atoi(info[FS_CREATE]) ? "ON" : "OFF", info[FS_L_TYPE]); Put_message(print_buf); sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME], info[FS_MODWITH]); Put_message(print_buf); } return info[FS_NAME]; }
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; }
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; } }
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; }
int RemoveItemFromLists(char *name, char *type, struct mqelem **elem, int verbose) { struct mqelem *local; char *args[10], temp_buf[BUFSIZ]; int lists; int status; args[0] = type; args[1] = name; *elem = NULL; /* * Get all list of which this item is a member, and store them in a queue. */ status = do_mr_query("get_lists_of_member", 2, args, StoreInfo, elem); if (status == MR_NO_MATCH) return SUB_NORMAL; if (status != MR_SUCCESS) { com_err(program_name, status, " in DeleteList (get_lists_of_member)."); return SUB_ERROR; } /* * If verbose mode, ask user of we should remove our list from * all these lists. */ local = *elem = QueueTop(*elem); lists = QueueCount(*elem); if (lists == 0) return SUB_NORMAL; if (verbose) { sprintf(temp_buf, "%s %s is a member of %d other list%s.\n", type, name, lists, ((lists == 1) ? "" : "s")); Put_message(temp_buf); while (local) { char **info = local->q_data; Print(1, &info[GLOM_NAME], (char *) NULL); local = local->q_forw; } Put_message(" "); /* Blank Line. */ sprintf(temp_buf, "Remove %s %s from these lists? ", type, name); if (YesNoQuestion(temp_buf, FALSE) != TRUE) { Put_message("Aborting..."); FreeQueue(*elem); *elem = NULL; return SUB_ERROR; } } /* * Remove this list from all lists that it is a member of. */ local = *elem; args[DM_MEMBER] = name; args[DM_TYPE] = type; while (local) { char **info = local->q_data; args[DM_LIST] = info[GLOM_NAME]; 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; }
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 ChangeFSGroupOrder(int argc, char **argv) { int stat, src, dst, i; struct mqelem *elem = NULL, *top, *tmpelem; char buf[BUFSIZ], *bufp, *args[3]; if ((stat = do_mr_query("get_fsgroup_members", 1, argv + 1, StoreInfo, &elem))) { if (stat == MR_NO_MATCH) { sprintf(buf, "Ether %s is not a filesystem group or it has no members", argv[1]); Put_message(buf); } else com_err(program_name, stat, " in ChangeFSGroupOrder"); return DM_NORMAL; } top = QueueTop(elem); fsgCount = 1; Loop(top, PrintFSGMembers); while (1) { bufp = strdup("1"); if (GetValueFromUser("Enter number of the filesystem to move:", &bufp) == SUB_ERROR) return DM_NORMAL; src = atoi(bufp); free(bufp); if (src < 0) { Put_message("You must enter a positive number (or 0 to abort)."); continue; } else if (src == 0) { Put_message("Aborted."); return DM_NORMAL; } for (elem = top, i = src; i-- > 1 && elem->q_forw; elem = elem->q_forw) ; if (i > 0) { Put_message("You entered a number that is too high"); continue; } break; } while (1) { bufp = strdup("0"); if (GetValueFromUser("Enter number of filesystem it should follow " "(0 to make it first):", &bufp) == SUB_ERROR) return DM_NORMAL; dst = atoi(bufp); free(bufp); if (src == dst || src == dst + 1) { Put_message("That has no effect on the sorting order!"); return DM_NORMAL; } if (dst < 0) { Put_message("You must enter a non-negative number."); continue; } for (tmpelem = top, i = dst; i-- > 1 && tmpelem->q_forw; tmpelem = tmpelem->q_forw) ; if (i > 0) { Put_message("You entered a number that is too high"); continue; } break; } args[2] = SortAfter(top, dst); args[0] = argv[1]; args[1] = ((char **)elem->q_data)[0]; if ((stat = do_mr_query("remove_filesys_from_fsgroup", 2, args, NULL, NULL))) { com_err(program_name, stat, " in ChangeFSGroupOrder"); return DM_NORMAL; } if ((stat = do_mr_query("add_filesys_to_fsgroup", 3, args, NULL, NULL))) com_err(program_name, stat, " in ChangeFSGroupOrder"); return DM_NORMAL; }