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 <afs/param.h>
15 #include <WINNT/afsevent.h>
20 #include <afs/cellconfig.h>
21 #include <afs/afsutil.h>
27 report_error (code, name, gname)
33 if (verbose) printf(" added %s to %s.\n",name,gname);
34 } else if (code == PRIDEXIST) {
35 if (verbose) printf (" user %s already on group %s\n", name, gname);
37 fprintf(stderr,"Couldn't add %s to %s!\n",name,gname);
38 fprintf(stderr,"%s (%d).\n",pr_ErrorMsg(code),code);
44 /* OK, this REALLY sucks bigtime, but I can't tell who is calling
45 * afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
46 * anyway. It's gonna give somebody fits to debug, I know, I know.
51 #include "AFS_component_version_number.c"
57 register afs_int32 code;
58 char name[PR_MAXNAMELEN];
59 char gname[PR_MAXNAMELEN];
60 char owner[PR_MAXNAMELEN];
73 fprintf(stderr,"Usage: readgroup [-v] [-c cellname] groupfile.\n");
77 for (i = 1;i<argc;i++) {
78 if (!strcmp(argv[i],"-v"))
81 if (!strcmp(argv[i],"-c")) {
82 cellname = (char *)malloc(100);
83 strncpy(cellname,argv[++i],100);
86 strncpy(buf,argv[i],150);
89 code = pr_Initialize(2, AFSDIR_CLIENT_ETC_DIRPATH, cellname);
91 fprintf(stderr,"pr_Initialize failed .. exiting.\n");
92 fprintf(stderr,"%s (%d).\n",pr_ErrorMsg(code),code);
96 if ((fp = fopen(buf,"r")) == NULL) {
97 fprintf(stderr,"Couldn't open %s.\n",argv[1]);
101 while ((tmp = fgets(buf,3000,fp)) != NULL) {
102 /* group file lines must either have the name of a group or a tab or blank space at beginning */
103 if (buf[0] == '\n') break;
104 if (buf[0] != ' ' && buf[0] != '\t') {
105 /* grab the group name */
106 bzero(gname,PR_MAXNAMELEN);
107 bzero(owner,PR_MAXNAMELEN);
108 sscanf(buf,"%s %d",gname,&id);
113 ptr = index(gname,':');
114 strncpy(owner,gname,ptr-gname);
115 if (strcmp(owner,"system") == 0)
116 strncpy(owner,"system:administrators",PR_MAXNAMELEN);
119 printf("Group is %s, owner is %s, id is %d.\n",gname,owner,id);
120 code = pr_CreateGroup(gname,owner,&id);
122 if (code != PRIDEXIST) { /* already exists */
123 fprintf(stderr,"Failed to create group %s with id %d!\n",gname,id);
124 fprintf(stderr,"%s (%d).\n",pr_ErrorMsg(code),code);
126 if (code != PREXIST && code != PRIDEXIST) { /* we won't add users if it's not there */
131 /* read members out of buf and add to the group */
132 bzero(name,PR_MAXNAMELEN);
133 while (sscanf(tmp,"%s",name) != EOF) {
134 if (index(name,':') == NULL) {
135 /* then it's not a group */
136 code = pr_AddToGroup(name,gname);
137 report_error (code, name, gname);
140 /* add the members of a group to the group */
142 printf("Adding %s to %s.\n",lnames.namelist_val[i],gname);
143 code = pr_ListMembers(name,&lnames);
145 fprintf(stderr,"Couldn't get the members for %s to add to %s.\n",name,gname);
146 fprintf(stderr,"%s (%d).\n",pr_ErrorMsg(code),code);
148 for (i=0;i<lnames.namelist_len;i++) {
149 code = pr_AddToGroup(lnames.namelist_val[i],gname);
150 report_error (code, lnames.namelist_val[i], gname);
152 if (lnames.namelist_val) free(lnames.namelist_val);
154 bzero(name,PR_MAXNAMELEN);
159 else { /* must have more names to add */
160 /* if we couldn't create the group, and it wasn't already there, don't try to add more users */
162 /* read members out of buf and add to the group */
163 bzero(name,PR_MAXNAMELEN);
166 while (sscanf(tmp,"%s",name) != EOF) {
167 if (index(name,':') == NULL) {
168 /* then it's not a group */
169 code = pr_AddToGroup(name,gname);
170 report_error (code, name, gname);
173 /* add the members of a group to the group */
174 code = pr_ListMembers(name,&lnames);
176 fprintf(stderr,"Couldn't get the members for %s to add to %s.\n",name,gname);
177 fprintf(stderr,"%s (%d).\n",pr_ErrorMsg(code),code);
179 for (i=0;i<lnames.namelist_len;i++) {
181 printf("Adding %s to %s.\n",lnames.namelist_val[i],gname);
182 code = pr_AddToGroup(lnames.namelist_val[i],gname);
183 report_error (code, lnames.namelist_val[i], gname);
185 if (lnames.namelist_val) free(lnames.namelist_val);
187 bzero(name,PR_MAXNAMELEN);
197 while (**s != ' ' && **s != '\t' && **s != '\0') (*s)++;
198 while (**s == ' ' || **s == '\t') (*s)++;