converts a username into uid:gid, * returns -1 on error & 0 on success */
| 74 | /* converts a username into uid:gid, |
| 75 | * returns -1 on error & 0 on success */ |
| 76 | int user2uid(int* uid, int* gid, char* user) |
| 77 | { |
| 78 | char* tmp; |
| 79 | struct passwd *pw_entry; |
| 80 | |
| 81 | if (user){ |
| 82 | *uid=strtol(user, &tmp, 10); |
| 83 | if ((tmp==0) ||(*tmp)){ |
| 84 | /* maybe it's a string */ |
| 85 | pw_entry=getpwnam(user); |
| 86 | if (pw_entry==0){ |
| 87 | goto error; |
| 88 | } |
| 89 | *uid=pw_entry->pw_uid; |
| 90 | if (gid) *gid=pw_entry->pw_gid; |
| 91 | } |
| 92 | return 0; |
| 93 | } |
| 94 | error: |
| 95 | return -1; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | int group2gid(int* gid, char* group) |
no outgoing calls
no test coverage detected