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