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