- Make container name in container-related queries case insensitive.
- Implement get_container_list and set_container_list queries for
associating a container with a list.
- Add a publicflg to containers, analagous to what's already there for
and update acl'ing semantics to use it.
- Pass associated container list to incremental programs for container
table incrementals.
Not guaranteed to be bug free, but seems to all work, and it's time to
checkpoint this work.
break;
case CONTAINERS_TABLE:
sprintf(stmt_buf, "SELECT c.name, c.description, c.location, c.contact, "
- "c.acl_type, c.acl_id, c.cnt_id FROM containers c WHERE %s",
- qual);
+ "c.acl_type, c.acl_id, c.cnt_id, c.list_id FROM containers c "
+ "WHERE %s", qual);
dosql(before);
- beforec = 7;
+ beforec = 8;
name = xmalloc(0);
id = atoi(before[5]);
if (!strncmp(before[4], "USER", 4))
id_to_name(id, STRINGS_TABLE, &name);
strcpy(before[5], name);
}
+ id = atoi(before[7]);
+ id_to_name(id, LIST_TABLE, &name);
+ strcpy(before[7], name);
break;
case MCMAP_TABLE:
strcpy(before[0], argv[0]);
sprintf(before[2], "%d", id);
name_to_id(before[1], CONTAINERS_TABLE, &id);
sprintf(before[3], "%d", id);
- beforec = 4;
+ name = xmalloc(0);
+ EXEC SQL SELECT list_id INTO :before[4] FROM containers
+ WHERE cnt_id = :id;
+ id = atoi(before[4]);
+ id_to_name(id, LIST_TABLE, &name);
+ strcpy(before[4], name);
+ beforec = 5;
break;
case SVC_TABLE:
strcpy(before[0], argv[0]);
{
char *name, *name2;
EXEC SQL BEGIN DECLARE SECTION;
- int id;
+ int id;
EXEC SQL END DECLARE SECTION;
struct iupdate *iu;
break;
case CONTAINERS_TABLE:
sprintf(stmt_buf, "SELECT c.name, c.description, c.location, c.contact, "
- "c.acl_type, c.acl_id, c.cnt_id FROM containers c WHERE %s",
- qual);
+ "c.acl_type, c.acl_id, c.cnt_id, c.list_id FROM containers c "
+ "WHERE %s", qual);
dosql(after);
- afterc = 7;
+ afterc = 8;
name = xmalloc(0);
id = atoi(after[5]);
if (!strncmp(after[4], "USER", 4))
id_to_name(id, STRINGS_TABLE, &name);
strcpy(after[5], name);
}
+ id = atoi(after[7]);
+ id_to_name(id, LIST_TABLE, &name);
+ strcpy(after[7], name);
break;
case MCMAP_TABLE:
strcpy(after[0], argv[0]);
sprintf(after[2], "%d", id);
name_to_id(after[1], CONTAINERS_TABLE, &id);
sprintf(after[3], "%d", id);
- afterc = 4;
+ name = xmalloc(0);
+ EXEC SQL SELECT list_id INTO :after[4] FROM containers
+ WHERE cnt_id = :id;
+ id = atoi(after[4]);
+ id_to_name(id, LIST_TABLE, &name);
+ strcpy(after[4], name);
+ afterc = 5;
break;
case SVC_TABLE:
strcpy(after[0], argv[0]);
int setup_aprn(struct query *q, char *argv[], client *cl);
int setup_dpsv(struct query *q, char *argv[], client *cl);
int setup_dcon(struct query *q, char *argv[], client *cl);
+int setup_acon(struct query *q, char *argv[], client *cl);
+int setup_scli(struct query *q, char *argv[], client *cl);
/* prototypes from qsupport.pc */
int set_pobox(struct query *q, char *argv[], client *cl);
int register_user(struct query *q, char *argv[], client *cl);
int do_user_reservation(struct query *q, char *argv[], client *cl);
int update_container(struct query *q, char *argv[], client *cl);
+int set_container_list(struct query *q, char *argv[], client *cl);
int get_ace_use(struct query *q, char **argv, client *cl,
int (*action)(int, char *[], void *), void *actarg);
int access_container(struct query *q, char *argv[], client *cl)
{
EXEC SQL BEGIN DECLARE SECTION;
- int cnt_id, acl_id, memacl_id;
+ int cnt_id, acl_id, memacl_id, mach_id, machine_owner_id, flag;
char acl_type[CONTAINERS_ACL_TYPE_SIZE], memacl_type[CONTAINERS_ACL_TYPE_SIZE];
char name[CONTAINERS_NAME_SIZE], *newname;
+ char machine_owner_type[MACHINE_OWNER_TYPE_SIZE];
EXEC SQL END DECLARE SECTION;
int status;
/* if amcn or dmcn, container id is the second argument */
if (strcmp(q->shortname, "amcn") == 0 || strcmp(q->shortname, "dmcn") == 0)
+ {
+ mach_id = *(int *)argv[0];
cnt_id = *(int *)argv[1];
+ }
- EXEC SQL SELECT acl_id, acl_type, memacl_id, memacl_type, name
- INTO :acl_id, :acl_type, :memacl_id, :memacl_type, :name
+ EXEC SQL SELECT acl_id, acl_type, memacl_id, memacl_type, name, publicflg
+ INTO :acl_id, :acl_type, :memacl_id, :memacl_type, :name, :flag
FROM containers
WHERE cnt_id = :cnt_id;
if (find_member(memacl_type, memacl_id, cl))
return MR_SUCCESS;
+ /* if the container is public or the query is delete, grant access if client
+ * is on owner list */
+ if (flag || q->type == DELETE)
+ {
+ EXEC SQL SELECT owner_type, owner_id INTO :machine_owner_type,
+ :machine_owner_id
+ FROM machine
+ WHERE mach_id = :mach_id;
+
+ if (sqlca.sqlerrd[2] == 1 && strcmp("NONE", machine_owner_type) &&
+ find_member(machine_owner_type, machine_owner_id, cl))
+ return MR_SUCCESS;
+ }
/* Otherwise fail. */
return MR_PERM;
}
client *cl)
{
char **argv;
- int status;
+ int status, idx = 0;
+
+ if (q->version >= 9)
+ idx = 1;
while (sq_get_data(sq, &argv))
{
mr_trim_args(q->vcnt, argv);
- status = fix_ace(argv[4], &argv[5]);
+ status = fix_ace(argv[4 + idx], &argv[5 + idx]);
if (status && status != MR_NO_MATCH)
return status;
- status = fix_ace(argv[6], &argv[7]);
+ status = fix_ace(argv[6 + idx], &argv[7 + idx]);
if (status && status != MR_NO_MATCH)
return status;
}
EXEC SQL SELECT string_id INTO :j FROM strings WHERE string = :iname;
break;
case CONTAINERS_TABLE:
- EXEC SQL SELECT cnt_id INTO :j FROM containers WHERE name = :iname;
+ EXEC SQL SELECT cnt_id INTO :j FROM containers WHERE LOWER(name) =
+ LOWER(:iname);
break;
default:
return MR_INTERNAL;
strcpy(containername, strtrim(containername));
EXEC SQL SELECT COUNT(cnt_id) INTO :cnt FROM containers
- WHERE name LIKE :containername || '/' || '%';
+ WHERE LOWER(name) LIKE LOWER(:containername || '/' || '%');
if (cnt > 0)
return MR_IN_USE;
return MR_SUCCESS;
}
+int setup_scli(struct query *q, char *argv[], client *cl)
+{
+ EXEC SQL BEGIN DECLARE SECTION;
+ int cnt_id, list_id;
+ EXEC SQL END DECLARE SECTION;
+
+ cnt_id = *(int *)argv[0];
+ /* Check if someone has already set the list for this container */
+ EXEC SQL SELECT list_id INTO :list_id FROM containers
+ WHERE cnt_id = :cnt_id;
+ if (list_id != 0)
+ return MR_EXISTS;
+
+ if (dbms_errno)
+ return mr_errcode;
+
+ return MR_SUCCESS;
+}
+
/* hostname_check()
* validate the rfc1035/rfc1123-ness of a hostname
*/
if (!isalnum(*(p - 1)))
return 1;
}
+
+int setup_acon(struct query *q, char *argv[], client *cl)
+{
+ EXEC SQL BEGIN DECLARE SECTION;
+ char containername[CONTAINERS_NAME_SIZE];
+ EXEC SQL END DECLARE SECTION;
+
+ char* ptr;
+
+ memset(containername, 0, sizeof(containername));
+ strcpy(containername, argv[0]);
+ ptr = strrchr(containername, '/');
+ /* sub container, check for parents */
+ if (ptr)
+ {
+ *ptr = '\0';
+ EXEC SQL SELECT * FROM containers
+ WHERE lower(name) = lower(:containername);
+ if (sqlca.sqlerrd[2] != 1)
+ return MR_CONTAINER_NO_PARENT;
+ }
+
+ if ((mr_errcode = prefetch_value(q, argv, cl)) != MR_SUCCESS)
+ return mr_errcode;
+
+ return MR_SUCCESS;
+}
int update_container(struct query *q, char *argv[], client *cl)
{
EXEC SQL BEGIN DECLARE SECTION;
- int cnt_id, acl_id, memacl_id, who;
+ int cnt_id, acl_id, memacl_id, who, flag;
char name[CONTAINERS_NAME_SIZE], newchildname[CONTAINERS_NAME_SIZE];
char* newname, *entity, *description, *location, *contact, *acl_type, *memacl_type;
EXEC SQL END DECLARE SECTION;
int cnt, childid;
char childname[CONTAINERS_NAME_SIZE];
char *qual;
+ int index = 0;
- cnt_id = *(int *)argv[0];
- newname = argv[1];
- description = argv[2];
- location = argv[3];
- contact = argv[4];
- acl_type = argv[5];
- acl_id = *(int *)argv[6];
- memacl_type = argv[7];
- memacl_id = *(int *)argv[8];
+ cnt_id = *(int *)argv[index++];
+ newname = argv[index++];
+
+ if (q->version >= 9)
+ flag = atoi(argv[index++]);
+
+ description = argv[index++];
+ location = argv[index++];
+ contact = argv[index++];
+ acl_type = argv[index++];
+ acl_id = *(int *)argv[index++];
+ memacl_type = argv[index++];
+ memacl_id = *(int *)argv[index++];
entity = cl->entity;
who = cl->client_id;
}
/* update the remaining fields */
- EXEC SQL UPDATE containers
- SET description = NVL(:description, CHR(0)), location = NVL(:location, CHR(0)),
- contact = NVL(:contact, CHR(0)), acl_type = :acl_type, acl_id = :acl_id,
- memacl_type = :memacl_type, memacl_id = :memacl_id,
- modtime = SYSDATE, modby = :who, modwith = :entity
- WHERE cnt_id = :cnt_id;
+ if (q->version >= 9)
+ {
+ EXEC SQL UPDATE containers
+ SET publicflg= :flag, description = NVL(:description, CHR(0)), location = NVL(:location, CHR(0)),
+ contact = NVL(:contact, CHR(0)), acl_type = :acl_type, acl_id = :acl_id,
+ memacl_type = :memacl_type, memacl_id = :memacl_id,
+ modtime = SYSDATE, modby = :who, modwith = :entity
+ WHERE cnt_id = :cnt_id;
+ }
+ else
+ {
+ EXEC SQL UPDATE containers
+ SET publicflg= :flag, description = NVL(:description, CHR(0)), location = NVL(:location, CHR(0)),
+ contact = NVL(:contact, CHR(0)), acl_type = :acl_type, acl_id = :acl_id,
+ memacl_type = :memacl_type, memacl_id = :memacl_id,
+ modtime = SYSDATE, modby = :who, modwith = :entity
+ WHERE cnt_id = :cnt_id;
+ }
if (dbms_errno)
return mr_errcode;
if (!isrecursive)
sprintf(tmp, "AND b.cnt_id = %d ", cnt_id);
else
- sprintf(tmp, "AND (b.cnt_id = %d OR b.name LIKE '%s/%%') ", cnt_id, containername);
+ sprintf(tmp, "AND (b.cnt_id = %d OR b.name LIKE LOWER('%s/%%')) ",
+ cnt_id, containername);
strcat(querystring, tmp);
strcat(querystring, "ORDER BY b.name, a.name");
strcpy(querystring, "SELECT name FROM containers ");
if (!isrecursive)
- sprintf(tmp, "WHERE name LIKE '%s/%%' and name NOT LIKE '%s/%%/%%' ", containername,
- containername);
+ sprintf(tmp, "WHERE LOWER(name) LIKE '%s/%%' and name NOT LIKE LOWER('%s/%%/%%') ",
+ containername, containername);
else
- sprintf(tmp, "WHERE name LIKE '%s/%%' ", containername);
+ sprintf(tmp, "WHERE LOWER(name) LIKE LOWER('%s/%%') ", containername);
strcat(querystring, tmp);
strcat(querystring, "ORDER BY name");
return MR_NO_MATCH;
return MR_SUCCESS;
}
+
+int set_container_list(struct query *q, char *argv[], client *cl)
+{
+ EXEC SQL BEGIN DECLARE SECTION;
+ int cnt_id, list_id;
+ EXEC SQL END DECLARE SECTION;
+
+ cnt_id = *(int *)argv[0];
+ list_id = *(int *)argv[1];
+
+ EXEC SQL UPDATE containers SET list_id = :list_id WHERE cnt_id = :cnt_id;
+ if (dbms_errno)
+ return mr_errcode;
+
+ return MR_SUCCESS;
+}
};
static struct valobj VOcon0[] = {
- {V_ID, 0, CONTAINERS_TABLE, "name", "cnt_id", MR_CONTAINER},
+ {V_ID, 0, CONTAINERS_TABLE, "name", "cnt_id", MR_CONTAINER},
};
static struct valobj VOnum0[] = {
"sid",
};
-static char *gcon_fields[] = {
+static char *gcon7_fields[] = {
"name",
"name", "description", "location", "contact",
"ace_type", "ace_name", "memace_type", "memace_name", "modtime", "modby", "modwith",
followup_gcon,
};
-static char *acon_fields[] = {
+static char *gcon_fields[] = {
+ "name",
+ "name", "publicflg", "description", "location", "contact",
+ "ace_type", "ace_name", "memace_type", "memace_name", "modtime", "modby", "modwith",
+};
+
+static char *acon7_fields[] = {
"name", "description", "location", "contact",
"ace_type", "ace_name", "memace_type", "memace_name",
};
-static struct valobj acon_valobj[] = {
+static struct valobj acon7_valobj[] = {
{V_CHAR, 0, CONTAINERS_TABLE, "name"},
{V_LEN, 1, CONTAINERS_TABLE, "description"},
{V_CHAR, 2, CONTAINERS_TABLE, "location"},
{V_TYPEDATA, 7, 0, 0, 0, MR_ACE},
};
+static struct validate acon7_validate =
+{
+ acon7_valobj,
+ 8,
+ "name",
+ "name = '%s'",
+ 1,
+ "cnt_id",
+ 0,
+ setup_acon,
+ set_modtime,
+};
+
+static char *acon_fields[] = {
+ "name", "publicflg", "description", "location", "contact",
+ "ace_type", "ace_name", "memace_type", "memace_name",
+};
+
+static struct valobj acon_valobj[] = {
+ {V_CHAR, 0, CONTAINERS_TABLE, "name"},
+ {V_NUM, 1},
+ {V_LEN, 2, CONTAINERS_TABLE, "description"},
+ {V_CHAR, 3, CONTAINERS_TABLE, "location"},
+ {V_CHAR, 4, CONTAINERS_TABLE, "contact"},
+ {V_TYPE, 5, 0, "ace_type", 0, MR_ACE},
+ {V_TYPEDATA, 6, 0, 0, 0, MR_ACE},
+ {V_TYPE, 7, 0, "ace_type", 0, MR_ACE},
+ {V_TYPEDATA, 8, 0, 0, 0, MR_ACE},
+};
+
static struct validate acon_validate =
{
acon_valobj,
- 8,
+ 9,
"name",
"name = '%s'",
1,
"cnt_id",
0,
- prefetch_value,
+ setup_acon,
set_modtime,
};
-static char *ucon_fields[] = {
+static char *ucon7_fields[] = {
"name",
"newname", "description", "location", "contact",
"ace_type", "ace_name", "memace_type", "memace_name",
};
-static struct valobj ucon_valobj[] = {
+static struct valobj ucon7_valobj[] = {
{V_ID, 0, CONTAINERS_TABLE, "name", "cnt_id", MR_CONTAINER},
{V_RENAME, 1, CONTAINERS_TABLE, "name", "cnt_id", MR_NOT_UNIQUE},
{V_LEN, 2, CONTAINERS_TABLE, "description"},
{V_TYPEDATA, 8, 0, 0, 0, MR_ACE},
};
+static struct validate ucon7_validate =
+{
+ ucon7_valobj,
+ 9,
+ 0,
+ 0,
+ 0,
+ 0,
+ access_container,
+ 0,
+ update_container,
+};
+
+static char *ucon_fields[] = {
+ "name",
+ "newname", "publicflg", "description", "location", "contact",
+ "ace_type", "ace_name", "memace_type", "memace_name",
+};
+
+static struct valobj ucon_valobj[] = {
+ {V_ID, 0, CONTAINERS_TABLE, "name", "cnt_id", MR_CONTAINER},
+ {V_RENAME, 1, CONTAINERS_TABLE, "name", "cnt_id", MR_NOT_UNIQUE},
+ {V_NUM, 2},
+ {V_LEN, 3, CONTAINERS_TABLE, "description"},
+ {V_CHAR, 4, CONTAINERS_TABLE, "location"},
+ {V_CHAR, 5, CONTAINERS_TABLE, "contact"},
+ {V_TYPE, 6, 0, "ace_type", 0, MR_ACE},
+ {V_TYPEDATA, 7, 0, 0, 0, MR_ACE},
+ {V_TYPE, 8, 0, "ace_type", 0, MR_ACE},
+ {V_TYPEDATA, 9, 0, 0, 0, MR_ACE},
+};
+
static struct validate ucon_validate =
{
ucon_valobj,
- 9,
+ 10,
0,
0,
0,
"name",
};
+static char *scli_fields[] = {
+ "containername",
+ "listname",
+};
+
+static struct valobj scli_valobj[] = {
+ {V_ID, 0, CONTAINERS_TABLE, "name", "cnt_id", MR_CONTAINER},
+ {V_ID, 1, LIST_TABLE, "name", "list_id", MR_LIST},
+};
+
+static struct validate scli_validate = {
+ scli_valobj,
+ 2,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ setup_scli,
+ set_container_list,
+};
+
+static char *gcli_fields[] = {
+ "containername",
+ "containername", "listname",
+};
/* Generalized Query Definitions */
"c",
CONTAINERS_TABLE,
"name, description, location, contact, acl_type, acl_id, memacl_type, memacl_id, TO_CHAR(modtime, 'DD-mon-YYYY HH24:MI:SS'), modby, modwith FROM containers",
- gcon_fields,
+ gcon7_fields,
11,
- "name LIKE '%s' AND cnt_id != 0",
+ "LOWER(name) LIKE LOWER('%s') AND cnt_id != 0",
+ 1,
+ NULL,
+ &gcon_validate,
+ },
+
+ {
+ /* Q_GCON - GET_CONTAINER, v9 */
+ "get_container",
+ "gcon",
+ 9,
+ RETRIEVE,
+ "c",
+ CONTAINERS_TABLE,
+ "name, publicflg, description, location, contact, acl_type, acl_id, memacl_type, memacl_id, TO_CHAR(modtime, 'DD-mon-YYYY HH24:MI:SS'), modby, modwith FROM containers",
+ gcon_fields,
+ 12,
+ "LOWER(name) LIKE LOWER('%s') AND cnt_id != 0",
1,
NULL,
&gcon_validate,
"c",
CONTAINERS_TABLE,
"INTO containers (name, description, location, contact, acl_type, acl_id, memacl_type, memacl_id, cnt_id) VALUES ('%s', NVL('%s', CHR(0)), NVL('%s', CHR(0)), NVL('%s', CHR(0)), '%s', %d, '%s', %d, %s)",
- acon_fields,
+ acon7_fields,
8,
0,
0,
NULL,
+ &acon7_validate,
+ },
+
+ {
+ /* Q_ACON - ADD_CONTAINER, v9 */ /* uses prefetch_value() for cnt_id */
+ "add_container",
+ "acon",
+ 9,
+ APPEND,
+ "c",
+ CONTAINERS_TABLE,
+ "INTO containers (name, publicflg, description, location, contact, acl_type, acl_id, memacl_type, memacl_id, cnt_id) VALUES ('%s', %s, NVL('%s', CHR(0)), NVL('%s', CHR(0)), NVL('%s', CHR(0)), '%s', %d, '%s', %d, %s)",
+ acon_fields,
+ 9,
+ 0,
+ 0,
+ NULL,
&acon_validate,
},
0,
CONTAINERS_TABLE,
0,
- ucon_fields,
+ ucon7_fields,
8,
0,
1,
NULL,
+ &ucon7_validate,
+ },
+
+ {
+ /* Q_UCON - UPDATE_CONTAINER, v9 */
+ "update_container",
+ "ucon",
+ 9,
+ UPDATE,
+ 0,
+ CONTAINERS_TABLE,
+ 0,
+ ucon_fields,
+ 9,
+ 0,
+ 1,
+ NULL,
&ucon_validate,
},
NULL,
},
+ {
+ /* Q_SCLI - SET_CONTAINER_LIST, v9 */
+ "set_container_list",
+ "scli",
+ 9,
+ UPDATE,
+ 0,
+ CONTAINERS_TABLE,
+ 0,
+ scli_fields,
+ 1,
+ 0,
+ 1,
+ NULL,
+ &scli_validate,
+ },
+
+ {
+ /* Q_GCLI - GET_CONTAINER_LIST, v9 */
+ "get_container_list",
+ "gcli",
+ 9,
+ RETRIEVE,
+ "c",
+ CONTAINERS_TABLE,
+ "c.name, l.name FROM containers c, list l",
+ gcli_fields,
+ 2,
+ "LOWER(c.name) = LOWER('%s') AND c.list_id = l.list_id AND c.list_id != 0",
+ 1,
+ NULL,
+ NULL,
+ },
+
};
int QueryCount = (sizeof(Queries) / sizeof(struct query));