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>
19 #include <WINNT/afsevent.h>
24 #include <afs/cellconfig.h>
25 #include <afs/afsutil.h>
33 report_error (code, name, gname)
39 if (verbose) printf(" added %s to %s.\n",name,gname);
40 } else if (code == PRIDEXIST) {
41 if (verbose) printf (" user %s already on group %s\n", name, gname);
43 fprintf(stderr,"Couldn't add %s to %s!\n",name,gname);
44 fprintf(stderr,"%s (%d).\n",pr_ErrorMsg(code),code);
50 /* OK, this REALLY sucks bigtime, but I can't tell who is calling
51 * afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
52 * anyway. It's gonna give somebody fits to debug, I know, I know.
57 #include "AFS_component_version_number.c"
63 register afs_int32 code;
64 char name[PR_MAXNAMELEN];
65 char gname[PR_MAXNAMELEN];
66 char owner[PR_MAXNAMELEN];
78 fprintf(stderr,"Usage: readgroup [-v] [-c cellname] groupfile.\n");
82 for (i = 1;i<argc;i++) {
83 if (!strcmp(argv[i],"-v"))
86 if (!strcmp(argv[i],"-c")) {
87 cellname = (char *)malloc(100);
88 strncpy(cellname,argv[++i],100);
91 strncpy(buf,argv[i],150);
94 code = pr_Initialize(2, AFSDIR_CLIENT_ETC_DIRPATH, cellname);
96 fprintf(stderr,"pr_Initialize failed .. exiting.\n");
97 fprintf(stderr,"%s (%d).\n",pr_ErrorMsg(code),code);
101 if ((fp = fopen(buf,"r")) == NULL) {
102 fprintf(stderr,"Couldn't open %s.\n",argv[1]);
106 while ((tmp = fgets(buf,3000,fp)) != NULL) {
107 /* group file lines must either have the name of a group or a tab or blank space at beginning */
108 if (buf[0] == '\n') break;
109 if (buf[0] != ' ' && buf[0] != '\t') {
110 /* grab the group name */
111 memset(gname, 0, PR_MAXNAMELEN);
112 memset(owner, 0, PR_MAXNAMELEN);
113 sscanf(buf,"%s %d",gname,&id);
118 ptr = strchr(gname, ':');
119 strncpy(owner,gname,ptr-gname);
120 if (strcmp(owner,"system") == 0)
121 strncpy(owner,"system:administrators",PR_MAXNAMELEN);
124 printf("Group is %s, owner is %s, id is %d.\n",gname,owner,id);
125 code = pr_CreateGroup(gname,owner,&id);
127 if (code != PRIDEXIST) { /* already exists */
128 fprintf(stderr,"Failed to create group %s with id %d!\n",gname,id);
129 fprintf(stderr,"%s (%d).\n",pr_ErrorMsg(code),code);
131 if (code != PREXIST && code != PRIDEXIST) { /* we won't add users if it's not there */
136 /* read members out of buf and add to the group */
137 memset(name, 0, PR_MAXNAMELEN);
138 while (sscanf(tmp,"%s",name) != EOF) {
139 if (strchr(name,':') == NULL) {
140 /* then it's not a group */
141 code = pr_AddToGroup(name,gname);
142 report_error (code, name, gname);
145 /* add the members of a group to the group */
147 printf("Adding %s to %s.\n",lnames.namelist_val[i],gname);
148 code = pr_ListMembers(name,&lnames);
150 fprintf(stderr,"Couldn't get the members for %s to add to %s.\n",name,gname);
151 fprintf(stderr,"%s (%d).\n",pr_ErrorMsg(code),code);
153 for (i=0;i<lnames.namelist_len;i++) {
154 code = pr_AddToGroup(lnames.namelist_val[i],gname);
155 report_error (code, lnames.namelist_val[i], gname);
157 if (lnames.namelist_val) free(lnames.namelist_val);
159 memset(name, 0, PR_MAXNAMELEN);
164 else { /* must have more names to add */
165 /* if we couldn't create the group, and it wasn't already there, don't try to add more users */
167 /* read members out of buf and add to the group */
168 memset(name, 0, PR_MAXNAMELEN);
171 while (sscanf(tmp,"%s",name) != EOF) {
172 if (strchr(name,':') == NULL) {
173 /* then it's not a group */
174 code = pr_AddToGroup(name,gname);
175 report_error (code, name, gname);
178 /* add the members of a group to the group */
179 code = pr_ListMembers(name,&lnames);
181 fprintf(stderr,"Couldn't get the members for %s to add to %s.\n",name,gname);
182 fprintf(stderr,"%s (%d).\n",pr_ErrorMsg(code),code);
184 for (i=0;i<lnames.namelist_len;i++) {
186 printf("Adding %s to %s.\n",lnames.namelist_val[i],gname);
187 code = pr_AddToGroup(lnames.namelist_val[i],gname);
188 report_error (code, lnames.namelist_val[i], gname);
190 if (lnames.namelist_val) free(lnames.namelist_val);
192 memset(name, 0, PR_MAXNAMELEN);
203 while (**s != ' ' && **s != '\t' && **s != '\0') (*s)++;
204 while (**s == ' ' || **s == '\t') (*s)++;