X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/blobdiff_plain/ca45701c417aca91d18c287742d3e2aa0dc0b1bc..c1c303a7acdcfbb1b479a6afd2647c575490ea23:/clients/moira/nfs.c diff --git a/clients/moira/nfs.c b/clients/moira/nfs.c index 3da906ea..c50e304a 100644 --- a/clients/moira/nfs.c +++ b/clients/moira/nfs.c @@ -1,40 +1,35 @@ -#if (!defined(lint) && !defined(SABER)) - static char rcsid_module_c[] = "$Header$"; -#endif lint - -/* This is the file nfs.c for the SMS Client, which allows a nieve - * user to quickly and easily maintain most parts of the SMS database. +/* $Id$ + * + * This is the file nfs.c for the Moira Client, which allows users + * to quickly and easily maintain most parts of the Moira database. * It Contains: All functions for manipulating NFS Physical directories. - * + * * Created: 5/6/88 * By: Chris D. Peterson * - * $Source$ - * $Author$ - * $Header$ - * - * Copyright 1988 by the Massachusetts Institute of Technology. - * - * For further information on copyright and distribution - * see the file mit-copyright.h + * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology. + * For copying and distribution information, please see the file + * . */ -#include -#include -#include -#include - -#include "mit-copyright.h" +#include +#include +#include #include "defs.h" #include "f_defs.h" #include "globals.h" -#include "infodefs.h" -/* #include */ +#include +#include +#include + +RCSID("$Header$"); + +char **AskNFSInfo(char **info); #define TYPE_NFS "NFS" -#define DEFAULT_DIR "/mit" +#define DEFAULT_DIR "/u1/lockers" #define DEFAULT_DEVICE "/dev/ra1c" #define DEFAULT_STATUS DEFAULT_YES /* active. */ #define DEFAULT_ALLOC "0" @@ -46,14 +41,11 @@ * Returns: useful string. */ -static char * -UpdatePrint(info) -char ** info; +static char *UpdatePrint(char **info) { - char temp_buf[BUFSIZ]; - sprintf(temp_buf, "Machine %s Directory %s", - info[NFS_NAME], info[NFS_DIR]); - return(Strsave(temp_buf)); /* Small memory leak here, but no good way + char temp_buf[BUFSIZ]; + sprintf(temp_buf, "Machine %s Directory %s", info[NFS_NAME], info[NFS_DIR]); + return strdup(temp_buf); /* Small memory leak here, but no good way to avoid it that I see. */ } @@ -63,97 +55,96 @@ char ** info; * Returns: directory of this nfs server, for DeleteNFSService(). */ -static char * -PrintNFSInfo(info) -char ** info; +static char *PrintNFSInfo(char **info) { - char buf[BUFSIZ], status_buf[BUFSIZ]; - int status = atoi(info[NFS_STATUS]); - Bool is_one = FALSE; - - status_buf[0] = '\0'; /* clear string. */ - - if (status & SMS_FS_STUDENT) { - strcat(status_buf, "Student"); - is_one = TRUE; + char buf[BUFSIZ], status_buf[BUFSIZ]; + int status = atoi(info[NFS_STATUS]); + Bool is_one = FALSE; + + status_buf[0] = '\0'; /* clear string. */ + + if (status & MR_FS_STUDENT) + { + strcat(status_buf, "Student"); + is_one = TRUE; + } + if (status & MR_FS_FACULTY) + { + if (is_one) + strcat(status_buf, " and "); + strcat(status_buf, "Faculty"); + is_one = TRUE; } - if (status & SMS_FS_FACULTY) { - if (is_one) - strcat(status_buf, " and "); - strcat(status_buf, "Faculty"); - is_one = TRUE; + if (status & MR_FS_STAFF) + { + if (is_one) + strcat(status_buf, " and "); + strcat(status_buf, "Staff"); + is_one = TRUE; } - if (status & SMS_FS_STAFF) { - if (is_one) - strcat(status_buf, " and "); - strcat(status_buf, "Staff"); - is_one = TRUE; + if (status & MR_FS_MISC) + { + if (is_one) + strcat(status_buf, " and "); + strcat(status_buf, "Miscellaneous"); } - if (status & SMS_FS_MISC) { - if (is_one) - strcat(status_buf, " and "); - strcat(status_buf, "Miscellaneous"); + /* Add another type here. */ + if (status & MR_FS_GROUPQUOTA) + { + if (is_one) + strcat(status_buf, " / "); + strcat(status_buf, "Group Quotas Enabled"); } - /* Add another type here. */ - - if (status_buf[0] == '\0') - strcat(status_buf, "-- None --"); - - Put_message(""); - sprintf(buf,"Machine: %-20s Directory: %-15s Device: %s", - info[NFS_NAME], info[NFS_DIR], info[NFS_DEVICE]); - Put_message(buf); - sprintf(buf, "Status: %s", status_buf); - Put_message(buf); - sprintf(buf, "Quota Allocated: %-17s Size: %s", - info[NFS_ALLOC], info[NFS_SIZE]); - Put_message(buf); - sprintf(buf, MOD_FORMAT, info[NFS_MODBY], info[NFS_MODTIME], - info[NFS_MODWITH]); - Put_message(buf); - return(info[NFS_DIR]); + + if (status_buf[0] == '\0') + strcat(status_buf, "-- None --"); + + Put_message(""); + sprintf(buf, "Machine: %-20s Directory: %-15s Device: %s", + info[NFS_NAME], info[NFS_DIR], info[NFS_DEVICE]); + Put_message(buf); + sprintf(buf, "Status: %s", status_buf); + Put_message(buf); + sprintf(buf, "Quota Allocated: %-17s Size: %s", + info[NFS_ALLOC], info[NFS_SIZE]); + Put_message(buf); + sprintf(buf, MOD_FORMAT, info[NFS_MODBY], info[NFS_MODTIME], + info[NFS_MODWITH]); + Put_message(buf); + return info[NFS_DIR]; } /* Function Name: AskNFSInfo. - * Description: This function askes the user for information about a + * Description: This function askes the user for information about a * machine and saves it into a structure. * Arguments: info - a pointer the the structure to put the * info into. * Returns: the arglist to make the update call with. */ -char ** -AskNFSInfo(info) -char ** info; +char **AskNFSInfo(char **info) { - /* Also need name of the machine in this structure. */ - - GetValueFromUser("Device for this filsystem", &info[NFS_DEVICE]); - GetFSTypes(&info[NFS_STATUS]); - GetValueFromUser("Allocated Space for this filsystem:",&info[NFS_ALLOC]); - GetValueFromUser("Size of this Filsystem:",&info[NFS_SIZE]); - - FreeAndClear(&info[NFS_MODTIME], TRUE); - FreeAndClear(&info[NFS_MODBY], TRUE); - FreeAndClear(&info[NFS_MODWITH], TRUE); - - return(info); + /* Also need name of the machine in this structure. */ + + if (GetValueFromUser("Device for this filsystem", &info[NFS_DEVICE]) == + SUB_ERROR) + return NULL; + if (GetFSTypes(&info[NFS_STATUS], TRUE) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Allocated Space for this filsystem:", + &info[NFS_ALLOC]) == SUB_ERROR) + return NULL; + if (GetValueFromUser("Size of this Filsystem:", &info[NFS_SIZE]) == + SUB_ERROR) + return NULL; + + FreeAndClear(&info[NFS_MODTIME], TRUE); + FreeAndClear(&info[NFS_MODBY], TRUE); + FreeAndClear(&info[NFS_MODWITH], TRUE); + + return info; } -/* Function Name: GetDirName - * Description: get the directory name. - * Arguments: none. - * Returns: the directory name. - */ - -static char * -GetDirName() -{ - char buf[BUFSIZ]; - if (Prompt_input("Directory: ", buf, BUFSIZ) == -1) - return(NULL); - return(Strsave(buf)); -} /* Function Name: ShowNFSService * Description: This function prints all exported partitions. @@ -161,33 +152,30 @@ GetDirName() * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -ShowNFSService(argc, argv) -int argc; -char **argv; +int ShowNFSService(int argc, char **argv) { - register int stat; - struct qelem *elem = NULL; - char *args[10]; - - if (!ValidName(argv[1])) - return(DM_NORMAL); - - args[0] = CanonicalizeHostname(argv[1]); - if ( (args[1] = GetDirName()) == NULL) - return(DM_NORMAL); - - if ( (stat = sms_query("get_nfsphys", 2, args, - StoreInfo, (char *) &elem)) != SMS_SUCCESS) - com_err(program_name, stat, " in ShowNFSServices."); - free(args[1]); /* prevents memory leaks. */ - - elem = QueueTop(elem); - Loop(elem, (void *) PrintNFSInfo); - - FreeQueue(elem); - return (DM_NORMAL); + 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; } /* Function Name: AddNFSService @@ -196,46 +184,50 @@ char **argv; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -AddNFSService(argc, argv) -char **argv; -int argc; +int AddNFSService(int argc, char **argv) { - char **add_args, *args[10]; - char *info[MAX_ARGS_SIZE]; - int stat; - - args[0] = CanonicalizeHostname(argv[1]); - if ( (args[1] = GetDirName()) == NULL) - return(DM_NORMAL); - - if (!ValidName(args[0]) || !ValidName(args[1])) - return(DM_NORMAL); - - if ( (stat = sms_query("get_nfsphys", 2, args, - NullFunc, (char *) NULL)) == SMS_SUCCESS) - Put_message("This service already exists."); - if (stat != SMS_NO_MATCH) - com_err(program_name, stat, " in get_nfsphys."); - - info[NFS_NAME] = Strsave(args[0]); - info[NFS_DIR] = args[1]; /* already saved. */ - info[NFS_DEVICE] = Strsave(DEFAULT_DEVICE); - info[NFS_STATUS] = Strsave(DEFAULT_STATUS); - info[NFS_ALLOC] = Strsave(DEFAULT_ALLOC); - info[NFS_SIZE] = Strsave(DEFAULT_SIZE); - info[NFS_MODBY] = info[NFS_MODWITH] = info[NFS_MODTIME] = NULL; - info[NFS_END] = NULL; - - add_args = AskNFSInfo(info); - - if ((stat = sms_query("add_nfsphys", CountArgs(add_args), add_args, - Scream, (char *) NULL)) != 0) - com_err(program_name, stat, " in AdsNFSService"); - - FreeInfo(info); - return (DM_NORMAL); + 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; } /* Function Name: RealUpdateNFSService @@ -245,19 +237,20 @@ int argc; * Returns: none. */ -/* ARGSUSED */ -static void -RealUpdateNFSService(info, junk) -char ** info; -Bool junk; +static void RealUpdateNFSService(char **info, Bool junk) { - char ** args; - register int stat; - - args = AskNFSInfo(info); - if ((stat = sms_query("update_nfsphys", CountArgs(args), args, - Scream, (char *)NULL)) != SMS_SUCCESS) - com_err(program_name, stat, (char *) NULL); + 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"); } /* Function Name: UpdateNFSService @@ -266,36 +259,33 @@ Bool junk; * Returns: DM_NORMAL. */ -/* ARGSUSED. */ -int -UpdateNFSService(argc, argv) -char **argv; -int argc; +int UpdateNFSService(int argc, char **argv) { - register int stat; - struct qelem *elem = NULL; - char * args[10]; - - if (!ValidName(argv[1])) - return(DM_NORMAL); - - args[0] = CanonicalizeHostname(argv[1]); - if ( (args[1] = GetDirName()) == NULL) - return(DM_NORMAL); - - if ( (stat = sms_query("get_nfsphys", 2, args, - StoreInfo, (char *) &elem)) != SMS_SUCCESS) { - com_err(program_name, stat, " in UpdateNFSService."); - return (DM_NORMAL); + 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[1]); /* stop memory leaks. */ + free(args[0]); + free(args[1]); /* stop memory leaks. */ - elem = QueueTop(elem); - QueryLoop(elem, UpdatePrint, RealUpdateNFSService, - "Update NFS Service for"); + elem = QueueTop(elem); + QueryLoop(elem, UpdatePrint, RealUpdateNFSService, "Update NFS Service for"); - FreeQueue(elem); - return (DM_NORMAL); + FreeQueue(elem); + return DM_NORMAL; } /* Function Name: FSPartPrint @@ -304,13 +294,11 @@ int argc; * Returns: none. */ -static void -FSPartPrint(info) -char ** info; +static void FSPartPrint(char **info) { - char buf[BUFSIZ]; - sprintf(buf, "NFS Filesystem %s uses that partition.", info[FS_NAME]); - Put_message(buf); + char buf[BUFSIZ]; + sprintf(buf, "NFS Filesystem %s uses that partition.", info[FS_NAME]); + Put_message(buf); } /* Function Name: RealDeleteNFSService @@ -321,52 +309,50 @@ char ** info; * Returns: none. */ -static void -RealDeleteNFSService(info, one_item) -char ** info; -Bool one_item; +static void RealDeleteNFSService(char **info, Bool one_item) { - char temp_buf[BUFSIZ], *args[10]; - struct qelem *elem= NULL; - register 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 = sms_query("get_filesys_by_nfsphys", CountArgs(args), - args, StoreInfo, &elem)) { - case SMS_NO_MATCH: /* it is unused, delete it. */ - if ( (stat = sms_query("delete_nfsphys", 2, info, Scream, - (char *) NULL )) != SMS_SUCCESS) - com_err(program_name, stat, " in DeleteNFSService"); - else - Put_message("Physical Filesystem Deleted."); - break; - case SMS_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; + 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"); + com_err(program_name, stat, " while checking usage of partition"); } } - else - Put_message("Physical filesystem not deleted."); + else + Put_message("Physical filesystem not deleted."); } /* Function Name: DeleteNFSService @@ -375,50 +361,37 @@ Bool one_item; * Returns: DM_NORMAL. */ -/* ARGSUSED */ -int -DeleteNFSService(argc, argv) -int argc; -char **argv; +int DeleteNFSService(int argc, char **argv) { - register int stat; - struct qelem *elem = NULL; - char * args[10]; - - if (!ValidName(argv[1])) - return(DM_NORMAL); - - args[0] = CanonicalizeHostname(argv[1]); - if ( (args[1] = GetDirName()) == NULL) - return(DM_NORMAL); - - switch(stat = sms_query("get_nfsphys", 2, args, - StoreInfo, (char *) &elem)) { - case SMS_NO_MATCH: - Put_message("This filsystem does not exist!"); - return(DM_NORMAL); - case SMS_SUCCESS: - break; + 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; + + switch ((stat = do_mr_query("get_nfsphys", 2, args, StoreInfo, &elem))) + { + case MR_NO_MATCH: + Put_message("This filsystem does not exist!"); + return DM_NORMAL; + case MR_SUCCESS: + break; default: - com_err(program_name, stat, " in DeleteNFSService"); - return(DM_NORMAL); + com_err(program_name, stat, " in DeleteNFSService"); + return DM_NORMAL; } - free(args[1]); /* stop memory leaks, in your neighborhood. */ - - QueryLoop(elem, PrintNFSInfo, RealDeleteNFSService, - "Delete the Physical Filesystem on Directory"); - - FreeQueue(elem); - return(DM_NORMAL); -} - -/* - * Local Variables: - * mode: c - * c-indent-level: 4 - * c-continued-statement-offset: 4 - * c-brace-offset: -4 - * c-argdecl-indent: 4 - * c-label-offset: -4 - * End: - */ + free(args[0]); + free(args[1]); /* stop memory leaks, in your neighborhood. */ + + QueryLoop(elem, PrintNFSInfo, RealDeleteNFSService, + "Delete the Physical Filesystem on Directory"); + + FreeQueue(elem); + return DM_NORMAL; +}