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
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)
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))
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;
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];
}
/* hostname_check()
- * validate the rfc1035-ness of a hostname
+ * validate the rfc1035/rfc1123-ness of a hostname
*/
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 != '.') ||
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;
+}