]> andersk Git - moira.git/blobdiff - server/qaccess.pc
Allow members of hidden lists to get_list_info. They still aren't able
[moira.git] / server / qaccess.pc
index 5820f28303aba7ed91f9db643d0980db65123839..dd473bc189aed1e1b6925036672fe45ba6b20d96 100644 (file)
@@ -274,15 +274,15 @@ int access_visible_list(struct query *q, char *argv[], client *cl)
 int access_vis_list_by_name(struct query *q, char *argv[], client *cl)
 {
   EXEC SQL BEGIN DECLARE SECTION;
-  int acl_id, memacl_id, flags, rowcount;
+  int acl_id, memacl_id, flags, rowcount, list_id;
   char acl_type[LIST_ACL_TYPE_SIZE], memacl_type[LIST_ACL_TYPE_SIZE];
   char *listname;
   EXEC SQL END DECLARE SECTION;
   int status;
 
   listname = argv[0];
-  EXEC SQL SELECT hidden, acl_id, acl_type, memacl_id, memacl_type 
-    INTO :flags, :acl_id, :acl_type, :memacl_id, :memacl_type
+  EXEC SQL SELECT hidden, acl_id, acl_type, memacl_id, memacl_type, list_id 
+    INTO :flags, :acl_id, :acl_type, :memacl_id, :memacl_type, :list_id
     FROM list 
     WHERE name = :listname;
 
@@ -294,14 +294,17 @@ int access_vis_list_by_name(struct query *q, char *argv[], client *cl)
   if (!flags)
     return MR_SUCCESS;
 
-  /* check for client in access control list */
+  /* If the user is a member of the acl, memacl, or the list itself,
+   * accept them.
+   */
   status = find_member(acl_type, acl_id, cl);
   if (!status)
-    {
-      status = find_member(memacl_type, memacl_id, cl);
-      if (!status)
-       return MR_PERM;
-    }
+    status = find_member(memacl_type, memacl_id, cl);
+  if (!status)
+    status = find_member("LIST", list_id, cl);
+  if (!status)
+    return MR_PERM;
+
   return MR_SUCCESS;
 }
 
@@ -309,7 +312,8 @@ int access_vis_list_by_name(struct query *q, char *argv[], client *cl)
 /* access_member - allow user to access member of type "USER" and name matches
  * username, or to access member of type "KERBEROS" and the principal matches
  * the user, or to access member of type "LIST" and list is one that user is
- * on the acl of, or the list is visible.
+ * on the acl of, or the list is visible.  Allow anyone to look up list
+ * memberships of MACHINEs.
  */
 
 int access_member(struct query *q, char *argv[], client *cl)
@@ -329,6 +333,9 @@ int access_member(struct query *q, char *argv[], client *cl)
        return MR_SUCCESS;
     }
 
+  if (!strcmp(argv[0], "MACHINE") || !strcmp(argv[0], "RMACHINE"))
+    return MR_SUCCESS;  
+
   return MR_PERM;
 }
 
@@ -412,16 +419,19 @@ int access_filesys(struct query *q, char *argv[], client *cl)
 int access_host(struct query *q, char *argv[], client *cl)
 {
   EXEC SQL BEGIN DECLARE SECTION;
-  int mid, sid, id;
+  int mid, sid, id, subnet_status;
   char mtype[MACHINE_OWNER_TYPE_SIZE], stype[SUBNET_OWNER_TYPE_SIZE];
+  char *account_number;
   EXEC SQL END DECLARE SECTION;
   int status, idx;
 
   if (q->version < 6)
     idx = 0;
-  else
+  else if (q->version >= 6 && q->version < 8)
     idx = 1;
-
+  else
+    idx = 2;
+  
   if (q->type == RETRIEVE)
     {
       if (strcmp(argv[0], "*") || strcmp(argv[1], "*") ||
@@ -442,11 +452,24 @@ int access_host(struct query *q, char *argv[], client *cl)
        return MR_BAD_CHAR;
 
       id = *(int *)argv[8 + idx];
-      EXEC SQL SELECT s.owner_type, s.owner_id
-       INTO :stype, :sid FROM subnet s
+      EXEC SQL SELECT s.owner_type, s.owner_id, s.status
+       INTO :stype, :sid, :subnet_status FROM subnet s
        WHERE s.snet_id = :id;
       mid = 0;
 
+      /* Non query owner must provide valid billing information. */
+      if (q->version >= 8)
+       {
+         if (subnet_status == SNET_STATUS_BILLABLE)
+           {
+             account_number = argv[7];
+             EXEC SQL SELECT account_number FROM accountnumbers 
+               WHERE account_number = :account_number;
+             if (sqlca.sqlcode == SQL_NO_MATCH)
+               return MR_ACCOUNT_NUMBER;
+           }
+       }
+
       if (find_member(stype, sid, cl))
        return MR_SUCCESS;
       else
@@ -464,14 +487,28 @@ int access_host(struct query *q, char *argv[], client *cl)
       id = *(int *)argv[0];
       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
+       s.owner_type, s.owner_id, s.status INTO :name, :use, :contact, 
+       :billing_contact, :status, :address, :mtype, :mid, :acomment
+       :ocomment, :snid, :stype, :sid, :subnet_status
        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 must provide valid billing information. */
+      if (q->version >= 8)
+       {
+         if ((subnet_status == SNET_STATUS_BILLABLE) &&
+             (atoi(argv[10]) != 3))
+           {
+             account_number = argv[8];
+             EXEC SQL SELECT account_number FROM accountnumbers 
+               WHERE account_number = :account_number;
+             if (sqlca.sqlcode == SQL_NO_MATCH)
+               return MR_ACCOUNT_NUMBER;
+           }
+       }
+
       /* non-query-owner cannot change use or ocomment */
       if ((use != atoi(argv[7 + idx])) || (ocomment != *(int *)argv[14 + idx]))
        return MR_PERM;
@@ -619,3 +656,83 @@ int access_zephyr(struct query *q, char *argv[], client *cl)
     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;
+}
This page took 0.040709 seconds and 4 git commands to generate.