Skip to content
Snippets Groups Projects
Commit c30543cd authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

implement youruid and yourgid to avoid 66 dependency

parent 98b788b3
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,8 @@
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
#include <pwd.h>
#include <oblibs/error2.h>
#include <oblibs/environ.h>
......@@ -28,8 +30,6 @@
#include <skalibs/djbunix.h>
#include <execline/execline.h>
#include <66/environ.h>
#include <66/utils.h>
#define USAGE "execl-subuidgid [ -h ] [ -o owner ] prog..."
......@@ -47,6 +47,40 @@ static inline void info_help (void)
strerr_diefu1sys(111, "write to stdout") ;
}
/** Implement again this function coming from
* 66. This is avoid the dependency from it*/
static int youruid(uid_t *passto,char const *owner)
{
int e ;
e = errno ;
errno = 0 ;
struct passwd *st ;
if (!(st = getpwnam(owner)) || errno)
{
if (!errno) errno = EINVAL ;
return 0 ;
}
*passto = st->pw_uid ;
errno = e ;
return 1 ;
}
static int yourgid(gid_t *passto,uid_t owner)
{
int e ;
e = errno ;
errno = 0 ;
struct passwd *st ;
if (!(st = getpwuid(owner)) || errno)
{
if (!errno) errno = EINVAL ;
return 0 ;
}
*passto = st->pw_gid ;
errno = e ;
return 1 ;
}
int main (int argc, char const **argv, char const *const *envp)
{
uid_t uid ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment