]> andersk Git - moira.git/commitdiff
Initial revision
authormar <mar>
Mon, 6 Jul 1992 15:01:21 +0000 (15:01 +0000)
committermar <mar>
Mon, 6 Jul 1992 15:01:21 +0000 (15:01 +0000)
clients/addusr/Imakefile [new file with mode: 0644]
clients/addusr/addusr.c [new file with mode: 0644]
man/addusr.1 [new file with mode: 0644]

diff --git a/clients/addusr/Imakefile b/clients/addusr/Imakefile
new file mode 100644 (file)
index 0000000..c559a06
--- /dev/null
@@ -0,0 +1,19 @@
+# $Header$
+#
+# Copyright 1992 by the Massachusetts Institute of Technology.
+#
+# For copying and distribution information,
+# please see the file <mit-copyright.h>.
+#
+# Imakefile for addusr.
+#
+
+SRCS=addusr.c
+SRCDIR=${SRCTOP}/clients/addusr
+CODE=${SRCS} Imakefile
+OBJS=addusr.o reg_stubs.o
+
+program(addusr,${OBJS},${MR_LIBDEP} ${GDB_LIBDEP}, -lkadm ${CLIBS},${PROGDIR})
+
+reg_stubs.c: ../userreg/reg_stubs.c
+       cp ../userreg/reg_stubs.c reg_stubs.c
diff --git a/clients/addusr/addusr.c b/clients/addusr/addusr.c
new file mode 100644 (file)
index 0000000..1289209
--- /dev/null
@@ -0,0 +1,340 @@
+/* $Header$
+ *
+ * Program to add users en batch to the moira database
+ *
+ * by Mark Rosenstein, July 1992.
+ *
+ * Copyright 1992 by the Massachusetts Institute of Technology.
+ *
+ * (c) Copyright 1992 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
+ */
+
+#include <mit-copyright.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <des.h>
+#include <krb.h>
+#include <gdss.h>
+#include <moira.h>
+#include <moira_site.h>
+
+#ifndef LINT
+static char adduser_rcsid[] = "$Header$";
+#endif
+
+/* flags from command line */
+char *class, *comment, *status_str, *shell, *filename;
+int reg_only, reg, verbose, nodupcheck;
+
+/* argument parsing macro */
+#define argis(a,b) ((strcmp(*arg+1, a) == 0) || (strcmp(*arg+1, b) == 0))
+
+char *whoami;
+int duplicate, errors;
+
+extern char *index();
+extern char *FixCase(), *RemoveHyphens(), *strtrim();
+extern int errno;
+int usercheck(), scream();
+
+
+main(argc, argv)
+int argc;
+char **argv;
+{
+    int status, lineno;
+    char **arg = argv, *qargv[U_END];
+    char *motd, *p, *first, *middle, *last, *id, *login, *passwd, *server;
+    char buf[BUFSIZ], idbuf[32];
+    FILE *input;
+
+    /* clear all flags & lists */
+    reg_only = reg = verbose = lineno = nodupcheck = errors = 0;
+    server = NULL;
+    filename = "-";
+    shell = "/bin/csh";
+    class = "TEMP";
+    comment = "";
+    status_str = "0";
+
+    whoami = argv[0];
+
+    /* parse args */
+    while (++arg - argv < argc) {
+       if  (**arg == '-')
+       {
+           if (argis("c", "class"))
+               if (arg - argv < argc - 1) {
+                   ++arg;
+                   class = *arg;
+               } else
+                   usage(argv);
+           else if (argis("C", "comment"))
+               if (arg - argv < argc - 1) {
+                   ++arg;
+                   comment = *arg;
+               } else
+                   usage(argv);
+           else if (argis("s", "status"))
+               if (arg - argv < argc - 1) {
+                   ++arg;
+                   status_str = *arg;
+               } else
+                   usage(argv);
+           else if (argis("h", "shell"))
+               if (arg - argv < argc - 1) {
+                   ++arg;
+                   shell = *arg;
+               } else
+                   usage(argv);
+           else if (argis("r", "reg_only"))
+               reg_only++;
+           else if (argis("R", "register"))
+               reg++;
+           else if (argis("f", "file"))
+               if (arg - argv < argc - 1) {
+                   ++arg;
+                   filename = *arg;
+               } else
+                   usage(argv);
+           else if (argis("v","verbose"))
+             verbose++;
+           else if (argis("d","nodupcheck"))
+             nodupcheck++;
+           else if (argis("S","server"))
+               if (arg - argv < argc - 1) {
+                   ++arg;
+                   server = *arg;
+               } else
+                   usage(argv);
+           else
+               usage(argv);
+       } else
+         usage(argv);
+    }
+
+    if (!strcmp(filename, "-"))
+      input = stdin;
+    else {
+       input = fopen(filename, "r");
+       if (input == NULL) {
+           com_err(whoami, errno, "opening input file %s", filename);
+           exit(2);
+       }
+    }
+
+    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);
+           }
+       }
+    }
+
+    if (reg || reg_only)
+      ureg_init();
+
+    qargv[U_NAME] = UNIQUE_LOGIN;
+    qargv[U_UID] = UNIQUE_UID;
+    qargv[U_SHELL] = shell;
+    qargv[U_STATE] = status_str;
+    qargv[U_CLASS] = class;
+    qargv[U_COMMENT] = comment;
+    qargv[U_SIGNATURE] = "";
+    qargv[U_SECURE] = "0";
+    while (fgets(buf, BUFSIZ, input)) {
+       /* throw away terminating newline */
+       p = &buf[strlen(buf) - 1];
+       if (*p == '\n')
+         *p = 0;
+       lineno++;
+       if (strlen(buf) == 0)
+         continue;
+       /* Last name is first thing on line */
+       last = buf;
+       /* First name follows a comma */
+       p = index(last, ',');
+       if (!p) {
+           com_err(whoami, MR_BAD_CHAR, "Missing comma on line %d", lineno);
+           errors++;
+           continue;
+       }
+       *p++ = 0;
+       first = p;
+       while (*p) p++;         /* find end-of-line */
+       if (reg_only || reg) {
+           while (!isspace(*p)) p--;
+           if (p <= first) {
+               com_err(whoami, 0, "Missing password on line %d", lineno);
+               errors++;
+               continue;
+           }
+           passwd = strtrim(&p[1]);
+           *p-- = 0;
+           /* previous field is login name */
+           while (isspace(*p)) p--;
+           while (!isspace(*p)) p--;
+           if (p <= first) {
+               com_err(whoami, 0, "Missing login on line %d", lineno);
+               errors++;
+               continue;
+           }
+           login = strtrim(&p[1]);
+           *p-- = 0;
+       } else {
+           /* ID is last thing on line */
+           p--;
+       }
+       while (isspace(*p)) p--;
+       while (!isspace(*p)) p--;
+       if (p <= first) {
+           com_err(whoami, 0, "Missing ID on line %d", lineno);
+           errors++;
+           continue;
+       }
+       id = &p[1];
+       *p-- = 0;
+       /* If something between first name & ID, it's middle name */
+       while (isspace(*p)) p--;
+       while (!isspace(*p)) p--;
+       if (p <= first)
+         middle = "";
+       else {
+           middle = &p[1];
+           *p = 0;
+       }
+       qargv[U_FIRST] = strtrim(first);
+       qargv[U_MIDDLE] = strtrim(middle);
+       qargv[U_LAST] = strtrim(last);
+       qargv[U_MITID] = strtrim(id);
+       FixCase(qargv[U_FIRST]);
+       FixCase(qargv[U_MIDDLE]);
+       FixCase(qargv[U_LAST]);
+       RemoveHyphens(qargv[U_MITID]);
+       if (!reg_only) {
+           if (!nodupcheck) {
+               char *dargv[2];
+
+               dargv[0] = qargv[U_FIRST];
+               dargv[1] = qargv[U_LAST];
+               duplicate = 0;
+               status = mr_query("get_user_account_by_name", 2, dargv,
+                                 usercheck, (char *) qargv);
+               if (status && status != MR_NO_MATCH) {
+                   com_err(whoami, status,
+                           "checking to see if user %s %s already exists",
+                           qargv[0], qargv[1]);
+                   com_err(whoami, 0, "NOT ADDING USER");
+                   errors++;
+                   continue;
+               }
+               if (duplicate > 0) {
+                   com_err(whoami, MR_EXISTS, "user %s %s already exists",
+                           qargv[0], qargv[1]);
+                   com_err(whoami, 0, "NOT ADDING USER");
+                   errors++;
+                   continue;
+               } else if (duplicate < 0) {
+                   com_err(whoami, MR_EXISTS,
+                           "user %s %s already exists with different ID number",
+                           qargv[0], qargv[1]);
+                   com_err(whoami, 0, "ADDING user anyway");
+               }
+           }
+           status = mr_query("add_user_account", U_SECURE + 1, qargv,
+                             scream, NULL);
+           if (status) {
+               com_err(whoami, status, "adding user %s %s", first, last);
+               errors++;
+           } else if (verbose)
+             printf("Added user %s %s %s (%s)\n", qargv[U_FIRST],
+                    qargv[U_MIDDLE], qargv[U_LAST], qargv[U_MITID]);
+       }
+       if (reg || reg_only) {
+           EncryptID(idbuf, qargv[U_MITID], qargv[U_FIRST], qargv[U_LAST]);
+           status = grab_login(qargv[U_FIRST], qargv[U_LAST],
+                               qargv[U_MITID], idbuf, login);
+           if (status) {
+               com_err(whoami, status, "While registering (login) %s %s",
+                       qargv[U_FIRST], qargv[U_LAST]);
+               errors++;
+               continue;
+           } else if (verbose)
+             printf("Registered user %s %s as %s\n", qargv[U_FIRST],
+                    qargv[U_LAST], login);
+           status = set_password(qargv[U_FIRST], qargv[U_LAST],
+                                 qargv[U_MITID], idbuf, passwd);
+           if (status) {
+               com_err(whoami, status, "While registering (passwd) %s %s",
+                       qargv[U_FIRST], qargv[U_LAST]);
+               errors++;
+               continue;
+           } else if (verbose)
+             printf("Set password for user %s\n", login);
+       }
+    }
+
+    exit(errors);
+}
+
+
+usage(argv)
+char **argv;
+{
+    fprintf(stderr, "Usage: %s [options]\n",argv[0]);
+    fprintf(stderr, "Options are\n");
+    fprintf(stderr, "   -f | -file filename (default STDIN)\n");
+    fprintf(stderr, "   -c | -class class (default TEMP)\n");
+    fprintf(stderr, "   -C | -comment \"comment\" (default \"\")\n");
+    fprintf(stderr, "   -s | -status status (default 0)\n");
+    fprintf(stderr, "   -h | -shell shell (default /bin/csh)\n");
+    fprintf(stderr, "   -r | -reg_only\n");
+    fprintf(stderr, "   -R | -register (and add to database)\n");
+    fprintf(stderr, "   -v | -verbose\n");
+    fprintf(stderr, "   -d | -nodupcheck (don't check for duplicates)\n");
+    fprintf(stderr, "   -S | -server servername\n");
+    exit(1);
+}
+
+
+/* Called only if a query returns a value that we weren't expecting */
+
+scream()
+{
+    fprintf(stderr, "Programmer botch\n");
+    exit(3);
+}
+
+
+/* query callback routine to check for duplicate users */
+
+usercheck(argc, argv, qargv)
+int argc;
+char **argv;
+char **qargv;
+{
+    if (!strcmp(argv[U_MITID], qargv[U_MITID]))
+      duplicate++;
+    else
+      duplicate--;
+}
diff --git a/man/addusr.1 b/man/addusr.1
new file mode 100644 (file)
index 0000000..bcfb59c
--- /dev/null
@@ -0,0 +1,80 @@
+.TH ADDUSR 1 "6 Jul 1992" "Project Athena"
+\" RCSID: $Header$
+.SH NAME
+addusr \- add and/or register users in Moira
+.SH SYNOPSIS
+.B addusr [-cCdfhrRsSv]
+.SH DESCRIPTION
+.I Addusr
+is a tool for adding users in bulk to the moira database and
+registering them for accounts.  It reads the users from a file (or
+stdin) rather than the menu-oriented regular moira client.
+
+The users are entered in one of two formats, depending on whether or
+not they will be registered.  When users are only being added to the
+database, the format is:
+.nf
+  lastname, firstname middlename idnumber
+.fi
+The lastname may have spaces in it, as it will continue up until the
+first comma on the line.  The firstname also may have spaces, as it
+will take up everything but the last two tokens on the line.  If only
+3 tokens are on the line, the middlename will be assumed to be the
+empty string.  The middlename cannot have spaces in it.  The idnumber
+also cannot have spaces, although it may have hyphens in it.  The
+capitalization of the names is not important as it will be corrected
+before entering into the database.  If the operation specified for
+.B addusr
+includes registering users, then there are two additional tokens on
+the end of the line:
+.nf
+  lastname, firstname middlename idnumber loginname password
+.fi
+Note that neither the loginname nor the password may contain spaces.
+.SH OPTIONS
+.IP \fB-file\ \fIfilename\ \fRor\ \fB-f\ \fIfilename\fR:
+This specifies the file that will be read for the list of users to
+operate on.  If not specifed, standard input will be used.  The file
+format is described above.
+.IP \fB-class\ \fIclass\ \fRor\ \fB-c\ \fIclass\fR:
+This specifies the account class that will be used for all users added
+in this invocation.  If not specified, \fITEMP\fR will be used.
+.IP \fB-comment\ \fI"comment"\ \fRor\ \fB-C\ \fI"comment"\fR:
+This specifies the comment that will be stored for all users added
+in this invocation.  If not specified, the comment field will be left
+blank.  Note that the double-quotes are not required by \fBaddusr\fR,
+but will be parsed out by the shell and are only needed to specify
+comments with spaces in them.
+.IP \fB-status\ \fIstatus\ \fRor\ \fB-s\ \fIstatus\fR:
+This specifies the account status that will be used for all users added
+in this invocation.  If not specified, \fI0 (registerable)\fR will be used.
+.IP \fB-shell\ \fIshell\ \fRor\ \fB-h\ \fIshell\fR:
+This specifies the login shell that will be stored for all users added
+in this invocation.  If not specified, \fI/bin/csh\fR will be used.
+.IP \fB-register\ \fRor\ \fB-R\fR:
+This instructs \fBaddusr\fR to both add the users to the database and
+then to immediately register them.
+.IP \fB-reg_only\ \fRor\ \fB-r\fR:
+This instructs \fBaddusr\fR to register the users without attempting
+to add them to the database.  They must already exist in the database.
+.IP \fB-verbose\ \fRor\ \fB-v\fR:
+This causes \fBaddusr\fR to print messages about each operation as it
+performs it.
+.IP \fB-nodupcheck\ \fRor\ \fB-d\fR:
+Do not attempt to check the database for duplicates before adding
+users.  Normally \fBaddusr\fR will check the database for users with
+the same name.  If it finds any who match in both name and ID number,
+the user will not be added.  If it finds a name match with a different
+ID number, it will print a warning and add the user anyway.
+.IP \fB-server\ \fIhost:port\ \fRor\ \fB-S\ \fIhost:port\fR:
+Use the specified host and port to contact the Moira server instead of
+the default server.  Both may be symbolic names or numbers.  If the
+port is left off, the default Moira server port will be assumed.  The
+server chosen will be the one specified on the command line, specified
+in the MOIRASERVER environment variable, the hesiod "moira" sloc entry,
+or the compiled in default, in that order or preference.
+
+.SH AUTHOR
+Mark Rosenstein
+.SH SEE ALSO
+moira(1), userreg(1)
This page took 0.864722 seconds and 5 git commands to generate.