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(code, name, gname)
46 printf(" added %s to %s.\n", name, gname);
47 } else if (code == PRIDEXIST) {
49 printf(" user %s already on group %s\n", name, gname);
51 fprintf(stderr, "Couldn't add %s to %s!\n", name, gname);
52 fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code), code);
59 /* OK, this REALLY sucks bigtime, but I can't tell who is calling
60 * afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
61 * anyway. It's gonna give somebody fits to debug, I know, I know.
66 #include "AFS_component_version_number.c"
72 register afs_int32 code;
73 char name[PR_MAXNAMELEN];
74 char gname[PR_MAXNAMELEN];
75 char owner[PR_MAXNAMELEN];
87 fprintf(stderr, "Usage: readgroup [-v] [-c cellname] groupfile.\n");
91 for (i = 1; i < argc; i++) {
92 if (!strcmp(argv[i], "-v"))
95 if (!strcmp(argv[i], "-c")) {
96 cellname = (char *)malloc(100);
97 strncpy(cellname, argv[++i], 100);
99 strncpy(buf, argv[i], 150);
102 code = pr_Initialize(2, AFSDIR_CLIENT_ETC_DIRPATH, cellname);
104 fprintf(stderr, "pr_Initialize failed .. exiting.\n");
105 fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code), code);
109 if ((fp = fopen(buf, "r")) == NULL) {
110 fprintf(stderr, "Couldn't open %s.\n", argv[1]);
114 while ((tmp = fgets(buf, 3000, fp)) != NULL) {
115 /* group file lines must either have the name of a group or a tab or blank space at beginning */
118 if (buf[0] != ' ' && buf[0] != '\t') {
119 /* grab the group name */
120 memset(gname, 0, PR_MAXNAMELEN);
121 memset(owner, 0, PR_MAXNAMELEN);
122 sscanf(buf, "%s %d", gname, &id);
127 ptr = strchr(gname, ':');
128 strncpy(owner, gname, ptr - gname);
129 if (strcmp(owner, "system") == 0)
130 strncpy(owner, "system:administrators", PR_MAXNAMELEN);
133 printf("Group is %s, owner is %s, id is %d.\n", gname, owner,
135 code = pr_CreateGroup(gname, owner, &id);
137 if (code != PRIDEXIST) { /* already exists */
138 fprintf(stderr, "Failed to create group %s with id %d!\n",
140 fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code), code);
142 if (code != PREXIST && code != PRIDEXIST) { /* we won't add users if it's not there */
147 /* read members out of buf and add to the group */
148 memset(name, 0, PR_MAXNAMELEN);
149 while (sscanf(tmp, "%s", name) != EOF) {
150 if (strchr(name, ':') == NULL) {
151 /* then it's not a group */
152 code = pr_AddToGroup(name, gname);
153 report_error(code, name, gname);
155 /* add the members of a group to the group */
157 printf("Adding %s to %s.\n",
158 lnames.namelist_val[i], gname);
159 code = pr_ListMembers(name, &lnames);
162 "Couldn't get the members for %s to add to %s.\n",
164 fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code),
167 for (i = 0; i < lnames.namelist_len; i++) {
169 pr_AddToGroup(lnames.namelist_val[i], gname);
170 report_error(code, lnames.namelist_val[i], gname);
172 if (lnames.namelist_val)
173 free(lnames.namelist_val);
175 memset(name, 0, PR_MAXNAMELEN);
179 } else { /* must have more names to add */
180 /* if we couldn't create the group, and it wasn't already there, don't try to add more users */
183 /* read members out of buf and add to the group */
184 memset(name, 0, PR_MAXNAMELEN);
187 while (sscanf(tmp, "%s", name) != EOF) {
188 if (strchr(name, ':') == NULL) {
189 /* then it's not a group */
190 code = pr_AddToGroup(name, gname);
191 report_error(code, name, gname);
193 /* add the members of a group to the group */
194 code = pr_ListMembers(name, &lnames);
197 "Couldn't get the members for %s to add to %s.\n",
199 fprintf(stderr, "%s (%d).\n", pr_ErrorMsg(code),
202 for (i = 0; i < lnames.namelist_len; i++) {
204 printf("Adding %s to %s.\n",
205 lnames.namelist_val[i], gname);
206 code = pr_AddToGroup(lnames.namelist_val[i], gname);
207 report_error(code, lnames.namelist_val[i], gname);
209 if (lnames.namelist_val)
210 free(lnames.namelist_val);
212 memset(name, 0, PR_MAXNAMELEN);
223 while (**s != ' ' && **s != '\t' && **s != '\0')
225 while (**s == ' ' || **s == '\t')