+
+/* access_zephyr */
+int access_zephyr(struct query *q, char *argv[], client *cl)
+{
+ EXEC SQL BEGIN DECLARE SECTION;
+ char type[ZEPHYR_OWNER_TYPE_SIZE];
+ char *class;
+ int id;
+ EXEC SQL END DECLARE SECTION;
+ int status;
+
+ class = argv[ZA_CLASS];
+ EXEC SQL SELECT owner_type, owner_id INTO :type, :id
+ FROM zephyr WHERE class = :class;
+ if (sqlca.sqlcode)
+ return MR_PERM;
+
+ status = find_member(type, id, cl);
+ if (status)
+ return MR_SUCCESS;
+ else
+ return MR_PERM;
+}
+
+/* access_container - check access for most container operations
+ *
+ * Inputs: argv[0] - cnt_id
+ * q - query name
+ * cl - client name
+ *
+ * - check if that client is a member of the access control list
+ * - OR, if the query is add_machine_to_container or delete_machine_from_container
+ * check if the client is a memeber of the mem_acl list
+ * - if the query is update_container and the container is to be renamed and
+ * it is a top-level container, only priviledged users can do it
+ */
+
+int access_container(struct query *q, char *argv[], client *cl)
+{
+ EXEC SQL BEGIN DECLARE SECTION;
+ 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;
+
+ cnt_id = *(int *)argv[0];
+
+ /* 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, publicflg
+ INTO :acl_id, :acl_type, :memacl_id, :memacl_type, :name, :flag
+ FROM containers
+ WHERE cnt_id = :cnt_id;
+
+ if (sqlca.sqlerrd[2] != 1)
+ return MR_INTERNAL;
+
+ /* trim off the trailing spaces */
+ strcpy(name, strtrim(name));
+
+ /* if the query is update_container and the containers is to be renamed
+ * and it is a top-level container, only dbadmin can do it */
+ if (!strcmp(q->shortname, "ucon"))
+ {
+ newname = argv[1];
+ if (strcmp(name, newname) && strchr(name, '/') == NULL)
+ return MR_PERM;
+ }
+
+ /* check for client in access control list and return success right
+ * away if it's there. */
+ if (find_member(acl_type, acl_id, cl))
+ return MR_SUCCESS;
+
+ /* If not amcn, dmcn, we lose. */
+ if (strcmp(q->shortname, "amcn") && strcmp(q->shortname, "dmcn"))
+ return MR_PERM;
+
+ 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;
+}