feat(exec): cgo call to getpwnam and getgrnam
This commit is contained in:
parent
653b4ff158
commit
15a804aa7d
@ -18,7 +18,8 @@
|
|||||||
"extensions": [
|
"extensions": [
|
||||||
"golang.go",
|
"golang.go",
|
||||||
"ms-azuretools.vscode-docker",
|
"ms-azuretools.vscode-docker",
|
||||||
"ms-vscode.makefile-tools"
|
"ms-vscode.makefile-tools",
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
Makefile
2
Makefile
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
all: wingmate dummy oneshot spawner starter pidproxy
|
all: wingmate dummy oneshot spawner starter pidproxy exec
|
||||||
|
|
||||||
wingmate:
|
wingmate:
|
||||||
$(MAKE) -C cmd/wingmate all
|
$(MAKE) -C cmd/wingmate all
|
||||||
|
|||||||
@ -2,14 +2,50 @@
|
|||||||
|
|
||||||
package main
|
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) {
|
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) {
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user