2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include <afs/param.h>
18 #include <WINNT/afsevent.h>
30 #include <afs/cellconfig.h>
31 #include <afs/afsutil.h>
39 report_error(afs_int32 code, char *name, char *gname)
43 printf(" added %s to %s.\n", name, gname);
44 } else if (code == PRIDEXIST) {
46 printf(" user %s already on group %s\n", name, gname);
48 fprintf(stderr, "Couldn't add %s to %s!\n", name, gname);
49 fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code), code);
56 /* OK, this REALLY sucks bigtime, but I can't tell who is calling
57 * afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
58 * anyway. It's gonna give somebody fits to debug, I know, I know.
63 #include "AFS_component_version_number.c"
66 main(int argc, char **argv)
68 register afs_int32 code;
69 char name[PR_MAXNAMELEN];
70 char gname[PR_MAXNAMELEN];
71 char owner[PR_MAXNAMELEN];
83 fprintf(stderr, "Usage: readgroup [-v] [-c cellname] groupfile.\n");
87 for (i = 1; i < argc; i++) {
88 if (!strcmp(argv[i], "-v"))
91 if (!strcmp(argv[i], "-c")) {
92 cellname = (char *)malloc(100);
93 strncpy(cellname, argv[++i], 100);
95 strncpy(buf, argv[i], 150);
98 code = pr_Initialize(2, AFSDIR_CLIENT_ETC_DIRPATH, cellname);
101 fprintf(stderr, "pr_Initialize failed .. exiting.\n");
102 fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code), code);
106 if ((fp = fopen(buf, "r")) == NULL) {
107 fprintf(stderr, "Couldn't open %s.\n", argv[1]);
111 while ((tmp = fgets(buf, 3000, fp)) != NULL) {
112 /* group file lines must either have the name of a group or a tab or blank space at beginning */
115 if (buf[0] != ' ' && buf[0] != '\t') {
116 /* grab the group name */
117 memset(gname, 0, PR_MAXNAMELEN);
118 memset(owner, 0, PR_MAXNAMELEN);
119 sscanf(buf, "%s %d", gname, &id);
124 ptr = strchr(gname, ':');
125 strncpy(owner, gname, ptr - gname);
126 if (strcmp(owner, "system") == 0)
127 strncpy(owner, "system:administrators", PR_MAXNAMELEN);
130 printf("Group is %s, owner is %s, id is %d.\n", gname, owner,
132 code = pr_CreateGroup(gname, owner, &id);
134 if (code != PRIDEXIST) { /* already exists */
135 fprintf(stderr, "Failed to create group %s with id %d!\n",
137 fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code), code);
139 if (code != PREXIST && code != PRIDEXIST) { /* we won't add users if it's not there */
144 /* read members out of buf and add to the group */
145 memset(name, 0, PR_MAXNAMELEN);
146 while (sscanf(tmp, "%s", name) != EOF) {
147 if (strchr(name, ':') == NULL) {
148 /* then it's not a group */
149 code = pr_AddToGroup(name, gname);
150 report_error(code, name, gname);
152 /* add the members of a group to the group */
154 printf("Adding %s to %s.\n",
155 lnames.namelist_val[i], gname);
156 code = pr_ListMembers(name, &lnames);
159 "Couldn't get the members for %s to add to %s.\n",
161 fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code),
164 for (i = 0; i < lnames.namelist_len; i++) {
166 pr_AddToGroup(lnames.namelist_val[i], gname);
167 report_error(code, lnames.namelist_val[i], gname);
169 if (lnames.namelist_val)
170 free(lnames.namelist_val);
172 memset(name, 0, PR_MAXNAMELEN);
176 } else { /* must have more names to add */
177 /* if we couldn't create the group, and it wasn't already there, don't try to add more users */
180 /* read members out of buf and add to the group */
181 memset(name, 0, PR_MAXNAMELEN);
184 while (sscanf(tmp, "%s", name) != EOF) {
185 if (strchr(name, ':') == NULL) {
186 /* then it's not a group */
187 code = pr_AddToGroup(name, gname);
188 report_error(code, name, gname);
190 /* add the members of a group to the group */
191 code = pr_ListMembers(name, &lnames);
194 "Couldn't get the members for %s to add to %s.\n",
196 fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code),
199 for (i = 0; i < lnames.namelist_len; i++) {
201 printf("Adding %s to %s.\n",
202 lnames.namelist_val[i], gname);
203 code = pr_AddToGroup(lnames.namelist_val[i], gname);
204 report_error(code, lnames.namelist_val[i], gname);
206 if (lnames.namelist_val)
207 free(lnames.namelist_val);
209 memset(name, 0, PR_MAXNAMELEN);
219 while (**s != ' ' && **s != '\t' && **s != '\0')
221 while (**s == ' ' || **s == '\t')