feat(exec): cgo call to getpwnam and getgrnam
This commit is contained in:
@@ -2,14 +2,50 @@
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
/*
|
||||
#include<errno.h>
|
||||
#include<string.h>
|
||||
#include<sys/types.h>
|
||||
#include<pwd.h>
|
||||
#include<grp.h>
|
||||
|
||||
static uid_t getuid(const char* username) {
|
||||
struct passwd local, *rv;
|
||||
errno = 0;
|
||||
rv = getpwnam(username);
|
||||
if (errno != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(&local, rv, sizeof(struct passwd));
|
||||
return local.pw_uid;
|
||||
}
|
||||
static gid_t getgid(const char* groupname) {
|
||||
struct group local, *rv;
|
||||
errno = 0;
|
||||
rv = getgrnam(groupname);
|
||||
if (errno != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(&local, rv, sizeof(struct group));
|
||||
return local.gr_gid;
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
func getUid(user string) (uint64, error) {
|
||||
return 0, errors.New("not implemented")
|
||||
u, err := C.getuid(C.CString(user))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint64(u), nil
|
||||
}
|
||||
|
||||
func getGid(group string) (uint64, error) {
|
||||
return 0, errors.New("not implemented")
|
||||
g, err := C.getgid(C.CString(group))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint64(g), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user