]> andersk Git - moira.git/blobdiff - clients/moira/quota.c
Code style cleanup. (No functional changes)
[moira.git] / clients / moira / quota.c
index 89be5aec997a3a18264d53b928df4bb89b40de9e..a019916c668234f1acd67349fc5c1bbe4ea04f64 100644 (file)
@@ -1,26 +1,27 @@
 #if (!defined(lint) && !defined(SABER))
   static char rcsid_module_c[] = "$Header$";
-#endif lint
+#endif
 
 /*     This is the file quota.c for the MOIRA Client, which allows a nieve
  *      user to quickly and easily maintain most parts of the MOIRA database.
  *     It Contains: Functions for manipulating the quota information.
- *     
+ *
  *     Created:        7/10/88
  *     By:             Chris D. Peterson
  *
  *      $Source$
  *      $Author$
  *      $Header$
- *     
+ *
  *     Copyright 1988 by the Massachusetts Institute of Technology.
  *
- *     For further information on copyright and distribution 
+ *     For further information on copyright and distribution
  *     see the file mit-copyright.h
  */
 
 #include <stdio.h>
-#include <strings.h>
+#include <stdlib.h>
+#include <string.h>
 #include <moira.h>
 #include <moira_site.h>
 #include <menu.h>
 #include "f_defs.h"
 #include "globals.h"
 
-static char * def_quota = NULL;        
-  
+static char *def_quota = NULL;
+
 #define DEFAULT_FILESYS DEFAULT_NONE
 #define DEFAULT_USER user      /* this is the user who started moira. */
-#define NOBODY "\\[nobody\\]"
+#define NOBODY "[nobody]"
 #define DEFAULT_QTYPE   "USER"
 
 
@@ -46,51 +47,51 @@ static char * def_quota = NULL;
  *            one, and it works, so why fuck with it.
  */
 
-static char *
-GetDefaultUserQuota(override)
-Bool override;
+static char *GetDefaultUserQuota(Bool override)
 {
   register int status;
-  char ** info;
-  struct qelem * top = NULL;
+  char **info;
+  struct qelem *top = NULL;
   static char *val[] = {"def_quota", NULL};
 
-  if (override || (def_quota == NULL)) {
-    if ( (status = do_mr_query("get_value", CountArgs(val), val,
-                               StoreInfo, (char *) &top)) != MR_SUCCESS) {
-       com_err(program_name, status, " in ShowDefaultQuota");
-       if (def_quota == NULL) {
-         Put_message("No default Quota Found, setting default to 0.");
-         def_quota = Strsave("0");
+  if (override || (def_quota == NULL))
+    {
+      if ((status = do_mr_query("get_value", CountArgs(val), val,
+                               StoreInfo, (char *) &top)))
+       {
+         com_err(program_name, status, " in ShowDefaultQuota");
+         if (!def_quota)
+           {
+             Put_message("No default Quota Found, setting default to 0.");
+             def_quota = Strsave("0");
+           }
+         else
+           Put_message("No default Quota Found, retaining old value.");
+       }
+      else
+       {
+         top = QueueTop(top);
+         info = (char **) top->q_data;
+         FreeAndClear(&def_quota, TRUE);
+         def_quota = Strsave(info[0]);
+         FreeQueue(top);
        }
-       else
-         Put_message("No default Quota Found, retaining old value.");
-      }
-    else {
-      top = QueueTop(top);
-      info = (char **) top->q_data;
-      FreeAndClear(&def_quota, TRUE);
-      def_quota = Strsave(info[0]);
-      FreeQueue(top);
     }
-  }
-  return(def_quota);
+  return def_quota;
 }
-    
+
 /*     Function Name: PrintDefaultQuota
  *     Description: Prints default quota info in a meaningful way.
  *     Arguments: value of the default quota.
  *     Returns: none.
  */
 
-static void
-PrintDefaultQuota(quota)
-char * quota;
+static void PrintDefaultQuota(char *quota)
 {
-    char temp_buf[BUFSIZ];
-    Put_message("");
-    sprintf(temp_buf,"The default quota is %s Kb.", quota);
-    Put_message(temp_buf);
+  char temp_buf[BUFSIZ];
+  Put_message("");
+  sprintf(temp_buf, "The default quota is %s Kb.", quota);
+  Put_message(temp_buf);
 }
 
 /*     Function Name: PrintQuota
@@ -99,56 +100,48 @@ char * quota;
  *     Returns: none.
  */
 
-static char *
-PrintQuota(info)
-char ** info;
+static char *PrintQuota(char **info)
 {
-    char buf[BUFSIZ];
-
-    Put_message("");
-
-    if (!strcmp(info[Q_TYPE], "ANY"))
-      sprintf(buf, "Filesystem: %s", info[Q_FILESYS]);
-    else
-      sprintf(buf, "Filesystem: %-45s %s %s", info[Q_FILESYS],
-             info[Q_TYPE], info[Q_NAME]);
-    Put_message(buf);
-    sprintf(buf, "Machine: %-20s Directory: %-15s",
-                  info[Q_MACHINE], info[Q_DIRECTORY]);
-    Put_message(buf);
-    sprintf(buf, "Quota: %s", info[Q_QUOTA]);
-    Put_message(buf);
-    sprintf(buf, MOD_FORMAT, info[Q_MODBY], info[Q_MODTIME], info[Q_MODWITH]);
-    Put_message(buf);
-    return(info[Q_FILESYS]);
+  char buf[BUFSIZ];
+
+  Put_message("");
+
+  if (!strcmp(info[Q_TYPE], "ANY"))
+    sprintf(buf, "Filesystem: %s", info[Q_FILESYS]);
+  else
+    sprintf(buf, "Filesystem: %-45s %s %s", info[Q_FILESYS],
+           info[Q_TYPE], info[Q_NAME]);
+  Put_message(buf);
+  sprintf(buf, "Machine: %-20s Directory: %-15s",
+         info[Q_MACHINE], info[Q_DIRECTORY]);
+  Put_message(buf);
+  sprintf(buf, "Quota: %s", info[Q_QUOTA]);
+  Put_message(buf);
+  sprintf(buf, MOD_FORMAT, info[Q_MODBY], info[Q_MODTIME], info[Q_MODWITH]);
+  Put_message(buf);
+  return info[Q_FILESYS];
 }
 
 
-afsfilsyshelper(argc, argv, hint)
-int argc;
-char **argv;
-int *hint;
+int afsfilsyshelper(int argc, char **argv, int *hint)
 {
-    *hint = !strcmp(argv[FS_TYPE], "AFS");
-    return(0);
+  *hint = !strcmp(argv[FS_TYPE], "AFS");
+  return 0;
 }
 
 
-int afsfilesys(name)
-char *name;
+int afsfilesys(char *name)
 {
-    int status, ret = 0;
-    char *argv[1];
-
-    if (index(name, '*') || index(name, '?') || index(name, '\\'))
-      return(0);
-    argv[0] = name;
-    status = do_mr_query("get_filesys_by_label", 1, argv,
-                         afsfilsyshelper, &ret);
-    if (status == MR_SUCCESS)
-      return(ret);
-    return(0);
-    
+  int status, ret = 0;
+  char *argv[1];
+
+  if (strchr(name, '*') || strchr(name, '?') || strchr(name, '\\'))
+    return 0;
+  argv[0] = name;
+  status = do_mr_query("get_filesys_by_label", 1, argv, afsfilsyshelper, &ret);
+  if (status == MR_SUCCESS)
+    return ret;
+  return status;
 }
 
 
@@ -158,49 +151,69 @@ char *name;
  *     Returns: the arguments.
  */
 
-static char **
-GetQuotaArgs(quota)
-Bool quota;
+static char **GetQuotaArgs(Bool quota)
 {
-  char ** args = (char **) malloc( MAX_ARGS_SIZE * sizeof(char *) );
-  
-  if (args == NULL) {
-    Put_message("Could not allocate memory in GetQuotaArgs.");
-    return(NULL);
-  }
+  char **args = malloc(MAX_ARGS_SIZE * sizeof(char *));
+  int af;
+
+  if (!args)
+    {
+      Put_message("Could not allocate memory in GetQuotaArgs.");
+      return NULL;
+    }
 
   args[Q_FILESYS] = Strsave(DEFAULT_FILESYS);
   args[Q_TYPE] = Strsave(DEFAULT_QTYPE);
   args[Q_NAME] = Strsave(DEFAULT_USER);
-  if (quota) {
-    args[Q_QUOTA] = Strsave(GetDefaultUserQuota(FALSE));
-    args[Q_QUOTA+1] = NULL;    /* NULL terminate. */
-  }
-  else 
-    args[Q_NAME+1] = NULL;     /* NULL terminate. */
+  if (quota)
+    {
+      args[Q_QUOTA] = Strsave(GetDefaultUserQuota(FALSE));
+      args[Q_QUOTA + 1] = NULL;        /* NULL terminate. */
+    }
+  else
+    args[Q_NAME + 1] = NULL;   /* NULL terminate. */
 
   /* Get filesystem. */
 
-  GetValueFromUser("Filesystem", &args[Q_FILESYS]);
+  if (GetValueFromUser("Filesystem", &args[Q_FILESYS]) == SUB_ERROR)
+    return NULL;
   if (quota && !ValidName(args[Q_FILESYS]))
-    return(NULL);
-  if (afsfilesys(args[Q_FILESYS])) {
-    args[Q_TYPE] = strsave("ANY");
-    args[Q_NAME] = strsave(NOBODY);
-  }
-  else {
-    GetTypeFromUser("Quota type", "quota_type", &args[Q_TYPE]);
-    GetValueFromUser("Name", &args[Q_NAME]);
-    if (!ValidName(args[Q_NAME])) return(NULL);
-  }
-
-  if (quota) {                 /* Get and check quota. */
-    GetValueFromUser("Quota", &args[Q_QUOTA]);
-    if (!ValidName(args[Q_QUOTA])) return(NULL);
-  }
-  return(args);
-}  
+    return NULL;
+
+  af = afsfilesys(args[Q_FILESYS]);
+  if (af != 0 && af != 1)
+    {
+      if (af == MR_NO_MATCH)
+       Put_message("That filesystem does not exist.");
+      else
+       com_err(program_name, af, " in afsfilesys");
+      return NULL;
+    }
+  if (af)
+    {
+      args[Q_TYPE] = strsave("ANY");
+      args[Q_NAME] = strsave(NOBODY);
+    }
+  else
+    {
+      if (GetTypeFromUser("Quota type", "quota_type", &args[Q_TYPE]) ==
+         SUB_ERROR)
+       return NULL;
+      if (GetValueFromUser("Name", &args[Q_NAME]) == SUB_ERROR)
+       return NULL;
+      if (!ValidName(args[Q_NAME]))
+       return NULL;
+    }
+
+  if (quota)                   /* Get and check quota. */
+    {
+      if (GetValueFromUser("Quota", &args[Q_QUOTA]) == SUB_ERROR)
+       return NULL;
+      if (!ValidName(args[Q_QUOTA]))
+       return NULL;
+    }
+  return args;
+}
 
 /*     Function Name: ShowDefaultQuota
  *     Description: This prints out a default quota for the system.
@@ -208,11 +221,10 @@ Bool quota;
  *     Returns: DM_NORMAL.
  */
 
-int
-ShowDefaultQuota()
+int ShowDefaultQuota(void)
 {
   PrintDefaultQuota(GetDefaultUserQuota(TRUE));
-  return (DM_NORMAL);
+  return DM_NORMAL;
 }
 
 /*     Function Name: ChangeDefaultQuota
@@ -221,37 +233,35 @@ ShowDefaultQuota()
  *     Returns: DM_NORMAL.
  */
 
-/*ARGSUSED*/
-int
-ChangeDefaultQuota(argc, argv)
-int argc;
-char *argv[];
+int ChangeDefaultQuota(int argc, char *argv[])
 {
-    register int status;
-    char temp_buf[BUFSIZ];
-    static char *newval[] = {
-       "def_quota", NULL, NULL
-    };
-
-    if (!ValidName(argv[1]))
-       return(DM_NORMAL);
-
-    sprintf(temp_buf,"%s %s","Are you sure that you want to",
-           "change the default quota for all new users");
-    if(Confirm(temp_buf)) {
-       newval[1] = argv[1];
-       if ( (status = do_mr_query("update_value", CountArgs(newval), 
-                                   newval, Scream, NULL)) == MR_SUCCESS ) {
+  register int status;
+  char temp_buf[BUFSIZ];
+  static char *newval[] = {
+    "def_quota", NULL, NULL
+  };
+
+  if (!ValidName(argv[1]))
+    return DM_NORMAL;
+
+  sprintf(temp_buf, "%s %s", "Are you sure that you want to",
+         "change the default quota for all new users");
+  if (Confirm(temp_buf))
+    {
+      newval[1] = argv[1];
+      if ((status = do_mr_query("update_value", CountArgs(newval),
+                               newval, Scream, NULL)) == MR_SUCCESS)
+       {
          FreeAndClear(&def_quota, TRUE);
          def_quota = Strsave(argv[1]);
        }
-       else
-           com_err(program_name, status, " in update_value");
+      else
+       com_err(program_name, status, " in update_value");
     }
-    else
-       Put_message("Quota not changed.");
+  else
+    Put_message("Quota not changed.");
 
-    return (DM_NORMAL);
+  return DM_NORMAL;
 }
 
 /* ------------------------ Filesystem Quotas -------------------- */
@@ -263,18 +273,17 @@ char *argv[];
  *      Returns: DM_NORMAL
  */
 
-int
-GetQuota()
+int GetQuota(void)
 {
   struct qelem *top = NULL;
   register int status;
-  char ** args;
+  char **args;
 
-  if ( (args = GetQuotaArgs(FALSE) ) == NULL)
-    return(DM_NORMAL);
+  if (!(args = GetQuotaArgs(FALSE)))
+    return DM_NORMAL;
 
-  if (( status = do_mr_query("get_quota", CountArgs(args), args,
-                            StoreInfo, (char *) &top)) != MR_SUCCESS)
+  if ((status = do_mr_query("get_quota", CountArgs(args), args,
+                           StoreInfo, (char *) &top)) != MR_SUCCESS)
     com_err(program_name, status, " in get_quota");
 
   FreeInfo(args);
@@ -284,7 +293,7 @@ GetQuota()
   Loop(top, (void *) PrintQuota);
 
   FreeQueue(top);
-  return(DM_NORMAL);
+  return DM_NORMAL;
 }
 
 /*        Function Name: GetQuotaByFilesys
@@ -294,23 +303,25 @@ GetQuota()
  *        Returns: DM_NORMAL
  */
 
-int
-GetQuotaByFilesys()
+int GetQuotaByFilesys(void)
 {
   struct qelem *top = NULL;
   register int status;
-  char **args = (char**)malloc(2*sizeof(char*));
+  char **args = malloc(2 * sizeof(char *));
 
-  if (args == NULL) {
-    Put_message("Could not allocate memory in GetQuotaByFilesys.");
-    return(DM_NORMAL);
-  }
+  if (!args)
+    {
+      Put_message("Could not allocate memory in GetQuotaByFilesys.");
+      return DM_NORMAL;
+    }
 
-  args[0] = args[1] = NULL;
-  GetValueFromUser("Filesystem", &args[0]);
+  args[0] = Strsave("");
+  args[1] = NULL;
+  if (GetValueFromUser("Filesystem", &args[0]) == SUB_ERROR)
+    return DM_NORMAL;
 
-  if (( status = do_mr_query("get_quota_by_filesys", 1, args,
-                            StoreInfo, (char *) &top)) != MR_SUCCESS)
+  if ((status = do_mr_query("get_quota_by_filesys", 1, args,
+                           StoreInfo, (char *) &top)) != MR_SUCCESS)
     com_err(program_name, status, " in get_quota_by_filesys");
 
   FreeInfo(args);
@@ -320,7 +331,7 @@ GetQuotaByFilesys()
   Loop(top, (void *) PrintQuota);
 
   FreeQueue(top);
-  return(DM_NORMAL);
+  return DM_NORMAL;
 }
 
 /*        Function Name: AddQuota
@@ -329,22 +340,21 @@ GetQuotaByFilesys()
  *        Arguments: None
  *        Returns: DM_NORMAL
  */
-int
-AddQuota()
+int AddQuota(void)
 {
-  char ** args;
+  char **args;
   register int status;
-  
-  if ( (args = GetQuotaArgs(TRUE) ) == NULL)
-    return(DM_NORMAL);
 
-  if ( (status = do_mr_query("add_quota", CountArgs(args), args,
-                             Scream, (char *) NULL)) != MR_SUCCESS)
+  if (!(args = GetQuotaArgs(TRUE)))
+    return DM_NORMAL;
+
+  if ((status = do_mr_query("add_quota", CountArgs(args), args,
+                           Scream, NULL)) != MR_SUCCESS)
     com_err(program_name, status, " in add_quota");
-  
+
   FreeInfo(args);
   free(args);
-  return(DM_NORMAL);
+  return DM_NORMAL;
 }
 
 /*     Function Name: RealUpdateQuota
@@ -353,23 +363,26 @@ AddQuota()
  *     Returns: none.
  */
 
-static void
-RealUpdateQuota(info)
-char ** info;
+static void RealUpdateQuota(char **info)
 {
   register int status;
   char temp_buf[BUFSIZ];
 
   sprintf(temp_buf, "New quota for filesystem %s (in KB)", info[Q_FILESYS]);
-  GetValueFromUser(temp_buf, &info[Q_QUOTA]);
+  if (GetValueFromUser(temp_buf, &info[Q_QUOTA]) == SUB_ERROR)
+    {
+      Put_message("Not changed.");
+      return;
+    }
 
   if (status = do_mr_query("update_quota", 4, info,
-                           Scream, (char *) NULL) != MR_SUCCESS) {
-    com_err(program_name, status, " in update_quota");
-    sprintf(temp_buf,"Could not perform quota change on %s",
-           info[Q_FILESYS]); 
-    Put_message(temp_buf);
-  }
+                           Scream, NULL) != MR_SUCCESS)
+    {
+      com_err(program_name, status, " in update_quota");
+      sprintf(temp_buf, "Could not perform quota change on %s",
+             info[Q_FILESYS]);
+      Put_message(temp_buf);
+    }
 }
 
 /*        Function Name: UpdateQuota
@@ -379,27 +392,26 @@ char ** info;
  *        Returns: DM_NORMAL
  */
 
-int
-UpdateQuota()
+int UpdateQuota(void)
 {
   int status;
   char **args;
   struct qelem *top = NULL;
-  
-  if ( (args = GetQuotaArgs(FALSE) ) == NULL)
-    return(DM_NORMAL);
 
-  if ( (status = do_mr_query("get_quota", CountArgs(args), args,
-                             StoreInfo, (char *) &top)) != MR_SUCCESS)
+  if (!(args = GetQuotaArgs(FALSE)))
+    return DM_NORMAL;
+
+  if ((status = do_mr_query("get_quota", CountArgs(args), args,
+                           StoreInfo, (char *) &top)) != MR_SUCCESS)
     com_err(program_name, status, " in get_quota");
-  
+
   FreeInfo(args);              /* done with args, free them. */
   free(args);
   top = QueueTop(top);
   Loop(top, RealUpdateQuota);
 
   FreeQueue(top);
-  return (DM_NORMAL);
+  return DM_NORMAL;
 }
 
 
@@ -411,31 +423,31 @@ UpdateQuota()
  *     Returns: none.
  */
 
-static void
-RealDeleteQuota(info, one_item)
-char ** info;
-Bool one_item;
+static void RealDeleteQuota(char **info, Bool one_item)
 {
   register int status;
   char temp_buf[BUFSIZ];
 
   if (!strcmp(info[Q_TYPE], "ANY"))
-    sprintf(temp_buf,
-           "Do you really want to delete the quota on %s",
-           info[Q_FILESYS]);
+    {
+      sprintf(temp_buf, "Do you really want to delete the quota on %s",
+             info[Q_FILESYS]);
+    }
   else
-    sprintf(temp_buf,
-           "Do you really want to delete the %s %s's quota on %s",
-           (strcmp(info[Q_TYPE], "USER") ? "group" : "user"),
-           info[Q_NAME], info[Q_FILESYS]);
-
-  if (!one_item || Confirm(temp_buf)) {
-    if ( (status = do_mr_query("delete_quota", 3, info,
-                               Scream, (char *) NULL)) != MR_SUCCESS)
-      com_err(program_name, status, " in delete_quota");
-    else
-      Put_message("Quota sucessfully removed.");
-  }
+    {
+      sprintf(temp_buf, "Do you really want to delete the %s %s's quota on %s",
+             (strcmp(info[Q_TYPE], "USER") ? "group" : "user"), info[Q_NAME],
+             info[Q_FILESYS]);
+    }
+
+  if (!one_item || Confirm(temp_buf))
+    {
+      if ((status = do_mr_query("delete_quota", 3, info,
+                               Scream, NULL)) != MR_SUCCESS)
+       com_err(program_name, status, " in delete_quota");
+      else
+       Put_message("Quota sucessfully removed.");
+    }
   else
     Put_message("Aborted.");
 }
@@ -447,18 +459,17 @@ Bool one_item;
  *        Returns: DM_NORMAL
  */
 
-int
-DeleteQuota()
+int DeleteQuota(void)
 {
   register int status;
   char **args;
   struct qelem *top = NULL;
 
-  if ( (args = GetQuotaArgs(FALSE) ) == NULL)
-    return(DM_NORMAL);
+  if (!(args = GetQuotaArgs(FALSE)))
+    return DM_NORMAL;
 
-  if ( (status = do_mr_query("get_quota", 3, args,
-                             StoreInfo, (char *) &top)) != MR_SUCCESS)
+  if ((status = do_mr_query("get_quota", 3, args,
+                           StoreInfo, (char *) &top)))
     com_err(program_name, status, " in get_quota");
 
   FreeInfo(args);
@@ -468,7 +479,5 @@ DeleteQuota()
            "Delete this quota on filesystem");
 
   FreeQueue(top);
-  return(DM_NORMAL);
+  return DM_NORMAL;
 }
-
-  
This page took 0.232226 seconds and 4 git commands to generate.