ptserver-prototypes-20090316
[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 RCSID
14     ("$Header$");
15
16 #include <stdio.h>
17 #ifdef AFS_NT40_ENV
18 #include <WINNT/afsevent.h>
19 #endif
20 #include <string.h>
21 #include <rx/rx.h>
22 #include <rx/xdr.h>
23 #include <afs/cellconfig.h>
24 #include <afs/afsutil.h>
25 #include <afs/com_err.h>
26 #include "ptclient.h"
27 #include "ptuser.h"
28 #include "ptprototypes.h"
29
30 int
31 osi_audit(void)
32 {
33 /* OK, this REALLY sucks bigtime, but I can't tell who is calling
34  * afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
35  * anyway.  It's gonna give somebody fits to debug, I know, I know.
36  */
37     return 0;
38 }
39
40 #include "AFS_component_version_number.c"
41
42 int
43 main(afs_int32 argc, char **argv)
44 {
45
46     register afs_int32 code;
47     char name[PR_MAXNAMELEN];
48     afs_int32 id;
49     char buf[150];
50     FILE *fp;
51     char *ptr;
52     char *aptr;
53     char *tmp;
54     char uid[8];
55     afs_int32 i;
56     afs_int32 verbose = 0;
57     char *cellname;
58
59     if (argc < 2) {
60         fprintf(stderr, "Usage: readpwd [-v] [-c cellname] passwdfile.\n");
61         exit(1);
62     }
63     cellname = 0;
64     for (i = 1; i < argc; i++) {
65         if (!strcmp(argv[i], "-v"))
66             verbose = 1;
67         else {
68             if (!strcmp(argv[i], "-c")) {
69                 cellname = (char *)malloc(100);
70                 strncpy(cellname, argv[++i], 100);
71             } else
72                 strncpy(buf, argv[i], 150);
73         }
74     }
75     code = pr_Initialize(2, AFSDIR_CLIENT_ETC_DIRPATH, cellname);
76     free(cellname);
77     if (code) {
78         fprintf(stderr, "pr_Initialize failed, code %d.\n", code);
79         exit(1);
80     }
81
82
83     if ((fp = fopen(buf, "r")) == NULL) {
84         fprintf(stderr, "Couldn't open %s.\n", argv[1]);
85         exit(2);
86     }
87     while ((tmp = fgets(buf, 150, fp)) != NULL) {
88         memset(name, 0, PR_MAXNAMELEN);
89         memset(uid, 0, 8);
90         ptr = strchr(buf, ':');
91         strncpy(name, buf, ptr - buf);
92         aptr = strchr(++ptr, ':');
93         ptr = strchr(++aptr, ':');
94         strncpy(uid, aptr, ptr - aptr);
95         id = atoi(uid);
96         if (verbose)
97             printf("Adding %s with id %d.\n", name, id);
98         code = pr_CreateUser(name, &id);
99         if (code) {
100             fprintf(stderr, "Failed to add user %s with id %d!\n", name, id);
101             fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code), code);
102         }
103     }
104     return 0;
105 }