00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #pragma ident "@(#) libf/pxf/pxfgetgrnam.c 92.1 06/29/99 11:36:06"
00038
00039
00040 #include <fortran.h>
00041 #include <errno.h>
00042 #include <liberrno.h>
00043 #include <malloc.h>
00044 #include <grp.h>
00045 #include <string.h>
00046 #include "pxfstruct.h"
00047 #include "table.h"
00048
00049 #ifndef _UNICOS
00050 #include <stddef.h>
00051 #endif
00052
00053 extern char *_fc_acopy(_fcd f);
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 #ifdef _UNICOS
00095 void
00096 PXFGETGRNAM(
00097 #else
00098 void
00099 _PXFGETGRNAM(
00100 #endif
00101 _fcd NAME,
00102 _f_int *ILEN,
00103 _f_int *JGROUP,
00104 _f_int *IERROR
00105 )
00106 {
00107 int count, i, j;
00108 struct group *groupsrc,
00109 *grouporiginal,
00110 grouptemp;
00111
00112
00113 char *cname,
00114 **membersrc,
00115 **memberdest;
00116 struct pxfhandle pxfhand;
00117
00118 pxfhand = _pxfhandle_table_lookup(&_pxfhandle_table, *JGROUP);
00119 if (pxfhand.pxfstructptr == NULL || pxfhand.pxftype != PXF_GROUP) {
00120 *IERROR = EBADHANDLE;
00121 return;
00122 }
00123 grouporiginal = (struct group *)pxfhand.pxfstructptr;
00124
00125
00126 if (*ILEN < 0 || *ILEN > _fcdlen(NAME)) {
00127 *IERROR = EINVAL;
00128 } else {
00129
00130 if (*ILEN == 0) {
00131
00132
00133
00134
00135
00136 cname = _fc_acopy(NAME);
00137 if (cname == NULL) {
00138 *IERROR = ENOMEM;
00139 return;
00140 }
00141
00142 } else {
00143 cname = (char *) malloc (*ILEN + 1);
00144 if (cname != NULL) {
00145 (void) memcpy(cname, _fcdtocp(NAME), *ILEN);
00146 cname[*ILEN] ='\0';
00147 } else {
00148 *IERROR = ENOMEM;
00149 return;
00150 }
00151 }
00152
00153
00154 if ((groupsrc = getgrnam(cname)) != NULL) {
00155
00156 free(cname);
00157
00158
00159
00160 grouptemp.gr_name =
00161 (char *) malloc((strlen(groupsrc->gr_name)+1)*sizeof(char));
00162 if (grouptemp.gr_name == NULL) {
00163 *IERROR = ENOMEM;
00164 return;
00165 }
00166 (void) strcpy(grouptemp.gr_name, groupsrc->gr_name);
00167
00168
00169
00170
00171 grouptemp.gr_passwd =
00172 (char *) malloc((strlen(groupsrc->gr_passwd)+1)*sizeof(char));
00173 if (grouptemp.gr_passwd == NULL) {
00174 *IERROR = ENOMEM;
00175 free(grouptemp.gr_name);
00176 return;
00177 }
00178 (void) strcpy(grouptemp.gr_passwd, groupsrc->gr_passwd);
00179
00180
00181 grouptemp.gr_gid = groupsrc->gr_gid;
00182
00183
00184 membersrc = groupsrc->gr_mem;
00185 for(count = 0; membersrc[count] != NULL; count++);
00186
00187
00188
00189 memberdest = (char **) calloc(count+1,sizeof(char *));
00190 if (memberdest == NULL) {
00191 *IERROR = ENOMEM;
00192 free(grouptemp.gr_name);
00193 free(grouptemp.gr_passwd);
00194 return;
00195 }
00196 for(i = 0; i < count; i++) {
00197 memberdest[i] = (char *) malloc((strlen(membersrc[i])+1)*sizeof(char));
00198 if (memberdest[i] == NULL) {
00199 *IERROR = ENOMEM;
00200 for(j = 0; j < i; j++) free(memberdest[j]);
00201 free(grouptemp.gr_name);
00202 free(grouptemp.gr_passwd);
00203 free(memberdest);
00204 return;
00205 }
00206 (void) strcpy(memberdest[i], membersrc[i]);
00207 }
00208 memberdest[i]= NULL;
00209 grouptemp.gr_mem = memberdest;
00210 } else {
00211 *IERROR = ENOENT;
00212 free(cname);
00213 return;
00214 }
00215 }
00216
00217
00218 free(grouporiginal->gr_name);
00219 free(grouporiginal->gr_passwd);
00220 if (grouporiginal->gr_mem != NULL) {
00221 for(i=0; grouporiginal->gr_mem[i] != NULL; i++) {
00222 free(grouporiginal->gr_mem[i]);
00223 }
00224 free(grouporiginal->gr_mem);
00225 }
00226 *grouporiginal = grouptemp;
00227 }
00228
00229
00230 #ifndef _UNICOS
00231 void
00232 pxfgetgrnam_(
00233 char *NAME,
00234 _f_int *ILEN,
00235 _f_int *JGROUP,
00236 _f_int *IERROR,
00237 _f_int namelen
00238 )
00239 {
00240 _PXFGETGRNAM( _cptofcd(NAME, namelen), ILEN,
00241 JGROUP, IERROR);
00242 }
00243 #endif
00244
00245
00246
00247
00248
00249
00250