]> andersk Git - moira.git/commitdiff
setup_alis: don't allow lists to be created/renamed with a lowercased
authordanw <danw>
Mon, 28 Dec 1998 17:42:13 +0000 (17:42 +0000)
committerdanw <danw>
Mon, 28 Dec 1998 17:42:13 +0000 (17:42 +0000)
version of an existing partially-uppercase name.

setup_ahst, hostinfo_check: the "model" field can start with a number.

server/qsetup.pc

index 7ba1777c206cf69528c60869fdf9ebb794d0f0a1..566e632df85f0b801006bbb38be7ac0eca523295 100644 (file)
@@ -32,7 +32,8 @@ EXEC SQL END DECLARE SECTION;
 
 EXEC SQL WHENEVER SQLERROR DO dbmserr();
 
-
+int hostname_check(char *name);
+int hostinfo_check(char *name, int num);
 int prefetch_value(struct query *q, char **argv, client *cl);
 int check_nfs(int mach_idx, char *name, char *access);
 
@@ -306,7 +307,8 @@ static int badlistchars[] = {
 int setup_alis(struct query *q, char *argv[], client *cl)
 {
   EXEC SQL BEGIN DECLARE SECTION;
-  int ngid;
+  int ngid, cnt;
+  char *name;
   EXEC SQL END DECLARE SECTION;
   unsigned char *p;
   int idx, err;
@@ -315,6 +317,7 @@ int setup_alis(struct query *q, char *argv[], client *cl)
     idx = 0;
   else if (!strcmp(q->shortname, "ulis"))
     idx = 1;
+  name = argv[idx];
 
   if (idx == 1)
     {
@@ -326,12 +329,19 @@ int setup_alis(struct query *q, char *argv[], client *cl)
        return MR_PERM;
     }
 
-  for (p = (unsigned char *) argv[idx]; *p; p++)
+  for (p = (unsigned char *) name; *p; p++)
     {
       if (badlistchars[*p])
        return MR_BAD_CHAR;
     }
 
+  /* Check that it doesn't conflict with a pre-existing weirdly-cased
+   * name. */
+  EXEC SQL SELECT COUNT(name) INTO :cnt FROM list
+    WHERE LOWER(name) = :name;
+  if (cnt)
+    return MR_EXISTS;
+
   if (!strcmp(argv[6 + idx], UNIQUE_GID) || atoi(argv[6 + idx]) == -1)
     {
       if (atoi(argv[5 + idx]))
@@ -863,13 +873,13 @@ int setup_ahst(struct query *q, char **argv, client *cl)
       !hostname_check(argv[row]))
     return MR_BAD_CHAR;
   if ((row == 0 || strcasecmp(argv[2], vendor)) &&
-      !hostinfo_check(argv[row + 1]))
+      !hostinfo_check(argv[row + 1], 0))
     return MR_BAD_CHAR;
   if ((row == 0 || strcasecmp(argv[3], model)) &&
-      !hostinfo_check(argv[row + 2]))
+      !hostinfo_check(argv[row + 2], 1))
     return MR_BAD_CHAR;
   if ((row == 0 || strcasecmp(argv[4], os)) &&
-      !hostinfo_check(argv[row + 3]))
+      !hostinfo_check(argv[row + 3], 0))
     return MR_BAD_CHAR;
 
   /* check for duplicate name */
@@ -1075,18 +1085,19 @@ int hostname_check(char *name)
   return 1;
 }
 
-int hostinfo_check(char *info)
+int hostinfo_check(char *info, int num)
 {
   char *p;
 
   if (!*info)
     return 1;
 
-  /* Sanity check host hostinfo: must start with a letter, contain
-   * only letters, numerals, and hyphen, and not end with a hyphen.
+  /* Sanity check host hostinfo: must start with a letter (or number
+   * if num is true), contain only letters, numerals, and hyphen, and
+   * not end with a hyphen.
    */
 
-  if (!isalpha(*info))
+  if (!isalpha(*info) && (!num || !isdigit(*info)))
     return 0;
   for (p = info; *p; p++)
     {
This page took 0.040844 seconds and 5 git commands to generate.