pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


map_current_user_to_ids with |GetCurrentThreadToken()| info
Posted by Anonymous on Thu 22nd Feb 2024 17:53
raw | new post
view followups (newest first): map_current_user_to_ids with |GetCurrentThreadToken()| info by Anonymous

  1. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  2. index a7ce502..8807589 100644
  3. --- a/daemon/nfs41_daemon.c
  4. +++ b/daemon/nfs41_daemon.c
  5. @@ -73,6 +73,79 @@ static int map_current_user_to_ids(nfs41_idmapper *idmapper, uid_t *uid, gid_t *
  6.      DWORD len = UNLEN + 1;
  7.      int status = NO_ERROR;
  8.  
  9. +#if 1
  10. +    HANDLE currthrtoken = GetCurrentThreadToken();
  11. +    TOKEN_USER *tu = NULL;
  12. +    DWORD tulen = 0;
  13. +    TOKEN_PRIMARY_GROUP *tg = NULL;
  14. +    DWORD tglen = 0;
  15. +
  16. +    if (!GetTokenInformation(currthrtoken, TokenUser, NULL, 0, &tulen) && (GetLastError() != ERROR_INSUFFICIENT_BUFFER)) {
  17. +        eprintf("GetTokenInformation: TokenUser failed %d\n", (int)GetLastError());
  18. +        goto xdone;
  19. +    }
  20. +
  21. +    tu = (PTOKEN_USER)malloc(tulen);
  22. +    if (!tu) {
  23. +        eprintf("malloc(%d) PTOKEN_USER failed\n", (int)tulen);
  24. +        goto xdone;
  25. +    }
  26. +
  27. +    /* Get the token user information from the access token. */
  28. +    if (!GetTokenInformation(currthrtoken, TokenUser, tu, tulen, &tulen)) {
  29. +        eprintf("GetTokenInformation: TokenUser 2 failed %d\n", (int)GetLastError());
  30. +        goto xdone;
  31. +    }
  32. +
  33. +    /* get the account/domain name of the SID */
  34. +    char name[256];
  35. +    char domname[256];
  36. +    DWORD nlen = sizeof(name);
  37. +    DWORD dlen = sizeof(domname);
  38. +    SID_NAME_USE nameuse = 0;
  39. +    if (!LookupAccountSidA(NULL, tu->User.Sid, name, &nlen, domname, &dlen, (PSID_NAME_USE)&nameuse)) {
  40. +        eprintf("GetTokenInformation: user LookupAccountSidA failed %d\n", (int)GetLastError());
  41. +       goto xdone;
  42. +    }
  43. +
  44. +    DPRINTF(0, ("map_current_user_to_ids: name='%s'\n", name));
  45. +
  46. +    /*
  47. +     * group
  48. +     */
  49. +
  50. +    if (!GetTokenInformation(currthrtoken, TokenPrimaryGroup, NULL, 0, &tglen) && (GetLastError() != ERROR_INSUFFICIENT_BUFFER)) {
  51. +        eprintf("GetTokenInformation: TokenPrimaryGroup failed %d\n", (int)GetLastError());
  52. +        goto xdone;
  53. +    }
  54. +
  55. +    tg = (PTOKEN_PRIMARY_GROUP)malloc(tglen);
  56. +    if (!tg) {
  57. +        eprintf("malloc(%d) PTOKEN_PRIMARY_GROUP failed %d\n", tglen, (int)GetLastError());
  58. +        goto xdone;
  59. +    }
  60. +
  61. +    /* Get the token user information from the access token. */
  62. +    if (!GetTokenInformation(currthrtoken, TokenPrimaryGroup, tg, tglen, &tglen)) {
  63. +        eprintf("GetTokenInformation: TokenPrimaryGroup 2 failed %d\n", (int)GetLastError());
  64. +        goto xdone;
  65. +    }
  66. +
  67. +    /* get the account/domain name of the SID */
  68. +    nlen = sizeof(name);
  69. +    dlen = sizeof(domname);
  70. +    nameuse = 0;
  71. +    if (!LookupAccountSidA(NULL, tg->PrimaryGroup, name, &nlen, domname, &dlen, (PSID_NAME_USE)&nameuse)) {
  72. +        eprintf("GetTokenInformation: group LookupAccountSidA failed %d\n", (int)GetLastError());
  73. +       goto xdone;
  74. +    }
  75. +    DPRINTF(0, ("map_current_user_to_ids: group='%s'\n", name));
  76. +
  77. +xdone:
  78. +    free(tu);
  79. +    free(tg);
  80. +#endif
  81. +
  82.      if (!GetUserNameA(username, &len)) {
  83.          status = GetLastError();
  84.          eprintf("map_current_user_to_ids: GetUserName() failed with %d\n", status);

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at