]> andersk Git - moira.git/commitdiff
Allow hostname to start with a digit in hostname_check, but disallow it
authordanw <danw>
Mon, 14 Dec 1998 18:53:33 +0000 (18:53 +0000)
committerdanw <danw>
Mon, 14 Dec 1998 18:53:33 +0000 (18:53 +0000)
in access_host/access_ahal. (So you can make hostnames start with a number
only if you're on the query acl.)

server/mr_server.h
server/qaccess.pc
server/qsetup.pc

index ca1c5a2b56d7d5449511e87efe374a644afd8649..1b684b2bfb34293f50bc5ae4d4f58c2301badb70 100644 (file)
@@ -230,6 +230,7 @@ int setup_dsnt(struct query *q, char *argv[], client *cl);
 int setup_ahst(struct query *q, char *argv[], client *cl);
 int setup_ahal(struct query *q, char *argv[], client *cl);
 int hostname_check(char *name);
+int hostinfo_check(char *name);
 
 /* prototypes from qsupport.pc */
 int set_pobox(struct query *q, char *argv[], client *cl);
index 4ec96f2776897256380d7bb1c03540a31f9e88d8..e391f4ea436060f2a2dac6579564167f36615677 100644 (file)
@@ -347,13 +347,17 @@ int access_host(struct query *q, char *argv[], client *cl)
       else
        return MR_PERM;
     }
-  
+
   if (q->type == APPEND)
     {
       /* Non-query owner must set use to zero */
       if (atoi(argv[6]) != 0)
        return MR_PERM;
 
+      /* ... and start the hostname with a letter */
+      if (isdigit(argv[0][0]))
+       return MR_BAD_CHAR;
+
       id = *(int *)argv[8];
       EXEC SQL SELECT s.owner_type, s.owner_id
        INTO :stype, :sid FROM subnet s
@@ -370,13 +374,14 @@ int access_host(struct query *q, char *argv[], client *cl)
       EXEC SQL BEGIN DECLARE SECTION;
       int status, acomment, use, ocomment, snid;
       char contact[MACHINE_CONTACT_SIZE], address[MACHINE_ADDRESS_SIZE];
+      char name[MACHINE_NAME_SIZE];
       EXEC SQL END DECLARE SECTION;
 
       id = *(int *)argv[0];
-      EXEC SQL SELECT m.use, m.contact, m.status, m.address, m.owner_type,
-       m.owner_id, m.acomment, m.ocomment, m.snet_id, s.owner_type, s.owner_id
-       INTO :use, :contact, :status, :address, :mtype, :mid, :acomment,
-       :ocomment, :snid, :stype, :sid
+      EXEC SQL SELECT m.name, m.use, m.contact, m.status, m.address,
+       m.owner_type, m.owner_id, m.acomment, m.ocomment, m.snet_id,
+       s.owner_type, s.owner_id INTO :name, :use, :contact, :status,
+       :address, :mtype, :mid, :acomment, :ocomment, :snid, :stype, :sid
        FROM machine m, subnet s
        WHERE m.mach_id = :id AND s.snet_id = m.snet_id;
       if (dbms_errno)
@@ -386,6 +391,10 @@ int access_host(struct query *q, char *argv[], client *cl)
       if ((use != atoi(argv[7])) || (ocomment != *(int *)argv[14]))
        return MR_PERM;
 
+      /* or rename to start with digit */
+      if (isdigit(argv[1][0]) && strcmp(strtrim(name), argv[1]))
+       return MR_BAD_CHAR;
+
       if (!find_member(stype, sid, cl))
        {
          if (find_member(mtype, mid, cl))
@@ -437,6 +446,9 @@ int access_ahal(struct query *q, char *argv[], client *cl)
 
   id = *(int *)argv[1];
 
+  if (q->type == APPEND && isdigit(argv[0][0]))
+    return MR_BAD_CHAR;
+
   EXEC SQL SELECT count(name) INTO :cnt from hostalias WHERE mach_id = :id;
   if (dbms_errno)
     return mr_errcode;
index 5c7c28a3047ff76f8e8bddb4c3028794dabf21e6..7ba1777c206cf69528c60869fdf9ebb794d0f0a1 100644 (file)
@@ -858,68 +858,19 @@ int setup_ahst(struct query *q, char **argv, client *cl)
   else
     row = 0;
 
-  if (row == 0 || strcasecmp(argv[1], oldname))
-    {
-      if (!hostname_check(argv[row]))
-       return MR_BAD_CHAR;
-    }
-
-  /* sanity check host vendor: must start with a letter, contain only
-   * letters, numerals, and hyphen, and end with an alphanumeric.
-   */
-  if (*argv[row + 1] && (row == 0 || strcasecmp(argv[2], vendor)))
-    {
-      char *p = argv[row + 1];
-
-      if (!isalpha(*p))
-       return MR_BAD_CHAR;
-      for (; *p; p++)
-       {
-         if ((!isalnum(*p) && *p != '-' && *p != '.') ||
-             (*p == '-' && p[1] == '.'))
-           return MR_BAD_CHAR;
-       }
-      if (!isalnum(*(p - 1)))
-       return MR_BAD_CHAR;
-    }
-
-  /* sanity check host type: must start with a letter, contain only
-   * letters, numerals, and hyphen, and end with an alphanumeric.
-   */
-  if (*argv[row + 2] && (row == 0 || strcasecmp(argv[3], model)))
-    {
-      char *p = argv[row + 2];
-
-      if (!isalnum(*p))
-       return MR_BAD_CHAR;
-      for (; *p; p++)
-       {
-         if ((!isalnum(*p) && *p != '-' && *p != '.') ||
-             (*p == '-' && p[1] == '.'))
-           return MR_BAD_CHAR;
-       }
-      if (!isalnum(*(p - 1)))
-       return MR_BAD_CHAR;
-    }
-
-  /* sanity check host os: must start with a letter, contain only
-   * letters, numerals, and hyphen, and end with an hyphen alphanumeric.
-   */
-  if (*argv[row + 3] && (row == 0 || strcasecmp(argv[4], os)))
-    {
-      char *p = argv[row + 3];
-
-      if (!isalpha(*p))
-       return MR_BAD_CHAR;
-      for (; *p; p++)
-       {
-         if ((!isalnum(*p) && *p != '-' && *p != '.') ||
-             (*p == '-' && p[1] == '.'))
-           return MR_BAD_CHAR;
-       }
-      if (!isalnum(*(p - 1)))
-       return MR_BAD_CHAR;
-    }
+  /* Sanity check name, vendor, model, and os. */
+  if ((row == 0 || strcasecmp(argv[1], oldname)) &&
+      !hostname_check(argv[row]))
+    return MR_BAD_CHAR;
+  if ((row == 0 || strcasecmp(argv[2], vendor)) &&
+      !hostinfo_check(argv[row + 1]))
+    return MR_BAD_CHAR;
+  if ((row == 0 || strcasecmp(argv[3], model)) &&
+      !hostinfo_check(argv[row + 2]))
+    return MR_BAD_CHAR;
+  if ((row == 0 || strcasecmp(argv[4], os)) &&
+      !hostinfo_check(argv[row + 3]))
+    return MR_BAD_CHAR;
 
   /* check for duplicate name */
   name = argv[row];
@@ -1095,7 +1046,7 @@ int setup_ahal(struct query *q, char **argv, client *cl)
 }
 
 /* hostname_check()
- * validate the rfc1035-ness of a hostname
+ * validate the rfc1035/rfc1123-ness of a hostname
  */
 
 int hostname_check(char *name)
@@ -1103,17 +1054,12 @@ int hostname_check(char *name)
   char *p;
   int count;
 
-  /* sanity check name: must start with a letter, contain only
-   * letters, numerals, and hyphen, and not end with a hyphen.
-   * also make sure no label (the thing the .s seperate) is longer
-   * than 63 characters.
+  /* Sanity check name: must contain only letters, numerals, and
+   * hyphen, and not start or end with a hyphen. Also make sure no
+   * label (the thing the .s seperate) is longer than 63 characters.
    */
 
-  p = name;
-  if (!isalpha(*p))
-    return 0;
-  count = 0;
-  for (; *p; p++)
+  for (p = name, count = 0; *p; p++)
     {
       count++;
       if ((!isalnum(*p) && *p != '-' && *p != '.') ||
@@ -1128,3 +1074,26 @@ int hostname_check(char *name)
     return 0;
   return 1;
 }
+
+int hostinfo_check(char *info)
+{
+  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.
+   */
+
+  if (!isalpha(*info))
+    return 0;
+  for (p = info; *p; p++)
+    {
+      if ((!isalnum(*p) && *p != '-' && *p != '.') ||
+         (*p == '-' && p[1] == '.'))
+       return 0;
+    }
+  if (!isalnum(*(p - 1)))
+    return 1;
+}
This page took 0.058057 seconds and 5 git commands to generate.