pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


map_current_user_to_ids with |GetCurrentThreadToken()| info
Posted by Anonymous on Sat 24th Feb 2024 10:31
raw | new post
modification of post by Anonymous (view diff)

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