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