/[pdpsoft]/trunk/grid-mw-security/ees/plugin_examples/localaccount/src/localaccount.c
ViewVC logotype

Diff of /trunk/grid-mw-security/ees/plugin_examples/localaccount/src/localaccount.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1753 by aramv, Tue Jun 1 23:48:58 2010 UTC revision 1754 by aramv, Thu Jun 10 16:35:55 2010 UTC
# Line 4  Line 4 
4  #include <getopt.h>  #include <getopt.h>
5  #include <stdio.h>  #include <stdio.h>
6  #include <pwd.h>  #include <pwd.h>
7    #include <sys/stat.h>
 gid_t gid_from_user_name(char* _user_name);  
 gid_t gid_from_uid(uid_t _uid);  
 /*gid_t gid_from_group_name(char* _group_name);*/  
 uid_t uid_from_user_name(char* _user_name);  
 char* username_from_passwd_struct(struct passwd _pw_entry);  
 struct passwd passwd_struct_for_gid(gid_t _gid);  
 struct passwd passwd_struct_for_uid(uid_t _uid);  
 /*struct passwd passwd_struct_for_group_name(char* _group_name);*/  
 struct passwd passwd_struct_for_user_name(char* _user_name);  
 void print_passwd_entry(struct passwd _pw_entry);  
8    
9  EES_PL_RC set_var_as_string(char* name, char* value);  EES_PL_RC set_var_as_string(char* name, char* value);
10  EES_PL_RC set_var_as_void_p(char* name, void* value, size_t size);  EES_PL_RC set_var_as_void_p(char* name, void* value, size_t size);
# Line 52  EES_PL_RC plugin_initialize(int argc, ch Line 42  EES_PL_RC plugin_initialize(int argc, ch
42    };    };
43    
44    EEF_log(LOG_DEBUG, "%s: Initializing localaccount plugin!\n", EEF_getRunningPluginName());    EEF_log(LOG_DEBUG, "%s: Initializing localaccount plugin!\n", EEF_getRunningPluginName());
   printf("%s: Initializing localaccount plugin!\n", EEF_getRunningPluginName());  
45    
46    /* defaults */    /* defaults */
47    _mapping_attribute = "http://authz-interop.org/xacml/subject/subject-x509-id";    _mapping_attribute = "http://authz-interop.org/xacml/subject/subject-x509-id";
48    
49    _obligation_name = "uidgid";    _obligation_name = NULL;
50    _attribute_user = "posix-uid";    _attribute_user = NULL;
51    _attribute_group = "posix-gid";    _obligation_name = NULL;
52    _gridmapfile = "/home/aczid/workspace/grid-mw-security/ees/examples/example_gridmapfile.txt";    _attribute_group = NULL;
53    _gridmapdir = "/home/aczid/workspace/grid-mw-security/ees/examples/example_gridmapdir";    _gridmapfile = NULL;
54      _gridmapfile = strdup("/home/aczid/workspace/grid-mw-security/ees/examples/example_gridmapfile.txt");
55      _gridmapdir = NULL;
56      _gridmapdir = strdup("/home/aczid/workspace/grid-mw-security/ees/examples/example_gridmapdir");
57    _use_strings = 0;    _use_strings = 0;
58    _use_pool    = 0;    _use_pool    = 0;
59        
# Line 120  EES_PL_RC plugin_initialize(int argc, ch Line 112  EES_PL_RC plugin_initialize(int argc, ch
112      }      }
113    }    }
114    
115      printf("Set gridmapfile as string: %s\n", _gridmapfile);
116    
117      printf("Done parsing options. Returning\n");
118    
119      printf("Attribute user: %s\n", _attribute_user);
120      printf("Attribute group: %s\n", _attribute_group);
121      printf("Obligation name: %s\n", _obligation_name);
122    
123    /* save state to AOS */    /* save state to AOS */
124    set_var_as_string("user_attribute",  _attribute_user);    set_var_as_string("user_attribute",  _attribute_user);
125    set_var_as_string("group_attribute", _attribute_group);    set_var_as_string("group_attribute", _attribute_group);
# Line 128  EES_PL_RC plugin_initialize(int argc, ch Line 128  EES_PL_RC plugin_initialize(int argc, ch
128    set_var_as_string("gridmapdir",      _gridmapdir);    set_var_as_string("gridmapdir",      _gridmapdir);
129    set_var_as_string("mappingattr",     _mapping_attribute);    set_var_as_string("mappingattr",     _mapping_attribute);
130    
131      /*set_var_as_void_p("use_strings",     &_use_strings, sizeof(int));*/
132      /*set_var_as_void_p("use_pool",        &_use_pool, sizeof(int));*/
133    
134    /* hack to set int in void*/    /* hack to set int in void*/
135    /*if((_tmp_void = calloc(1, sizeof(int))) != NULL){*/    /*if((_tmp_void = calloc(1, sizeof(int))) != NULL){*/
136    /**((int*)_tmp_void) = _use_strings;*/    /**((int*)_tmp_void) = _use_strings;*/
   set_var_as_void_p("use_strings",     &_use_strings, sizeof(int));  
137    /*printf("Setting _use_strings: %i\n", _use_strings);*/    /*printf("Setting _use_strings: %i\n", _use_strings);*/
138    /*}*/    /*}*/
139    
# Line 139  EES_PL_RC plugin_initialize(int argc, ch Line 141  EES_PL_RC plugin_initialize(int argc, ch
141    /**((int*)_tmp_void) = _use_pool;*/    /**((int*)_tmp_void) = _use_pool;*/
142    /*set_var_as_void_p("use_pool",     _tmp_void, sizeof(int));*/    /*set_var_as_void_p("use_pool",     _tmp_void, sizeof(int));*/
143    /*}*/    /*}*/
144      /*printf("Saved use_strings as: %s\n", get_var_as_int("use_strings"));*/
145    
146    set_var_as_void_p("use_pool",     &_use_pool, sizeof(int));    /*free(_attribute_user);*/
147    printf("Got strings var as int: %i\n", get_var_as_int("use_strings"));    /*free(_attribute_group);*/
148    printf("Got pool var as int: %i\n", get_var_as_int("use_pool"));    /*free(_obligation_name);*/
149      /*free(_gridmapfile);*/
150      /*free(_gridmapdir);*/
151      /*free(_mapping_attribute);*/
152    
153    
154      /*aos_dump_argslist();*/
155    
156    return EES_PL_SUCCESS;    return EES_PL_SUCCESS;
157  }  }
158    
# Line 153  EES_PL_RC set_var_as_string(char* name, Line 161  EES_PL_RC set_var_as_string(char* name,
161    aos_attribute_t* attribute;    aos_attribute_t* attribute;
162    char*            attribute_name;    char*            attribute_name;
163    
   asprintf(&attribute_name, "%s_%s", name, EEF_getRunningPluginName());  
   
164    rewindContexts(NULL);    rewindContexts(NULL);
165    while(context = getNextContext(NONE, NULL)){    while((context = getNextContext(NONE, NULL))){
166        if(context){
167          break;
168        }
169    }      }  
170    if(context == NULL){    if(context == NULL){
171      context = createContext (NONE);      context = createContext (NONE);
# Line 168  EES_PL_RC set_var_as_string(char* name, Line 177  EES_PL_RC set_var_as_string(char* name,
177      return EES_PL_FAILURE;      return EES_PL_FAILURE;
178    }    }
179    
180      if(value == NULL){
181        EEF_log(LOG_ERR, "Value cannot be NULL\n");
182        return EES_PL_FAILURE;
183      }
184    
185    /* store attribute names in AOS for lookup during run */    /* store attribute names in AOS for lookup during run */
186    if((attribute = createAttribute())){    if((attribute = createAttribute())){
187      setAttributeId(   attribute, attribute_name);      if(asprintf(&attribute_name, "%s_%s", name, EEF_getRunningPluginName())){
188          setAttributeId(   attribute, attribute_name);
189          free(attribute_name);
190        }
191      setAttributeValue(attribute, value, strlen(value)+1);      setAttributeValue(attribute, value, strlen(value)+1);
192        free(value);
193      addAttribute(context, attribute);      addAttribute(context, attribute);
194    }    }
195    
196    return EES_PL_SUCCESS;    return EES_PL_SUCCESS;
197  }  }
198    
# Line 183  EES_PL_RC set_var_as_void_p(char* name, Line 202  EES_PL_RC set_var_as_void_p(char* name,
202    aos_attribute_t* attribute;    aos_attribute_t* attribute;
203    char*            attribute_name;    char*            attribute_name;
204    
   asprintf(&attribute_name, "%s_%s", name, EEF_getRunningPluginName());  
   
205    /* store attribute names in AOS for lookup during run */    /* store attribute names in AOS for lookup during run */
206    
207    rewindContexts(NULL);    rewindContexts(NULL);
208    while((context = getNextContext(NONE, NULL))){    while((context = getNextContext(NONE, NULL))){
209        printf("Looking for NONE context: %p\n", context);
210        if(context){
211          break;
212        }
213    }      }  
214    if(context == NULL){    if(context == NULL){
215      context = createContext (NONE);      context = createContext (NONE);
216      addContext (context);      addContext (context);
217    }      }
218    
219    if(context == NULL){    if(context == NULL){
220      EEF_log(LOG_ERR, "Unable to get context\n");      EEF_log(LOG_ERR, "Unable to get context\n");
# Line 201  EES_PL_RC set_var_as_void_p(char* name, Line 222  EES_PL_RC set_var_as_void_p(char* name,
222    }    }
223    
224    if((attribute = createAttribute())){    if((attribute = createAttribute())){
225      setAttributeId(   attribute, attribute_name);      if(asprintf(&attribute_name, "%s_%s", name, EEF_getRunningPluginName())){
226          setAttributeId(   attribute, attribute_name);
227          free(attribute_name);
228        }
229      setAttributeValue(attribute, value, size);      setAttributeValue(attribute, value, size);
230        free(value);
231      addAttribute(context, attribute);      addAttribute(context, attribute);
232    }    }
233      printf("Created attribute at %p\n", attribute);
234    return EES_PL_SUCCESS;    return EES_PL_SUCCESS;
235  }  }
236    
# Line 217  char* get_var_as_string(char* name){ Line 243  char* get_var_as_string(char* name){
243    
244    rewindContexts(NULL);    rewindContexts(NULL);
245    while((context = getNextContext(NONE, NULL))){    while((context = getNextContext(NONE, NULL))){
246        printf("Getting %s from %p\n", localname, context);
247      rewindAttributes(context);      rewindAttributes(context);
248      while((attribute = getNextAttribute(context))){      while((attribute = getNextAttribute(context))){
249        if(strcmp(getAttributeId(attribute), localname) == 0){        if(strcmp(getAttributeId(attribute), localname) == 0){
250            free(localname);
251          return getAttributeValueAsString(attribute);          return getAttributeValueAsString(attribute);
252        }        }
253      }      }
254    }    }
255      free(localname);
256    return NULL;    return NULL;
257  }  }
258    
# Line 232  int get_var_as_int(char* name){ Line 261  int get_var_as_int(char* name){
261    aos_context_t  * context;    aos_context_t  * context;
262    aos_attribute_t* attribute;    aos_attribute_t* attribute;
263    
264      /* TODO Free this */
265    asprintf(&localname, "%s_%s", name, EEF_getRunningPluginName());    asprintf(&localname, "%s_%s", name, EEF_getRunningPluginName());
266    
267    rewindContexts(NULL);    rewindContexts(NULL);
# Line 239  int get_var_as_int(char* name){ Line 269  int get_var_as_int(char* name){
269      rewindAttributes(context);      rewindAttributes(context);
270      while((attribute = getNextAttribute(context))){      while((attribute = getNextAttribute(context))){
271        if(strcmp(getAttributeId(attribute), localname) == 0){        if(strcmp(getAttributeId(attribute), localname) == 0){
272            free(localname);
273          return getAttributeValueAsInt(attribute);          return getAttributeValueAsInt(attribute);
274        }        }
275      }      }
276    }    }
277      free(localname);
278    return -1;    return -1;
279  }  }
280    
# Line 256  EES_PL_RC plugin_run(){ Line 288  EES_PL_RC plugin_run(){
288    aos_attribute_t  *_uid_attr       = NULL;    aos_attribute_t  *_uid_attr       = NULL;
289    aos_attribute_t  *_gid_attr       = NULL;    aos_attribute_t  *_gid_attr       = NULL;
290    
291    char             *_dn             = NULL;    char             *_cn             = NULL;
292    
293    char             *_uid_str        = NULL;    char             *_uid_str        = NULL;
294    char             *_gid_str        = NULL;    char             *_gid_str        = NULL;
# Line 273  EES_PL_RC plugin_run(){ Line 305  EES_PL_RC plugin_run(){
305    int               _use_strings    = 0;    int               _use_strings    = 0;
306    int               _use_pool       = 0;    int               _use_pool       = 0;
307    struct passwd     _tmp_pwd_s;    struct passwd     _tmp_pwd_s;
308      struct stat       _gridmapfile_stat;
309    
310    /*printf("Running %s\n", EEF_getRunningPluginName());*/    printf("Running %s\n", EEF_getRunningPluginName());
   
   /* fetch _dn (subject-x509-id) */  
   /*rewindContexts(NULL);*/  
   /*while((_context = getNextContext(SUBJECT, NULL))){*/  
   /*printf("Got context at %p\n", _context);*/  
   /*rewindAttributes(_context);*/  
   /*while((_tmp_attr = getNextAttribute(_context))){*/  
   /*printf("Got attribute %p\n", _tmp_attr);*/  
   /*if(strcmp(getAttributeId(_tmp_attr), _mapping_attribute) == 0){*/  
   /*_dn = getAttributeValueAsString(_tmp_attr);*/  
   /*}*/  
   /*printf("Still in attr loop\n");*/  
   /*}*/  
   /*printf("Still in context loop\n");*/  
   /*}*/  
   
   printf("Out of search\n");  
311    
312    /* populate fields */    /* populate fields */
313    _attribute_user    = get_var_as_string("user_attribute");    _attribute_user    = get_var_as_string("user_attribute");
# Line 302  EES_PL_RC plugin_run(){ Line 318  EES_PL_RC plugin_run(){
318    _mapping_attribute = get_var_as_string("mappingattr");    _mapping_attribute = get_var_as_string("mappingattr");
319    
320    _use_strings       = get_var_as_int("use_strings");    _use_strings       = get_var_as_int("use_strings");
321    printf("Use_strings: %i\n", _use_strings);    /*printf("Use_strings: %i\n", _use_strings);*/
322    _use_pool          = get_var_as_int("use_pool");    _use_pool          = get_var_as_int("use_pool");
323    printf("Use_pool: %i\n", _use_pool);    /*printf("Use_pool: %i\n", _use_pool);*/
324    
325    /* DEBUG - TODO: remove */  
326    _dn = "/O=dutchgrid/O=users/O=nikhef/CN=Aram Cornelis Zeno Verstegen";    /* fetch _cn (subject-x509-id) */
327      rewindContexts(NULL);
328      while((_context = getNextContext(SUBJECT, NULL))){
329        printf("Got context at %p\n", _context);
330        rewindAttributes(_context);
331        while((_tmp_attr = getNextAttribute(_context))){
332          printf("Got attribute %p\n", _tmp_attr);
333          if(strcmp(getAttributeId(_tmp_attr), _mapping_attribute) == 0){
334            _cn = getAttributeValueAsString(_tmp_attr);
335          }
336        }
337      }
338    
339    /* check if a DN was found */    /* check if a DN was found */
340    if(_dn == NULL){    if(_cn == NULL){
341      EEF_log(LOG_ERR, "%s: No CN found!\n", EEF_getRunningPluginName());      EEF_log(LOG_ERR, "%s: No CN found!\n", EEF_getRunningPluginName());
342      return EES_PL_FAILURE;      return EES_PL_FAILURE;
343    }    }
344    
345      printf("Checking gridmapfile\n");
346    /* TODO check if path to gridmapfile exists */    /* TODO check if path to gridmapfile exists */
347      if(stat("/etc/passwd", &_gridmapfile_stat) != 0){
348        EEF_log("Unable to stat gridmapfile (%s): %s\n", _gridmapfile, strerror(errno));
349      }
350    
351    
352    
353    printf("Gridmapfile: %s\n", _gridmapfile);    printf("Gridmapfile: %s\n", _gridmapfile);
354    /* look up DN in gridmapfile */    /* look up DN in gridmapfile */
355    parse_gridmapfile(_gridmapfile, &_mappings);    parse_gridmapfile(_gridmapfile, &_mappings);
356    _mapping_line = find_mapping(_mappings, _dn, MATCH_WILD_CHARS);    _mapping_line = find_mapping(_mappings, _cn, MATCH_WILD_CHARS);
   
357    
358    /* TODO check if path to gridmapdir exists */    /* TODO check if path to gridmapdir exists */
359    if (_mapping_line != NULL && _mapping_line->mappings != NULL && _mapping_line->mappings->value != NULL){    if (_mapping_line != NULL && _mapping_line->mappings != NULL && _mapping_line->mappings->value != NULL){
# Line 329  EES_PL_RC plugin_run(){ Line 362  EES_PL_RC plugin_run(){
362      gridmap_list_free(_mappings);      gridmap_list_free(_mappings);
363    } else {    } else {
364      gridmap_list_free(_mappings);      gridmap_list_free(_mappings);
365      EEF_log(LOG_ERR, "%s: Unable to open gridmapfile \"%s\": %s", EEF_getRunningPluginName(), _gridmapfile, strerror(errno));      EEF_log(LOG_ERR, "%s: Unable to find mapping for CN \"%s\" in gridmapfile \"%s\"", EEF_getRunningPluginName(), _cn, _gridmapfile);
366      goto end_failure;      goto end_failure;
367    }    }
368    
   /* fetch passwd struct */  
   _tmp_pwd_s = passwd_struct_for_user_name(_user_name);  
   
369    /* TODO add secondary GIDs */    /* TODO add secondary GIDs */
370    
371    if(_use_strings){    if(_use_strings){
372      _uid_str = username_from_passwd_struct(_tmp_pwd_s);      _uid_str = strdup(_user_name);
373      /*_gid_str = (_tmp_pwd_s);*/      free(_user_name);
     /* TODO set group name */  
374      printf("Username as string\n");      printf("Username as string\n");
375    } else {    } else {
376      asprintf(&_uid_str, "%llu", (long long unsigned int) uid_from_user_name(_user_name));      asprintf(&_uid_str, "%llu", (long long unsigned int) uid_from_user_name(_user_name));
377      printf("Username as uid\n");      printf("Username as uid\n");
378      /* TODO */      /* TODO */
379    }    }
380    
381    printf("Uid: %s\n", _uid_str);    printf("Uid: %s\n", _uid_str);
382    printf("Uid strlen: %i\n", strlen(_uid_str));    printf("Uid strlen: %i\n", strlen(_uid_str));
383    
   /*_gid_str = username_from_passwd_struct(_tmp_pwd_s);*/  
384    
385    /*printf("Adding obligations for uid %s and gid %s\n", _uid_str, _gid_str);*/    /*printf("Adding obligations for uid %s and gid %s\n", _uid_str, _gid_str);*/
386    
# Line 359  EES_PL_RC plugin_run(){ Line 388  EES_PL_RC plugin_run(){
388    printf("Mapping to group attribute %s\n", _attribute_group);    printf("Mapping to group attribute %s\n", _attribute_group);
389    
390    /* add obligation for new uid-gid */    /* add obligation for new uid-gid */
   if((_uid_attr = createAttribute())){  
     setAttributeId(   _uid_attr, _attribute_user);  
     setAttributeValue(_uid_attr, _uid_str, strlen(_uid_str)+1);  
   }  
   free(_uid_str);  
391    
392    printf("Set uid str\n");    printf("Set uid str\n");
393    
   if(_gid_str){  
     if((_gid_attr = createAttribute())){  
       setAttributeId(   _gid_attr, _attribute_group);  
       setAttributeValue(_gid_attr, _gid_str, strlen(_gid_str)+1);  
     }  
     free(_gid_str);  
   }  
   
394    if((_context = createContext(OBLIGATION)) != NULL){    if((_context = createContext(OBLIGATION)) != NULL){
395      setContextObligationId(_context, _obligation_name);      setContextObligationId(_context, _obligation_name);
396      addAttribute(_context, _uid_attr);      if((_uid_attr = createAttribute())){
397      addAttribute(_context, _gid_attr);        setAttributeId(   _uid_attr, _attribute_user);
398          setAttributeValue(_uid_attr, _uid_str, strlen(_uid_str)+1);
399          addAttribute(_context, _uid_attr);
400          free(_uid_str);
401        }
402    
403        if(_gid_str){
404          if((_gid_attr = createAttribute())){
405            setAttributeId(   _gid_attr, _attribute_group);
406            setAttributeValue(_gid_attr, _gid_str, strlen(_gid_str)+1);
407            addAttribute(_context, _gid_attr);
408          }
409          free(_gid_str);
410        }
411    
412      addContext(_context);      addContext(_context);
413      return EES_PL_SUCCESS;      return EES_PL_SUCCESS;
414    }    }
# Line 388  EES_PL_RC plugin_run(){ Line 418  EES_PL_RC plugin_run(){
418  }  }
419    
420  EES_PL_RC plugin_terminate(){  EES_PL_RC plugin_terminate(){
   aos_context_t* _context;  
   aos_attribute_t* _tmp_attr;  
   
   /*rewindContexts(NULL);*/  
   /*while((_context = getNextContext(ANY, NULL))){*/  
   /*rewindAttributes(_context);*/  
   /*while((_tmp_attr = getNextAttribute(_context))){*/  
   /*printf("Attr: %s\n", getAttributeId(_tmp_attr));*/  
   /*printf("\tVal: %s\n", getAttributeValueAsString(_tmp_attr));*/  
   /**//*printf("Destroying: %p\n", _tmp_attr);*/  
   /*destroyAttribute(_context, _tmp_attr);*/  
   /*}*/  
   /*}*/  
421    return EES_PL_SUCCESS;      return EES_PL_SUCCESS;  
422  }  }
   
 /* helper functions */  
   
 struct passwd passwd_struct_for_user_name(char* _user_name){  
   struct  passwd    _pw_entry;  
   struct  passwd   *_pw_entry_p     = &_pw_entry;  
   struct  passwd   *_tmp_pw_entry_p = NULL;  
   char              _pw_buffer[200];  
   size_t            _pw_size        = sizeof(_pw_buffer);  
   
   /* lookup uid for local account */  
   errno = getpwnam_r(_user_name, _pw_entry_p, _pw_buffer,  _pw_size, &_tmp_pw_entry_p);  
   if(_tmp_pw_entry_p == NULL){  
     if(errno == 0){  
       EEF_log(LOG_ERR, "%s: No user '%s' found", EEF_getRunningPluginName(), _user_name);  
     } else {  
       EEF_log(LOG_ERR, "%s: %s", EEF_getRunningPluginName(), strerror(errno));  
     }  
   }  
   endpwent();  
   
   print_passwd_entry(_pw_entry);  
   
   return _pw_entry;  
 }  
   
 /*struct group group_struct_for_group_name(char* _group_name){*/  
 /*struct  group     _gr_entry;*/  
 /*struct  group    *_gr_entry_p     = &_gr_entry;*/  
 /*struct  group    *_tmp_gr_entry_p = NULL;*/  
 /*char              _gr_buffer[200];*/  
 /*size_t            _gr_size        = sizeof(_gr_buffer);*/  
   
 /**//* lookup uid for local account */  
 /*errno = getgrent_r(_group_name, _pw_entry_p, _pw_buffer,  _pw_size, &_tmp_pw_entry_p);*/  
 /*if(_tmp_pw_entry_p == NULL){*/  
 /*if(errno == 0){*/  
 /*EEF_log(LOG_ERR, "%s: No user '%s' found", EEF_getRunningPluginName(), _group_name); */  
 /*} else {*/  
 /*EEF_log(LOG_ERR, "%s: %s", EEF_getRunningPluginName(), strerror(errno)); */  
 /*} */  
 /*}*/  
 /*endpwent();*/  
 /*free(_group_name);*/  
   
 /*print_passwd_entry(_pw_entry);*/  
   
 /*return _pw_entry;*/  
 /*}*/  
   
 struct passwd passwd_struct_for_uid(uid_t _uid){  
   struct  passwd    _pw_entry;  
   struct  passwd   *_pw_entry_p     = &_pw_entry;  
   struct  passwd   *_tmp_pw_entry_p = NULL;  
   char              _pw_buffer[200];  
   size_t            _pw_size        = sizeof(_pw_buffer);  
   
   /* lookup uid for local account */  
   errno = getpwuid_r(_uid, _pw_entry_p, _pw_buffer,  _pw_size, &_tmp_pw_entry_p);  
   if(_tmp_pw_entry_p == NULL){  
     if(errno == 0){  
       EEF_log(LOG_ERR, "%s: No user '%s' found", EEF_getRunningPluginName(), _uid);  
     } else {  
       EEF_log(LOG_ERR, "%s: %s", EEF_getRunningPluginName(), strerror(errno));  
     }  
   }  
   endpwent();  
   
   print_passwd_entry(_pw_entry);  
   
   return _pw_entry;  
 }  
   
 /*struct passwd passwd_struct_for_gid(gid_t _gid){*/  
 /*struct  passwd    _pw_entry;*/  
 /*struct  passwd   *_pw_entry_p     = &_pw_entry;*/  
 /*struct  passwd   *_tmp_pw_entry_p = NULL;*/  
 /*char              _pw_buffer[200];*/  
 /*size_t            _pw_size        = sizeof(_pw_buffer);*/  
   
 /**//* lookup uid for local account */  
 /*errno = getpwgid_r(_gid, _pw_entry_p, _pw_buffer,  _pw_size, &_tmp_pw_entry_p);*/  
 /*if(_tmp_pw_entry_p == NULL){*/  
 /*if(errno == 0){*/  
 /*EEF_log(LOG_ERR, "%s: No user '%s' found", EEF_getRunningPluginName(), _gid); */  
 /*} else {*/  
 /*EEF_log(LOG_ERR, "%s: %s", EEF_getRunningPluginName(), strerror(errno)); */  
 /*} */  
 /*}*/  
 /*endpwent();*/  
   
 /*print_passwd_entry(_pw_entry);*/  
   
 /*return _pw_entry;*/  
 /*}*/  
   
 char* username_from_passwd_struct(struct passwd _pw_entry){  
   char*  _uid_str     = "";  
   
   /*if(!_use_names){*/  
     _uid_str = strdup(_pw_entry.pw_name);  
     /*} else {*/  
     /*if(asprintf(&_uid_str, "%llu", (unsigned long long) _pw_entry.pw_uid) == -1){*/  
     /*return NULL; */  
     /*}*/  
     /*}*/  
   return _uid_str;  
 }  
   
 uid_t uid_from_user_name(char* _user_name){  
   struct passwd _pass;  
   uid_t         _uid;  
   _pass = passwd_struct_for_user_name(_user_name);  
   _uid =_pass.pw_uid;  
   endpwent();  
   return _uid;  
 }  
   
 /*gid_t gid_from_group_name(char* _group_name){*/  
 /*struct passwd _pass;*/  
 /*gid_t         _gid;*/  
 /*_pass = passwd_struct_for_group_name(_group_name);*/  
 /*_gid =_pass.pw_gid;*/  
 /*endpwent();*/  
 /*return _gid;*/  
 /*}*/  
   
 gid_t gid_from_uid(uid_t _uid){  
   struct passwd _pass;  
   gid_t         _gid;  
   _pass = passwd_struct_for_uid(_uid);  
   _gid =_pass.pw_gid;  
   endpwent();  
   return _gid;  
 }  
   
 gid_t gid_from_user_name(char* _user_name){  
   struct passwd _pass;  
   gid_t         _gid;  
   _pass = passwd_struct_for_user_name(_user_name);  
   _gid =_pass.pw_gid;  
   endpwent();  
   return _gid;  
 }  
   
 void print_passwd_entry(struct passwd _pw_entry){  
   EEF_log(LOG_DEBUG, "User name %s\n",   _pw_entry.pw_name  );  
   EEF_log(LOG_DEBUG, "Uid %i\n",         _pw_entry.pw_uid   );  
   EEF_log(LOG_DEBUG, "Gid %i\n",         _pw_entry.pw_gid   );  
   EEF_log(LOG_DEBUG, "Initial dir %s\n", _pw_entry.pw_dir   );  
   EEF_log(LOG_DEBUG, "Shell %s\n",       _pw_entry.pw_shell );  
   
   return;  
 }  

Legend:
Removed from v.1753  
changed lines
  Added in v.1754

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28