sid2name.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <auth.h>
  12. #include <fcall.h>
  13. #include <thread.h>
  14. #include <9p.h>
  15. #include "cifs.h"
  16. struct { /* Well known security IDs */
  17. char *name;
  18. char *auth;
  19. char *rid;
  20. } known[] = {
  21. /* default local users */
  22. { "lu.dialup", "S-1-5-1", nil },
  23. { "lu.network", "S-1-5-2", nil },
  24. { "lu.batch", "S-1-5-3", nil },
  25. { "lu.interactive", "S-1-5-4", nil },
  26. { "lu.service", "S-1-5-6", nil },
  27. { "lu.anon", "S-1-5-7", nil },
  28. { "lu.DC", "S-1-5-8", nil },
  29. { "lu.enterprise-domain", "S-1-5-9", nil },
  30. { "lu.self", "S-1-5-10", nil },
  31. { "lu.authenticated", "S-1-5-11", nil },
  32. { "lu.restricted", "S-1-5-12", nil },
  33. { "lu.terminal-services", "S-1-5-13", nil },
  34. { "lu.remote-desktop", "S-1-5-14", nil },
  35. { "lu.local-system", "S-1-5-18", nil },
  36. { "lu.local-service", "S-1-5-19", nil },
  37. { "lu.network-service", "S-1-5-20", nil },
  38. { "lu.builtin", "S-1-5-32", nil },
  39. /* default local groups */
  40. { "lg.null", "S-1-0-0", nil },
  41. { "lg.world", "S-1-1-0", nil },
  42. { "lg.local", "S-1-2-0", nil },
  43. { "lg.creator-owner", "S-1-3-0", nil },
  44. { "lg.creator-group", "S-1-3-1", nil },
  45. { "lg.creator-owner-server", "S-1-3-2", nil },
  46. { "lg.creator-group-server", "S-1-3-3", nil },
  47. /* default domain users */
  48. { "du.admin", "S-1-5", "500" },
  49. { "du.guest", "S-1-5", "501" },
  50. { "du.kerberos", "S-1-5", "502" },
  51. /* default domain groups */
  52. { "dg.admins", "S-1-5-21", "512" },
  53. { "dg.users", "S-1-5-21", "513" },
  54. { "dg.guests", "S-1-5", "514" },
  55. { "dg.computers", "S-1-5", "515" },
  56. { "dg.controllers", "S-1-5", "516" },
  57. { "dg.cert-admins", "S-1-5", "517" },
  58. { "dg.schema-admins", "S-1-5", "518" },
  59. { "dg.enterprise-admins", "S-1-5", "519" },
  60. { "dg.group-policy-admins", "S-1-5", "520" },
  61. { "dg.remote-access", "S-1-5", "553" },
  62. /* default domain aliases */
  63. { "da.admins", "S-1-5", "544" },
  64. { "da.users", "S-1-5", "545" },
  65. { "da.guests", "S-1-5", "546" },
  66. { "da.power-users", "S-1-5", "547" },
  67. { "da.account-operators", "S-1-5", "548" },
  68. { "da.server-operators", "S-1-5", "549" },
  69. { "da.print-operators", "S-1-5", "550" },
  70. { "da.backup-operators", "S-1-5", "551" },
  71. { "da.replicator", "S-1-5", "552" },
  72. { "da.RAS-servers", "S-1-5", "553" },
  73. };
  74. static char *
  75. sid2name(char *sid)
  76. {
  77. int i;
  78. char *rid;
  79. if(sid == nil || (rid = strrchr(sid, '-')) == nil || *++rid == 0)
  80. return estrdup9p("-");
  81. for(i = 0; i < nelem(known); i++){
  82. if(strcmp(known[i].auth, sid) == 0 && known[i].rid == nil)
  83. return estrdup9p(known[i].name);
  84. if(strlen(known[i].auth) < strlen(sid) &&
  85. strncmp(known[i].auth, sid, strlen(known[i].auth)) == 0 &&
  86. known[i].rid && strcmp(known[i].rid, rid) == 0)
  87. return estrdup9p(known[i].name);
  88. }
  89. return estrdup9p(rid);
  90. }
  91. void
  92. upd_names(Session *s, Share *sp, char *path, Dir *d)
  93. {
  94. int fh, result;
  95. char *usid, *gsid;
  96. FInfo fi;
  97. if(d->uid)
  98. free(d->uid);
  99. if(d->gid)
  100. free(d->gid);
  101. if((fh = CIFS_NT_opencreate(s, sp, path, 0, 0, 0, READ_CONTROL,
  102. FILE_SHARE_ALL, FILE_OPEN, &result, &fi)) == -1){
  103. d->uid = estrdup9p("unknown");
  104. d->gid = estrdup9p("unknown");
  105. return;
  106. }
  107. usid = nil;
  108. gsid = nil;
  109. TNTquerysecurity(s, sp, fh, &usid, &gsid);
  110. d->uid = sid2name(usid);
  111. d->gid = sid2name(gsid);
  112. if(fh != -1)
  113. CIFSclose(s, sp, fh);
  114. }