Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-----------------------------------------------
- GetUid & GetGid
- fs.getuid(username);
- * Returns the UID for a user given their name.
- * Wrapper for: getpwnam / pwd.h
- fs.getgid(groupname);
- * Returns the UID for a user given their name.
- * Wrapper for: getgrgid / grp.h
- -----------------------------------------------*/
- typedef struct eio_req_getid eio_req_getid;
- struct eio_req_getid {
- void *
- };
- static char getbuf[1024];
- static int After_GetId (eio_req *req) {
- HandleScope scope;
- }
- /*-----------------------------------------------
- fs.getuid(username);
- -----------------------------------------------*/
- static Handle<Value> GetUid(const Arguments& args) {
- HandleScope scope;
- if ( args.Length() < 1) {
- return THROW_BAD_ARGS;
- }
- if (args[1]->IsFunction()) {
- // Handle with EIO_CUSTOM
- } else {
- Local<Value> uid;
- if (args[0]->IsInt32()) {
- uid = Integer::New(args[0]->Int32Value());
- } else {
- String::Utf8Value pwnam(args[0]->ToString());
- struct passwd pwd, *pwdp = NULL;
- int err;
- if ((err = getpwnam_r(*pwnam, &pwd, getbuf, sizeof(getbuf), &pwdp)) ||
- pwdp == NULL) {
- return ThrowException(ErrnoException(errno, "getpwnam_r"));
- }
- uid = Integer::New(pwdp->pw_uid);
- }
- return scope.Close(uid);
- }
- }
- /*-----------------------------------------------
- fs.getgid(groupname);
- -----------------------------------------------*/
- static Handle<Value> GetGid(const Arguments& args) {
- HandleScope scope;
- if ( args.Length() < 1) {
- return THROW_BAD_ARGS;
- }
- if (args[1]->IsFunction()) {
- // Handle with EIO_CUSTOM
- } else {
- Local<Value> gid;
- if (args[0]->IsInt32()) {
- gid = Integer::New(args[0]->Int32Value());
- } else {
- String::Utf8Value grpnam(args[0]->ToString());
- struct group grp, *grpp = NULL;
- int err;
- if ((err = getgrnam_r(*grpnam, &grp, getbuf, sizeof(getbuf), &grpp)) ||
- grpp == NULL) {
- return ThrowException(ErrnoException(errno, "getgrnam_r"));
- }
- gid = Integer::New(grpp->gr_gid);
- }
- return scope.Close(gid);
- }
- }
Add Comment
Please, Sign In to add comment