From e4ae019062358b54128ff857b08110e009a291cc Mon Sep 17 00:00:00 2001 From: zacheiss Date: Tue, 19 Dec 2000 07:32:46 +0000 Subject: [PATCH] Changes for billing_contact column in machine table. --- server/qaccess.pc | 40 ++++++---- server/qfollow.pc | 23 +++--- server/qsetup.pc | 25 +++--- server/queries2.c | 189 ++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 228 insertions(+), 49 deletions(-) diff --git a/server/qaccess.pc b/server/qaccess.pc index 50c1d0f2..06c72ba7 100644 --- a/server/qaccess.pc +++ b/server/qaccess.pc @@ -415,7 +415,12 @@ int access_host(struct query *q, char *argv[], client *cl) int mid, sid, id; char mtype[MACHINE_OWNER_TYPE_SIZE], stype[SUBNET_OWNER_TYPE_SIZE]; EXEC SQL END DECLARE SECTION; - int status; + int status, idx; + + if (q->version < 6) + idx = 0; + else + idx = 1; if (q->type == RETRIEVE) { @@ -429,14 +434,14 @@ int access_host(struct query *q, char *argv[], client *cl) if (q->type == APPEND) { /* Non-query owner must set use to zero */ - if (atoi(argv[6]) != 0) + if (atoi(argv[6 + idx]) != 0) return MR_PERM; /* ... and start the hostname with a letter */ if (isdigit(argv[0][0])) return MR_BAD_CHAR; - id = *(int *)argv[8]; + id = *(int *)argv[8 + idx]; EXEC SQL SELECT s.owner_type, s.owner_id INTO :stype, :sid FROM subnet s WHERE s.snet_id = :id; @@ -453,20 +458,22 @@ int access_host(struct query *q, char *argv[], client *cl) int status, acomment, use, ocomment, snid; char contact[MACHINE_CONTACT_SIZE], address[MACHINE_ADDRESS_SIZE]; char name[MACHINE_NAME_SIZE]; + char billing_contact[MACHINE_BILLING_CONTACT_SIZE]; EXEC SQL END DECLARE SECTION; id = *(int *)argv[0]; - 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 + EXEC SQL SELECT m.name, m.use, m.contact, m.billing_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, :billing_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) return mr_errcode; /* non-query-owner cannot change use or ocomment */ - if ((use != atoi(argv[7])) || (ocomment != *(int *)argv[14])) + if ((use != atoi(argv[7 + idx])) || (ocomment != *(int *)argv[14 + idx])) return MR_PERM; /* or rename to start with digit */ @@ -479,19 +486,24 @@ int access_host(struct query *q, char *argv[], client *cl) { /* host owner also cannot change contact, status, address, owner, or acomment */ - if (strcmp(argv[6], strtrim(contact)) || - (status != atoi(argv[8])) || - strcmp(argv[10], strtrim(address)) || - strcmp(argv[11], strtrim(mtype)) || - (mid != *(int *)argv[12]) || (acomment != *(int *)argv[13])) + if (strcmp(argv[6 + idx], strtrim(contact)) || + (status != atoi(argv[8 + idx])) || + strcmp(argv[10 + idx], strtrim(address)) || + strcmp(argv[11 + idx], strtrim(mtype)) || + (mid != *(int *)argv[12 + idx]) || + (acomment != *(int *)argv[13 + idx])) return MR_PERM; + /* Billing contact field didn't appear until version 6 */ + if (q->version >= 6) + if (strcmp(argv[8], strtrim(billing_contact))) + return MR_PERM; } else return MR_PERM; } /* If moving to a new subnet, make sure user is on acl there */ - id = *(int *)argv[9]; + id = *(int *)argv[9 + idx]; if (id != snid) { EXEC SQL SELECT owner_type, owner_id INTO :stype, :sid diff --git a/server/qfollow.pc b/server/qfollow.pc index f1422c6d..feff1489 100644 --- a/server/qfollow.pc +++ b/server/qfollow.pc @@ -548,29 +548,34 @@ int followup_ghst(struct query *q, struct save_queue *sq, struct validate *v, client *cl) { char **argv; - int id, status; + int id, status, idx; + + if (q->version < 6) + idx = 0; + else + idx = 1; while (sq_get_data(sq, &argv)) { mr_trim_args(q->vcnt, argv); - id = atoi(argv[13]); - status = id_to_name(id, STRINGS_TABLE, &argv[13]); + id = atoi(argv[13 + idx]); + status = id_to_name(id, STRINGS_TABLE, &argv[13 + idx]); if (status) return status; - id = atoi(argv[14]); - status = id_to_name(id, STRINGS_TABLE, &argv[14]); + id = atoi(argv[14 + idx]); + status = id_to_name(id, STRINGS_TABLE, &argv[14 + idx]); if (status) return status; - id = atoi(argv[16]); + id = atoi(argv[16 + idx]); if (id < 0) - status = id_to_name(-id, STRINGS_TABLE, &argv[16]); + status = id_to_name(-id, STRINGS_TABLE, &argv[16 + idx]); else - status = id_to_name(id, USERS_TABLE, &argv[16]); + status = id_to_name(id, USERS_TABLE, &argv[16 + idx]); if (status && status != MR_NO_MATCH) return status; - status = fix_ace(argv[11], &argv[12]); + status = fix_ace(argv[11 + idx], &argv[12 + idx]); if (status && status != MR_NO_MATCH) return status; } diff --git a/server/qsetup.pc b/server/qsetup.pc index e9abecc7..11a4da78 100644 --- a/server/qsetup.pc +++ b/server/qsetup.pc @@ -879,7 +879,7 @@ int setup_ahst(struct query *q, char **argv, client *cl) int value, id, ssaddr, smask, shigh, slow, cnt; unsigned int saddr, mask, high, low; EXEC SQL END DECLARE SECTION; - int row; + int row, idx; struct in_addr addr; id = *(int *)argv[0]; @@ -894,6 +894,11 @@ int setup_ahst(struct query *q, char **argv, client *cl) else row = 0; + if (q->version < 6) + idx = 0; + else + idx = 1; + /* Sanity check name, vendor, model, and os. */ if ((row == 0 || strcasecmp(argv[1], oldname)) && !hostname_check(argv[row])) @@ -918,18 +923,18 @@ int setup_ahst(struct query *q, char **argv, client *cl) return MR_EXISTS; /* check address */ - if (!strcmp(argv[9 + row], "unassigned")) + if (!strcmp(argv[9 + row + idx], "unassigned")) value = -1; - else if (!strcmp(argv[9 + row], "unique")) + else if (!strcmp(argv[9 + row + idx], "unique")) { - if (*(int *)argv[8 + row] == 0) + if (*(int *)argv[8 + row + idx] == 0) value = -1; else value = -2; } else { - value = ntohl(inet_addr(argv[9 + row])); + value = ntohl(inet_addr(argv[9 + row + idx])); if (value == -1) return MR_ADDRESS; } @@ -940,7 +945,7 @@ int setup_ahst(struct query *q, char **argv, client *cl) /* * an address or unique was specified. */ - id = *(int *)argv[8 + row]; + id = *(int *)argv[8 + row + idx]; EXEC SQL SELECT saddr, mask, high, low INTO :ssaddr, :smask, :shigh, :slow FROM subnet WHERE snet_id = :id; if (dbms_errno) @@ -964,7 +969,7 @@ int setup_ahst(struct query *q, char **argv, client *cl) * link in an inet_addr() that returns an error for * this case. */ - addr.s_addr = inet_addr(argv[9 + row]); + addr.s_addr = inet_addr(argv[9 + row + idx]); name = inet_ntoa(addr); EXEC SQL SELECT count(mach_id) INTO :cnt FROM machine WHERE address = :name; @@ -1016,13 +1021,13 @@ int setup_ahst(struct query *q, char **argv, client *cl) * we have an address in value. Convert it to a string and store it. */ addr.s_addr = htonl(value); - strcpy(argv[9 + row], inet_ntoa(addr)); + strcpy(argv[9 + row + idx], inet_ntoa(addr)); } else - strcpy(argv[9 + row], "unassigned"); + strcpy(argv[9 + row + idx], "unassigned"); /* status checking */ - value = atoi(argv[7 + row]); + value = atoi(argv[7 + row + idx]); if (row == 0 && !(value == 1 || value == 0)) return MR_TYPE; if (row == 1) diff --git a/server/queries2.c b/server/queries2.c index ca8a1538..811f6e01 100644 --- a/server/queries2.c +++ b/server/queries2.c @@ -767,7 +767,7 @@ static char *gmac_fields[] = { "name", "type", "modtime", "modby", "modwith", }; -static char *ghst_fields[] = { +static char *ghst2_fields[] = { "name", "address", "location", "network", "name", "vendor", "model", "os", "location", "contact", "use", "status", "status_change", "network", "address", "ace_type", @@ -775,7 +775,7 @@ static char *ghst_fields[] = { "inuse", "modtime", "modby", "modwith", }; -static char *ghbh_fields[] = { +static char *ghbh2_fields[] = { "hwaddr", "name", "vendor", "model", "os", "location", "contact", "use", "status", "status_change", "network", "address", "ace_type", @@ -783,6 +783,22 @@ static char *ghbh_fields[] = { "inuse", "modtime", "modby", "modwith", }; +static char *ghst_fields[] = { + "name", "address", "location", "network", + "name", "vendor", "model", "os", "location", "contact", "billing_contact", + "use", "status", "status_change", "network", "address", "ace_type", + "ace_name", "admin_comment", "ops_comment", "created", "creator", + "inuse", "modtime", "modby", "modwith", +}; + +static char *ghbh_fields[] = { + "hwaddr", + "name", "vendor", "model", "os", "location", "contact", "billing_contact", + "use", "status", "status_change", "network", "address", "ace_type", + "ace_name", "admin_comment", "ops_comment", "created", "creator", + "inuse", "modtime", "modby", "modwith", +}; + static struct validate ghst_validate = { 0, 0, @@ -800,13 +816,13 @@ static char *ghha_fields[] = { "hwaddr", }; -static char *ahst_fields[] = { +static char *ahst2_fields[] = { "name", "vendor", "model", "os", "location", "contact", "use", "status", "subnet", "address", "ace_type", "ace_name", "admin_comment", "ops_comment", }; -static struct valobj ahst_valobj[] = { +static struct valobj ahst2_valobj[] = { {V_CHAR, 0, MACHINE_TABLE, "name"}, {V_CHAR, 1, MACHINE_TABLE, "vendor"}, {V_CHAR, 2, MACHINE_TABLE, "model"}, @@ -822,9 +838,44 @@ static struct valobj ahst_valobj[] = { {V_ID, 13, STRINGS_TABLE, "string", "string_id", MR_NO_MATCH}, }; +static struct validate ahst2_validate = { + ahst2_valobj, + 13, + "name", + "name = UPPER('%s')", + 1, + "mach_id", + access_host, + setup_ahst, + set_uppercase_modtime, +}; + +static char *ahst_fields[] = { + "name", "vendor", "model", "os", "location", "contact", "billing_contact", + "use", "status", "subnet", "address", "ace_type", "ace_name", + "admin_comment", "ops_comment", +}; + +static struct valobj ahst_valobj[] = { + {V_CHAR, 0, MACHINE_TABLE, "name"}, + {V_CHAR, 1, MACHINE_TABLE, "vendor"}, + {V_CHAR, 2, MACHINE_TABLE, "model"}, + {V_CHAR, 3, MACHINE_TABLE, "os"}, + {V_CHAR, 4, MACHINE_TABLE, "location"}, + {V_CHAR, 5, MACHINE_TABLE, "contact"}, + {V_CHAR, 6, MACHINE_TABLE, "billing_contact"}, + {V_NUM, 7}, + {V_NUM, 8}, + {V_ID, 9, SUBNET_TABLE, "name", "snet_id", MR_SUBNET}, + {V_TYPE, 11, 0, "ace_type", 0, MR_ACE}, + {V_TYPEDATA, 12, 0, 0, 0, MR_ACE}, + {V_ID, 13, STRINGS_TABLE, "string", "string_id", MR_NO_MATCH}, + {V_ID, 14, STRINGS_TABLE, "string", "string_id", MR_NO_MATCH}, +}; + static struct validate ahst_validate = { ahst_valobj, - 13, + 14, "name", "name = UPPER('%s')", 1, @@ -834,14 +885,14 @@ static struct validate ahst_validate = { set_uppercase_modtime, }; -static char *uhst_fields[] = { +static char *uhst2_fields[] = { "name", "newname", "vendor", "model", "os", "location", "contact", "use", "status", "subnet", "address", "ace_type", "ace_name", "admin_comment", "ops_comment", }; -static struct valobj uhst_valobj[] = { +static struct valobj uhst2_valobj[] = { {V_CHAR, 0, MACHINE_TABLE, "name"}, {V_ID, 0, MACHINE_TABLE, "name", "mach_id", MR_MACHINE}, {V_RENAME, 1, MACHINE_TABLE, "name", "mach_id", MR_NOT_UNIQUE}, @@ -859,9 +910,47 @@ static struct valobj uhst_valobj[] = { {V_ID, 14, STRINGS_TABLE, "string", "string_id", MR_NO_MATCH}, }; +static struct validate uhst2_validate = { + uhst2_valobj, + 15, + 0, + 0, + 0, + "mach_id", + access_host, + setup_ahst, + set_modtime_by_id, +}; + +static char *uhst_fields[] = { + "name", + "newname", "vendor", "model", "os", "location", "contact", "billing_contact", + "use", "status", "subnet", "address", "ace_type", "ace_name", + "admin_comment", "ops_comment", +}; + +static struct valobj uhst_valobj[] = { + {V_CHAR, 0, MACHINE_TABLE, "name"}, + {V_ID, 0, MACHINE_TABLE, "name", "mach_id", MR_MACHINE}, + {V_RENAME, 1, MACHINE_TABLE, "name", "mach_id", MR_NOT_UNIQUE}, + {V_CHAR, 2, MACHINE_TABLE, "vendor"}, + {V_CHAR, 3, MACHINE_TABLE, "model"}, + {V_CHAR, 4, MACHINE_TABLE, "os"}, + {V_CHAR, 5, MACHINE_TABLE, "location"}, + {V_CHAR, 6, MACHINE_TABLE, "contact"}, + {V_CHAR, 7, MACHINE_TABLE, "billing_contact"}, + {V_NUM, 8}, + {V_NUM, 9}, + {V_ID, 10, SUBNET_TABLE, "name", "snet_id", MR_SUBNET}, + {V_TYPE, 12, 0, "ace_type", 0, MR_ACE}, + {V_TYPEDATA, 13, 0, 0, 0, MR_ACE}, + {V_ID, 14, STRINGS_TABLE, "string", "string_id", MR_NO_MATCH}, + {V_ID, 15, STRINGS_TABLE, "string", "string_id", MR_NO_MATCH}, +}; + static struct validate uhst_validate = { uhst_valobj, - 15, + 16, 0, 0, 0, @@ -3958,7 +4047,7 @@ struct query Queries[] = { }, { - /* Q_GHST - GET_HOST */ + /* Q_GHST - GET_HOST, v2 */ "get_host", "ghst", 2, @@ -3966,7 +4055,7 @@ struct query Queries[] = { "m", MACHINE_TABLE, "m.name, m.vendor, m.model, m.os, m.location, m.contact, m.use, m.status, TO_CHAR(m.statuschange, 'DD-mon-YYYY HH24:MI:SS'), s.name, m.address, m.owner_type, m.owner_id, m.acomment, m.ocomment, TO_CHAR(m.created, 'DD-mon-YYYY HH24:MI:SS'), m.creator, TO_CHAR(m.inuse, 'DD-mon-YYYY HH24:MI:SS'), TO_CHAR(m.modtime, 'DD-mon-YYYY HH24:MI:SS'), m.modby, m.modwith FROM machine m, subnet s", - ghst_fields, + ghst2_fields, 21, "m.name LIKE UPPER('%s') AND m.address LIKE '%s' AND m.location LIKE UPPER('%s') AND s.name LIKE UPPER('%s') AND m.mach_id != 0 AND s.snet_id = m.snet_id", 4, @@ -3975,7 +4064,24 @@ struct query Queries[] = { }, { - /* Q_GHBH - GET_HOST_BY_HWADDR */ + /* Q_GHST - GET_HOST, v6 */ + "get_host", + "ghst", + 6, + RETRIEVE, + "m", + MACHINE_TABLE, + "m.name, m.vendor, m.model, m.os, m.location, m.contact, m.billing_contact, m.use, m.status, TO_CHAR(m.statuschange, 'DD-mon-YYYY HH24:MI:SS'), s.name, m.address, m.owner_type, m.owner_id, m.acomment, m.ocomment, TO_CHAR(m.created, 'DD-mon-YYYY HH24:MI:SS'), m.creator, TO_CHAR(m.inuse, 'DD-mon-YYYY HH24:MI:SS'), TO_CHAR(m.modtime, 'DD-mon-YYYY HH24:MI:SS'), m.modby, m.modwith FROM machine m, subnet s", + ghst_fields, + 22, + "m.name LIKE UPPER('%s') AND m.address LIKE '%s' AND m.location LIKE UPPER('%s') AND s.name LIKE UPPER('%s') AND m.mach_id != 0 AND s.snet_id = m.snet_id", + 4, + "m.name", + &ghst_validate, + }, + + { + /* Q_GHBH - GET_HOST_BY_HWADDR, v2 */ "get_host_by_hwaddr", "ghbh", 2, @@ -3983,7 +4089,7 @@ struct query Queries[] = { "m", MACHINE_TABLE, "m.name, m.vendor, m.model, m.os, m.location, m.contact, m.use, m.status, TO_CHAR(m.statuschange, 'DD-mon-YYYY HH24:MI:SS'), s.name, m.address, m.owner_type, m.owner_id, m.acomment, m.ocomment, TO_CHAR(m.created, 'DD-mon-YYYY HH24:MI:SS'), m.creator, TO_CHAR(m.inuse, 'DD-mon-YYYY HH24:MI:SS'), TO_CHAR(m.modtime, 'DD-mon-YYYY HH24:MI:SS'), m.modby, m.modwith FROM machine m, subnet s", - ghbh_fields, + ghbh2_fields, 21, "m.hwaddr LIKE LOWER('%s') AND m.mach_id != 0 AND s.snet_id = m.snet_id", 1, @@ -3991,6 +4097,23 @@ struct query Queries[] = { &ghst_validate, }, + { + /* Q_GHBH - GET_HOST_BY_HWADDR, v6 */ + "get_host_by_hwaddr", + "ghbh", + 6, + RETRIEVE, + "m", + MACHINE_TABLE, + "m.name, m.vendor, m.model, m.os, m.location, m.contact, m.billing_contact, m.use, m.status, TO_CHAR(m.statuschange, 'DD-mon-YYYY HH24:MI:SS'), s.name, m.address, m.owner_type, m.owner_id, m.acomment, m.ocomment, TO_CHAR(m.created, 'DD-mon-YYYY HH24:MI:SS'), m.creator, TO_CHAR(m.inuse, 'DD-mon-YYYY HH24:MI:SS'), TO_CHAR(m.modtime, 'DD-mon-YYYY HH24:MI:SS'), m.modby, m.modwith FROM machine m, subnet s", + ghbh_fields, + 22, + "m.hwaddr LIKE LOWER('%s') AND m.mach_id != 0 AND s.snet_id = m.snet_id", + 1, + "m.name", + &ghst_validate, + }, + { /* Q_GHHA - GET_HOST_HWADDR */ "get_host_hwaddr", @@ -4009,7 +4132,7 @@ struct query Queries[] = { }, { - /* Q_AHST - ADD_HOST */ /* uses prefetch_value() for mach_id */ + /* Q_AHST - ADD_HOST, v2 */ /* uses prefetch_value() for mach_id */ "add_host", "ahst", 2, @@ -4017,16 +4140,33 @@ struct query Queries[] = { "m", MACHINE_TABLE, "INTO machine (name, vendor, model, os, location, contact, use, status, statuschange, snet_id, address, owner_type, owner_id, acomment, ocomment, created, inuse, mach_id, creator) VALUES (UPPER('%s'), NVL(UPPER('%s'), CHR(0)), NVL(UPPER('%s'), CHR(0)), NVL(UPPER('%s'), CHR(0)), NVL(UPPER('%s'), CHR(0)), NVL('%s', CHR(0)), %s, %s, SYSDATE, %d, '%s', '%s', %d, %d, %d, SYSDATE, SYSDATE, %s, %s)", - ahst_fields, + ahst2_fields, 14, 0, 0, NULL, + &ahst2_validate, + }, + + { + /* Q_AHST - ADD_HOST, v6 */ /* uses prefetch_value() for mach_id */ + "add_host", + "ahst", + 6, + APPEND, + "m", + MACHINE_TABLE, + "INTO machine (name, vendor, model, os, location, contact, billing_contact, use, status, statuschange, snet_id, address, owner_type, owner_id, acomment, ocomment, created, inuse, mach_id, creator) VALUES (UPPER('%s'), NVL(UPPER('%s'), CHR(0)), NVL(UPPER('%s'), CHR(0)), NVL(UPPER('%s'), CHR(0)), NVL(UPPER('%s'), CHR(0)), NVL('%s', CHR(0)), NVL('%s', CHR(0)), %s, %s, SYSDATE, %d, '%s', '%s', %d, %d, %d, SYSDATE, SYSDATE, %s, %s)", + ahst_fields, + 15, + 0, + 0, + NULL, &ahst_validate, }, { - /* Q_UHST - UPDATE_HOST */ + /* Q_UHST - UPDATE_HOST, v2 */ "update_host", "uhst", 2, @@ -4034,11 +4174,28 @@ struct query Queries[] = { "m", MACHINE_TABLE, "machine SET name = NVL(UPPER('%s'), CHR(0)), vendor = NVL(UPPER('%s'), CHR(0)), model = NVL(UPPER('%s'), CHR(0)), os = NVL(UPPER('%s'), CHR(0)), location = NVL(UPPER('%s'), CHR(0)), contact = NVL('%s', CHR(0)), use = %s, status = %s, snet_id = %d, address = '%s', owner_type = '%s', owner_id = %d, acomment = %d, ocomment = %d", - uhst_fields, + uhst2_fields, 14, "mach_id = %d", 1, NULL, + &uhst2_validate, + }, + + { + /* Q_UHST - UPDATE_HOST, v6 */ + "update_host", + "uhst", + 6, + UPDATE, + "m", + MACHINE_TABLE, + "machine SET name = NVL(UPPER('%s'), CHR(0)), vendor = NVL(UPPER('%s'), CHR(0)), model = NVL(UPPER('%s'), CHR(0)), os = NVL(UPPER('%s'), CHR(0)), location = NVL(UPPER('%s'), CHR(0)), contact = NVL('%s', CHR(0)), billing_contact = NVL('%s', CHR(0)), use = %s, status = %s, snet_id = %d, address = '%s', owner_type = '%s', owner_id = %d, acomment = %d, ocomment = %d", + uhst_fields, + 15, + "mach_id = %d", + 1, + NULL, &uhst_validate, }, -- 2.45.1