46e3a9e15c946e54f440669d5227ae934468754a
[openafs.git] / src / ptserver / readpwd.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13
14 #include <stdio.h>
15 #ifdef AFS_NT40_ENV
16 #include <WINNT/afsevent.h>
17 #endif
18 #include <string.h>
19 #include <rx/rx.h>
20 #include <rx/xdr.h>
21 #include <afs/cellconfig.h>
22 #include <afs/afsutil.h>
23 #include <afs/com_err.h>
24 #include "ptclient.h"
25 #include "ptuser.h"
26 #include "ptprototypes.h"
27
28 int
29 osi_audit(void)
30 {
31 /* OK, this REALLY sucks bigtime, but I can't tell who is calling
32  * afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
33  * anyway.  It's gonna give somebody fits to debug, I know, I know.
34  */
35     return 0;
36 }
37
38 #include "AFS_component_version_number.c"
39
40 int
41 main(afs_int32 argc, char **argv)
42 {
43
44     afs_int32 code;
45     char name[PR_MAXNAMELEN];
46     afs_int32 id;
47     char buf[150];
48     FILE *fp;
49     char *ptr;
50     char *aptr;
51     char *tmp;
52     char uid[8];
53     afs_int32 i;
54     afs_int32 verbose = 0;
55     char *cellname;
56
57     if (argc < 2) {
58         fprintf(stderr, "Usage: readpwd [-v] [-c cellname] passwdfile.\n");
59         exit(1);
60     }
61     cellname = 0;
62     for (i = 1; i < argc; i++) {
63         if (!strcmp(argv[i], "-v"))
64             verbose = 1;
65         else {
66             if (!strcmp(argv[i], "-c")) {
67                 cellname = (char *)malloc(100);
68                 strncpy(cellname, argv[++i], 100);
69             } else
70                 strncpy(buf, argv[i], 150);
71         }
72     }
73     code = pr_Initialize(2, AFSDIR_CLIENT_ETC_DIRPATH, cellname);
74     free(cellname);
75     if (code) {
76         fprintf(stderr, "pr_Initialize failed, code %d.\n", code);
77         exit(1);
78     }
79
80
81     if ((fp = fopen(buf, "r")) == NULL) {
82         fprintf(stderr, "Couldn't open %s.\n", argv[1]);
83         exit(2);
84     }
85     while ((tmp = fgets(buf, 150, fp)) != NULL) {
86         memset(name, 0, PR_MAXNAMELEN);
87         memset(uid, 0, 8);
88         ptr = strchr(buf, ':');
89         strncpy(name, buf, ptr - buf);
90         aptr = strchr(++ptr, ':');
91         ptr = strchr(++aptr, ':');
92         strncpy(uid, aptr, ptr - aptr);
93         id = atoi(uid);
94         if (verbose)
95             printf("Adding %s with id %d.\n", name, id);
96         code = pr_CreateUser(name, &id);
97         if (code) {
98             fprintf(stderr, "Failed to add user %s with id %d!\n", name, id);
99             fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code), code);
100         }
101     }
102     return 0;
103 }