EXEC SQL BEGIN DECLARE SECTION;
int ngid;
EXEC SQL END DECLARE SECTION;
- char *malloc();
unsigned char *p;
int idx;
id = *(int *)argv[0];
dir = argv[1];
- EXEC SQL REPEATED SELECT fs.tid INTO :cnt FROM filesys fs, nfsphys np
+ EXEC SQL REPEATED SELECT count(fs.tid) INTO :cnt FROM filesys fs, nfsphys np
WHERE fs.mach_id = :id AND fs.phys_id = np.nfsphys_id
AND np.mach_id = :id AND np.dir = :dir;
if (cnt > 0)
if (*(p-1) == '-') 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 || strcmp(argv[2], cl->args->mr_argv[2]))) {
+ 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 || strcmp(argv[3], cl->args->mr_argv[3]))) {
+ 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 vendor: must start with a letter, contain only
+ * letters, numerals, and hyphen, and end with an hyphen alphanumeric.
+ */
+ if (*argv[row+3] && (row == 0 || strcmp(argv[4], cl->args->mr_argv[4]))) {
+ 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);
+ }
+
/* check for duplicate name */
name = argv[row];
EXEC SQL SELECT count(mach_id) INTO :cnt FROM hostalias
value = -1;
else
value = -2;
- } else
- value = ntohl(inet_addr(argv[9+row]));
+ } else {
+ value = ntohl(inet_addr(argv[9+row]));
+ if (value == -1) return(MR_ADDRESS);
+ }
if (value == 0) return(MR_ADDRESS);
if (value != -1) {
+ /*
+ * an address or unique was specified.
+ */
id = *(int *)argv[8+row];
EXEC SQL SELECT saddr, mask, high, low INTO :addr, :mask, :high, :low
FROM subnet WHERE snet_id = :id;
if (ingres_errno) return(mr_errcode);
if (value != -2) {
+ /*
+ * someone specified an IP address for the host record
+ */
if ((value & mask) != addr) return(MR_ADDRESS);
- name = argv[9+row];
+ /*
+ * run the address argument through inet_addr(). This
+ * has the effect that any out of bounds host addrs will
+ * be converted to a valid host addr. We do this now
+ * so that the uniqueness check works. We should also
+ * link in an inet_addr() that returns an error for
+ * this case.
+ */
+ name = (char *) inet_ntoa(inet_addr(argv[9+row]));
EXEC SQL SELECT count(mach_id) INTO :cnt FROM machine
WHERE address = :name;
if (ingres_errno) return(mr_errcode);
if (cnt > 0) {
+ /*
+ * make IP address is unique. If this a modify request
+ * (row == 1), then we expect one record to exist.
+ */
if (row == 0 || row == 1 && cnt > 1) return(MR_ADDRESS);
if (row == 1 && cnt == 1) {
EXEC SQL SELECT mach_id INTO :id FROM machine
}
}
} else {
+ /*
+ * a "unique" address was specified. Walk through the
+ * range specified in the network record, return
+ * error if no room left.
+ */
for (id = low; id <= high; id++) {
if (((id & 0xff) == 0) ||
((id & 0xff) == 255))
else
value = htonl(value);
}
+ /*
+ * we have an address in value. Convert it to a string and store it.
+ */
value = htonl(value);
- argv[9+row] = strsave(inet_ntoa(value));
+ strcpy(argv[9+row], inet_ntoa(value));
} else {
- argv[9+row] = strsave("unassigned");
+ strcpy(argv[9+row], "unassigned");
}
/* status checking */
value = atoi(argv[7+row]);
- if (row == 0 && !(value == 1 || value == 3))
+ if (row == 0 && !(value == 1 || value == 0))
return(MR_TYPE);
if (row == 1) {
id = *(int *)argv[0];
EXEC SQL SELECT status INTO :cnt FROM machine WHERE mach_id = :id;
if (ingres_errno) return(mr_errcode);
if (value != cnt) {
- EXEC SQL UPDATE machine SET statuschange = date('now');
+ EXEC SQL UPDATE machine SET statuschange = date('now')
+ WHERE mach_id = :id;
}
}
acomment, use, snet_id, ocomment INTO :s6, :i8, :s10, :s11, :i12,
:i13, :i7, :i9, :i14 FROM machine WHERE mach_id = :id;
if (ingres_errno) return(mr_errcode);
- /* subnet owner cannot change use or ocomment */
- if ((i7 != atoi(argv[7])) || (i14 != *(int *)argv[14]))
+ /* subnet owner cannot change use, comment, or network */
+ if ((i7 != atoi(argv[7])) || (i14 != *(int *)argv[14]) ||
+ (i9 != *(int *)argv[9]))
return(MR_PERM);
/* host owner cannot change contact, status, address, owner_type,
* owner_id, acomment, or subnet */
if (host_access_level == 2 &&
(strcmp(argv[6], strtrim(s6)) || (i8 != atoi(argv[8])) ||
- strcmp(argv[10], strtrim(s10)) || strcmp(argv[11], strtrim(s11)) ||
+ strcmp(argv[10], strtrim(s10)) ||strcmp(argv[11], strtrim(s11)) ||
(i12 != *(int *)argv[12]) || (i13 != *(int *)argv[13]) ||
- (i9 = *(int *)argv[9])))
+ (i9 != *(int *)argv[9])))
return(MR_PERM);
}
+ /*
+ * If this is an update_host query, we're done.
+ */
+ if (row == 1)
+ return(MR_SUCCESS);
+
+ /*
+ * For an add_host query, allocate and fill in a new machine id,
+ * and then insert the creator id.
+ */
if ((mr_errcode = prefetch_value(q,argv,cl)) != MR_SUCCESS)
return(mr_errcode);
- row = q->argc + q->vcnt + 1;
- sprintf(buf, "%d",cl->client_id);
- argv[row] = strsave(buf);
- argv[row+1] = NULL;
+ sprintf(argv[q->argc + q->vcnt + 1], "%d",cl->client_id);
return(MR_SUCCESS);
}