#include <mit-copyright.h>
#include <moira.h>
#include <moira_site.h>
+#include <mrclient.h>
#include <ctype.h>
#include <errno.h>
void usage(char **argv);
int usercheck(int argc, char **argv, void *qargv);
+int get_uid(int argc, char **argv, void *qargv);
int main(int argc, char **argv)
{
int status, lineno;
char **arg = argv, *qargv[U_END];
- char *motd, *p, *first, *middle, *last, *id, *login, *server;
+ char *p, *first, *middle, *last, *id, *login, *server;
char buf[BUFSIZ], idbuf[32];
FILE *input;
}
}
- if (!reg_only)
- {
- /* fire up Moira */
- if ((status = mr_connect(server)))
- {
- com_err(whoami, status, "unable to connect to the Moira server");
- exit(2);
- }
- if ((status = mr_motd(&motd)))
- {
- com_err(whoami, status, "unable to check server status");
- exit(2);
- }
- if (motd)
- {
- fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
- motd);
- mr_disconnect();
- exit(2);
- }
-
- if ((status = mr_auth("addusr")))
- {
- if (status == MR_USER_AUTH)
- com_err(whoami, status, "");
- else
- {
- com_err(whoami, status, "unable to authenticate to Moira");
- exit(2);
- }
- }
- }
+ /* fire up Moira */
+ if (mrcl_connect(server, "addusr", 1) != MRCL_SUCCESS)
+ exit(2);
qargv[U_NAME] = UNIQUE_LOGIN;
qargv[U_UID] = UNIQUE_UID;
}
if (reg || reg_only)
{
- char *rargv[3];
+ char *gargv[2], *rargv[3], uid[10];
- rargv[0] = qargv[U_MITID];
+ uid[0] = '\0';
+ gargv[0] = qargv[U_FIRST];
+ gargv[1] = qargv[U_LAST];
+ status = mr_query("get_user_account_by_name", 2, gargv,
+ get_uid, &uid);
+ if (status)
+ {
+ com_err(whoami, status, "while looking up uid for %s %s",
+ qargv[U_FIRST], qargv[U_LAST]);
+ errors++;
+ continue;
+ }
+
+ rargv[0] = uid;
rargv[1] = login;
rargv[2] = "0";
- status = mr_query("register_user", 2, rargv, NULL, NULL);
+ status = mr_query("register_user", 3, rargv, NULL, NULL);
if (status)
{
com_err(whoami, status, "while registering (login) %s %s",
return MR_CONT;
}
+
+/* query callback to get uid of a just-added account */
+int get_uid(int argc, char **argv, void *uidv)
+{
+ char *uid = uidv;
+
+ if (uid[0] == '\0')
+ strcpy(uid, argv[U_UID]);
+ else
+ {
+ if (!strcmp(argv[U_MODWITH], "addusr"))
+ strcpy(uid, argv[U_UID]);
+ }
+
+ return MR_CONT;
+}