pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Prototype uid2sid mapping, try #001
Posted by Anonymous on Wed 4th Oct 2023 09:20
raw | new post
view followups (newest first): msnfs41client: Prototype uid2sid mapping, try #001 by Anonymous

  1. diff --git a/daemon/acl.c b/daemon/acl.c
  2. index 3a86735..cb58f70 100644
  3. --- a/daemon/acl.c
  4. +++ b/daemon/acl.c
  5. @@ -22,6 +22,7 @@
  6.  #include <Windows.h>
  7.  #include <strsafe.h>
  8.  #include <sddl.h>
  9. +#include <ctype.h>
  10.  
  11.  #include "nfs41_ops.h"
  12.  #include "delegation.h"
  13. @@ -77,6 +78,34 @@ static int create_unknownsid(WELL_KNOWN_SID_TYPE type, PSID *sid,
  14.      return status;
  15.  }
  16.  
  17. +static
  18. +void allocate_SECURITY_SAMBA_UNIX_AUTHORITY(PSID *p_sid)
  19. +{
  20. +    // S-1-22-1-1
  21. +#define SECURITY_SAMBA_UNIX_AUTHORITY {0,0,0,0,0,22}
  22. +    SID_IDENTIFIER_AUTHORITY sid_id_auth = SECURITY_SAMBA_UNIX_AUTHORITY;
  23. +    PSID psid = 0;
  24. +    /*
  25. +     *
  26. +     * $ getent passwd Unix_User+0
  27. +     * Unix_User+0:*:4278190080:4278190080:U-Unix_User\0,S-1-22-1-0:/:/sbin/nologin
  28. +     *
  29. +     */
  30. +    // Create a new SID with the given ID authority and no sub-authorities
  31. +    if (!AllocateAndInitializeSid(&sid_id_auth, 2, 1, 0, 0, 0, 0, 0, 0, 0, &psid)) {
  32. +        dprintf(ACLLVL, "allocate_SECURITY_SAMBA_UNIX_AUTHORITY failed\n");
  33. +      
  34. +       PSID newsid = malloc(128);
  35. +       (void)CopySid(128, newsid, psid);
  36. +       *p_sid = newsid;
  37. +    }
  38. +    else
  39. +    {
  40. +        dprintf(ACLLVL, "allocate_SECURITY_SAMBA_UNIX_AUTHORITY success\n");
  41. +    }
  42. +}
  43. +
  44. +
  45.  static void convert_nfs4name_2_user_domain(LPSTR nfs4name,
  46.                                             LPSTR *domain)
  47.  {
  48. @@ -96,6 +125,34 @@ static int map_name_2_sid(DWORD *sid_len, PSID *sid, LPCSTR name)
  49.      SID_NAME_USE sid_type;
  50.      LPSTR tmp_buf = NULL;
  51.      DWORD tmp = 0;
  52. +    char modnamebuf[256];
  53. +    
  54. +    if (isdigit(name[0])) {
  55. +       unsigned long num = atol(name);
  56. +       switch (num) {
  57. +            case 1000:
  58. +           case 197608:
  59. +                dprintf(ACLLVL, "map_name_2_sid: remap %ld to 'roland_mainz'\n", num);
  60. +               name = "roland_mainz";
  61. +               break;
  62. +           default:
  63. +               allocate_SECURITY_SAMBA_UNIX_AUTHORITY(&(*sid));
  64. +
  65. +               (void)snprintf(modnamebuf, sizeof(modnamebuf), "S-1-22-1-%lu", num);
  66. +               SetLastError(0);
  67. +               if (ConvertStringSidToSidA(modnamebuf, *sid)) {
  68. +                    dprintf(ACLLVL, "map_name_2_sid: lookup Unix_User+%ld for '%s'=='%s' success\n",
  69. +                       num, name, modnamebuf);
  70. +                   return ERROR_SUCCESS;
  71. +               }
  72. +               status = GetLastError();
  73. +                dprintf(ACLLVL, "map_name_2_sid: lookup Unix_User+%ld for '%s'=='%s' returned %d\n",
  74. +                   num, name, modnamebuf, status);
  75. +               if (!status)
  76. +                    return status;
  77. +               name = modnamebuf;
  78. +       }
  79. +    }
  80.  
  81.      status = LookupAccountName(NULL, name, NULL, sid_len, NULL, &tmp, &sid_type);
  82.      dprintf(ACLLVL, "map_name_2_sid: LookupAccountName for %s returned %d "
  83. @@ -107,6 +164,10 @@ static int map_name_2_sid(DWORD *sid_len, PSID *sid, LPCSTR name)
  84.      status = GetLastError();
  85.      switch(status) {
  86.      case ERROR_INSUFFICIENT_BUFFER:
  87. +#if 1
  88. +       (*sid_len)+=128;
  89. +       tmp += 128;
  90. +#endif
  91.          *sid = malloc(*sid_len);
  92.          if (*sid == NULL) {
  93.              status = GetLastError();
  94. @@ -798,4 +859,4 @@ const nfs41_upcall_op nfs41_op_setacl = {
  95.      parse_setacl,
  96.      handle_setacl,
  97.      marshall_setacl
  98. -};
  99. \ No newline at end of file
  100. +};

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