feat(exec): cgo call to getpwnam and getgrnam

This commit is contained in:
Suyono 2023-12-17 05:23:26 +00:00
parent 653b4ff158
commit 15a804aa7d
3 changed files with 44 additions and 7 deletions

View File

@ -18,7 +18,8 @@
"extensions": [
"golang.go",
"ms-azuretools.vscode-docker",
"ms-vscode.makefile-tools"
"ms-vscode.makefile-tools",
"ms-vscode.cpptools-extension-pack"
]
}
}

View File

@ -1,6 +1,6 @@
all: wingmate dummy oneshot spawner starter pidproxy
all: wingmate dummy oneshot spawner starter pidproxy exec
wingmate:
$(MAKE) -C cmd/wingmate all

View File

@ -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
}