]> andersk Git - moira.git/blobdiff - reg_svr/reg_svr.pc
check_username_available() should know about the userhistory table.
[moira.git] / reg_svr / reg_svr.pc
index 504712f719752e0da3c2465d2e13c36e792d5050..a8616151ffd51d6aa1aef305e1a07523b0ad6f2e 100644 (file)
@@ -788,6 +788,9 @@ void QUIT(reg_client *rc, int argc, char **argv)
 /* Register a user in Moira */
 int register_user(int uid, char *username)
 {
+  EXEC SQL BEGIN DECLARE SECTION;
+  char class[USERS_TYPE_SIZE];
+  EXEC SQL END DECLARE SECTION;
   char uidbuf[10], *qargv[3], *motd = NULL;
   long status;
 
@@ -816,10 +819,28 @@ int register_user(int uid, char *username)
       return MR_INTERNAL;
     }
 
+  EXEC SQL SELECT type INTO :class FROM users WHERE unix_uid = :uid;
+
   sprintf(uidbuf, "%d", uid);
   qargv[0] = uidbuf;
   qargv[1] = username;
-  qargv[2] = "IMAP";
+
+  /* Incoming students should be given Exchange poboxes.
+   * Doesn't work for undergrads in the class of 2100 or higher.
+   */ 
+  if (!strcmp(strtrim(class), "G") || !strncmp(class, "FALL", 4) ||
+      !strncmp(class, "SPRING", 5) || !strncmp(class, "SUMMER", 6) ||
+      !strncmp(class, "20", 2))
+    {
+      com_err(whoami, 0, "assigning EXCHANGE pobox to user %s, class %s", username, class);
+      qargv[2] = "EXCHANGE";
+    }
+  else 
+    {
+      com_err(whoami, 0, "assigning IMAP pobox to user %s, class %s", username, class);
+      qargv[2] = "IMAP";
+    }
+
   status = mr_query("register_user", 3, qargv, NULL, NULL);
   mr_disconnect();
   return status;
@@ -985,6 +1006,13 @@ int check_username_available(char *username)
   if (count != 0)
     return MR_IN_USE;
 
+  EXEC SQL SELECT COUNT(login) INTO :count FROM userhistory
+    WHERE login = :username;
+  if (sqlca.sqlcode)
+    return MR_DBMS_ERR;
+  if (count != 0)
+    return MR_IN_USE;
+
   return MR_SUCCESS;
 }
 
This page took 0.032184 seconds and 4 git commands to generate.