]> andersk Git - moira.git/blobdiff - server/qaccess.pc
Back out the validate_chars() portion of the empty string patch; V_CHAR
[moira.git] / server / qaccess.pc
index f6ea10440852c5130a0022c421142f253bc3b4f4..c80e842609cb19a267e5e359fc1b42b0e5ac3226 100644 (file)
@@ -128,18 +128,18 @@ int access_list(struct query *q, char *argv[], client *cl)
 {
   EXEC SQL BEGIN DECLARE SECTION;
   int list_id, acl_id, flags, gid, users_id, member_id, member_acl_id;
-  int memacl_id;
+  int memacl_id, mailman, mailman_id;
   char acl_type[LIST_ACL_TYPE_SIZE], name[LIST_NAME_SIZE], *newname;
   char member_acl_type[LIST_ACL_TYPE_SIZE], memacl_type[LIST_ACL_TYPE_SIZE];
   EXEC SQL END DECLARE SECTION;
-  int status;
+  int status, cnt;
 
   list_id = *(int *)argv[0];
   member_id = *(int *)argv[2];
   EXEC SQL SELECT acl_id, acl_type, memacl_id, memacl_type,
-    gid, publicflg, name
+    gid, publicflg, name, mailman, mailman_id
     INTO :acl_id, :acl_type, :memacl_id, :memacl_type, 
-    :gid, :flags, :name
+    :gid, :flags, :name, :mailman, :mailman_id
     FROM list
     WHERE list_id = :list_id;
 
@@ -163,32 +163,41 @@ int access_list(struct query *q, char *argv[], client *cl)
 
       newname = argv[1];
 
-      if (!strcmp("ulis", q->shortname))
-         {
-           /* Check that it doesn't conflict with the Grouper namespace. */
-           if (strlen(newname) > 4 && isdigit(newname[2]) && 
-               isdigit(newname[3]) && newname[4] == '-')
-             {
-               if (!strncasecmp(newname, "fa", 2) ||
-                   !strncasecmp(newname, "sp", 2) ||
-                   !strncasecmp(newname, "su", 2) ||
-                   !strncasecmp(newname, "ja", 2))
-                 return MR_RESERVED;
-             }
-
-           /* Don't let anyone take owner-foo list names.  They interact 
-            * weirdly with the aliases automatically generated by 
-            * mailhub.gen.
-            */
-           if (!strncasecmp(newname, "owner-", 6))
-             return MR_RESERVED;
-         }
-
+      /* Check that it doesn't conflict with the Grouper namespace. */
+      if (strlen(newname) > 4 && isdigit(newname[2]) && 
+         isdigit(newname[3]) && newname[4] == '-')
+       {
+         if (!strncasecmp(newname, "fa", 2) ||
+             !strncasecmp(newname, "sp", 2) ||
+             !strncasecmp(newname, "su", 2) ||
+             !strncasecmp(newname, "ja", 2))
+           return MR_RESERVED;
+       }
+      
+      /* Don't let anyone take owner-foo list names.  They interact 
+       * weirdly with the aliases automatically generated by 
+       * mailhub.gen.
+       */
+      if (!strncasecmp(newname, "owner-", 6))
+       return MR_RESERVED;
+      
       EXEC SQL SELECT users_id INTO :users_id FROM users
        WHERE login = :newname;
       if ((sqlca.sqlcode != SQL_NO_MATCH) && strcmp(strtrim(name), newname) &&
          (users_id != cl->users_id))
        return MR_PERM;
+
+      /* For modern enough clients, don't allow ordinary users to toggle
+       * the mailman bit or change the server.
+       */
+      if (q->version >= 10)
+       {
+         if (mailman != atoi(argv[9]))
+           return MR_PERM;
+
+         if (mailman_id != *(int *)argv[10])
+           return MR_PERM;
+       }
     }
 
   /* check for client in access control list and return success right 
@@ -274,15 +283,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 +303,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 +321,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 +342,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;
 }
 
@@ -665,9 +681,10 @@ int access_zephyr(struct query *q, char *argv[], client *cl)
 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;
 
@@ -675,10 +692,13 @@ int access_container(struct query *q, char *argv[], client *cl)
   
   /* 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;
 
@@ -709,6 +729,19 @@ int access_container(struct query *q, char *argv[], client *cl)
   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.073406 seconds and 4 git commands to generate.