Guest User

Untitled

a guest
May 26th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1.  
  2. /*-----------------------------------------------
  3. GetUid & GetGid
  4.  
  5. fs.getuid(username);
  6. * Returns the UID for a user given their name.
  7. * Wrapper for: getpwnam / pwd.h
  8.  
  9. fs.getgid(groupname);
  10. * Returns the UID for a user given their name.
  11. * Wrapper for: getgrgid / grp.h
  12.  
  13. -----------------------------------------------*/
  14. typedef struct eio_req_getid eio_req_getid;
  15. struct eio_req_getid {
  16. void *
  17. };
  18.  
  19. static char getbuf[1024];
  20.  
  21.  
  22. static int After_GetId (eio_req *req) {
  23. HandleScope scope;
  24.  
  25. }
  26.  
  27. /*-----------------------------------------------
  28. fs.getuid(username);
  29. -----------------------------------------------*/
  30. static Handle<Value> GetUid(const Arguments& args) {
  31. HandleScope scope;
  32.  
  33. if ( args.Length() < 1) {
  34. return THROW_BAD_ARGS;
  35. }
  36.  
  37. if (args[1]->IsFunction()) {
  38. // Handle with EIO_CUSTOM
  39. } else {
  40. Local<Value> uid;
  41. if (args[0]->IsInt32()) {
  42. uid = Integer::New(args[0]->Int32Value());
  43. } else {
  44. String::Utf8Value pwnam(args[0]->ToString());
  45. struct passwd pwd, *pwdp = NULL;
  46. int err;
  47.  
  48. if ((err = getpwnam_r(*pwnam, &pwd, getbuf, sizeof(getbuf), &pwdp)) ||
  49. pwdp == NULL) {
  50. return ThrowException(ErrnoException(errno, "getpwnam_r"));
  51. }
  52.  
  53. uid = Integer::New(pwdp->pw_uid);
  54. }
  55. return scope.Close(uid);
  56. }
  57. }
  58.  
  59. /*-----------------------------------------------
  60. fs.getgid(groupname);
  61. -----------------------------------------------*/
  62. static Handle<Value> GetGid(const Arguments& args) {
  63. HandleScope scope;
  64.  
  65. if ( args.Length() < 1) {
  66. return THROW_BAD_ARGS;
  67. }
  68.  
  69. if (args[1]->IsFunction()) {
  70. // Handle with EIO_CUSTOM
  71. } else {
  72. Local<Value> gid;
  73. if (args[0]->IsInt32()) {
  74. gid = Integer::New(args[0]->Int32Value());
  75. } else {
  76. String::Utf8Value grpnam(args[0]->ToString());
  77. struct group grp, *grpp = NULL;
  78. int err;
  79.  
  80. if ((err = getgrnam_r(*grpnam, &grp, getbuf, sizeof(getbuf), &grpp)) ||
  81. grpp == NULL) {
  82. return ThrowException(ErrnoException(errno, "getgrnam_r"));
  83. }
  84.  
  85. gid = Integer::New(grpp->gr_gid);
  86. }
  87. return scope.Close(gid);
  88. }
  89. }
Add Comment
Please, Sign In to add comment