#include <unistd.h>
#include <com_err.h>
+#ifdef HAVE_KRB4
#include <krb.h>
+#endif
EXEC SQL INCLUDE sqlca;
/* 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;
return MR_DOWN;
}
- status = krb_get_svc_in_tkt(REG_SVR_PRINCIPAL, REG_SVR_INSTANCE,
- krb_realmofhost(hostname), MOIRA_SNAME,
- shorthostname, 3, KEYFILE);
- if (status)
- status += ERROR_TABLE_BASE_krb;
- else
- status = mr_auth("reg_svr");
+ status = mr_krb5_auth("reg_svr");
if (status)
{
com_err(whoami, status, "authenticating to moira");
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;
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;
}