/apps/net/samba-current/samba-sambagroups.patch

https://github.com/tenchman/TTLinux · Patch · 168 lines · 166 code · 2 blank · 0 comment · 0 complexity · 91d7aad98633a60a87ab6c9b6ac9d92c MD5 · raw file

  1. --- source/Makefile.in.sambagroups 2007-03-08 09:57:26.000000000 +0100
  2. +++ source/Makefile.in 2007-03-08 09:52:34.000000000 +0100
  3. @@ -735,7 +735,7 @@
  4. $(AFS_OBJ) $(AFS_SETTOKEN_OBJ) \
  5. $(LIBADS_SERVER_OBJ) $(SERVER_MUTEX_OBJ)
  6. -WBINFO_OBJ = nsswitch/wbinfo.o $(LIBSAMBA_OBJ) $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) \
  7. +WBINFO_OBJ = nsswitch/wbinfo.o nsswitch/sambagroups.o $(LIBSAMBA_OBJ) $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) \
  8. $(SECRETS_OBJ) $(POPT_LIB_OBJ) $(AFS_SETTOKEN_OBJ) $(RPC_PARSE_OBJ1) $(DOSERR_OBJ)
  9. WINBIND_NSS_OBJ = $(WBCOMMON_OBJ) lib/replace1.o @WINBIND_NSS_EXTRA_OBJS@
  10. --- source/nsswitch/wbinfo.c.sambagroups 2007-03-08 09:57:08.000000000 +0100
  11. +++ source/nsswitch/wbinfo.c 2007-03-08 09:23:24.000000000 +0100
  12. @@ -1149,6 +1149,7 @@ int main(int argc, char **argv)
  13. /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
  14. #endif
  15. { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL },
  16. + { "sambagroups", 'L', POPT_ARG_NONE, 0, 'L', "Listener for squid's group requests", NULL },
  17. POPT_COMMON_VERSION
  18. POPT_TABLEEND
  19. };
  20. @@ -1375,6 +1376,9 @@ int main(int argc, char **argv)
  21. goto done;
  22. }
  23. break;
  24. + case 'L':
  25. + sambagroups_listener();
  26. + break;
  27. case 'p':
  28. if (!wbinfo_ping()) {
  29. d_fprintf(stderr, "could not ping winbindd!\n");
  30. --- source/nsswitch/sambagroups.c.sambagroups 2007-03-08 09:51:44.000000000 +0100
  31. +++ source/nsswitch/sambagroups.c 2007-03-08 16:35:59.000000000 +0100
  32. @@ -0,0 +1,134 @@
  33. +#include <stdlib.h>
  34. +#include <fcntl.h>
  35. +#include <unistd.h>
  36. +#include <stdio.h>
  37. +#include <errno.h>
  38. +#include <ctype.h>
  39. +#include <string.h>
  40. +
  41. +#include <sys/file.h>
  42. +#include <sys/stat.h>
  43. +
  44. +#include "includes.h"
  45. +#include "winbindd.h"
  46. +
  47. +#define READSIZ 1024
  48. +
  49. +#define writec(__fd, __chr) write(__fd, __chr, strlen(__chr))
  50. +static int inputfd = 0;
  51. +static int outputfd = 1;
  52. +
  53. +char domainsep = '+';
  54. +
  55. +int sambagroups_lookup(char * user, char *group)
  56. +{
  57. + struct winbindd_request request;
  58. + struct winbindd_response response;
  59. + char *domain, *t;
  60. + int gid, i;
  61. +
  62. + /* Send off request */
  63. +
  64. + ZERO_STRUCT(request);
  65. + ZERO_STRUCT(response);
  66. +
  67. + if (!user) {
  68. + writec(outputfd, "ERROR: user missing\n");
  69. + return -1;
  70. + }
  71. + if (!group) {
  72. + writec(outputfd, "ERROR: group missing\n");
  73. + return -1;
  74. + }
  75. +
  76. + /* lookup group sid */
  77. + if ((t = strchr(user, domainsep))) {
  78. + domain = user;
  79. + *t = '\0';
  80. + fstrcpy(request.data.name.dom_name, domain);
  81. + *t = '+';
  82. + }
  83. +
  84. + fstrcpy(request.data.name.name, group);
  85. +
  86. +
  87. + if (winbindd_request_response(WINBINDD_LOOKUPNAME, &request, &response) !=
  88. + NSS_STATUS_SUCCESS) {
  89. + writec(outputfd, "ERROR: cannot lookup group sid\n");
  90. + return -1;
  91. + }
  92. +
  93. + ZERO_STRUCT(request);
  94. + fstrcpy(request.data.sid, response.data.sid.sid);
  95. + ZERO_STRUCT(response);
  96. +
  97. + if (winbindd_request_response(WINBINDD_SID_TO_GID, &request, &response) !=
  98. + NSS_STATUS_SUCCESS) {
  99. + writec(outputfd, "ERROR: cannot convert sid to gid\n");
  100. + return -1;
  101. + }
  102. +
  103. + gid = (int)response.data.gid;
  104. +
  105. +
  106. +
  107. + ZERO_STRUCT(request);
  108. + ZERO_STRUCT(response);
  109. +
  110. + /* do we need domain+user? */
  111. + fstrcpy(request.data.username, user);
  112. +
  113. + if (NSS_STATUS_SUCCESS != winbindd_request_response(WINBINDD_GETGROUPS, &request, &response)) {
  114. + writec(outputfd, "ERROR: cannot lookup user groups\n");
  115. + return -1;
  116. + }
  117. +
  118. + for (i = 0; i < response.data.num_entries; i++)
  119. + if (gid == (int)((gid_t *)response.extra_data.data)[i]) {
  120. + SAFE_FREE(response.extra_data.data);
  121. + return 0;
  122. + }
  123. +
  124. +
  125. + SAFE_FREE(response.extra_data.data);
  126. + return -1;
  127. +}
  128. +
  129. +int sambagroups_listener() {
  130. + char buf[READSIZ];
  131. + int rlen;
  132. + fd_set rfds;
  133. +
  134. +
  135. + while (1) {
  136. + FD_ZERO(&rfds);
  137. + FD_SET(inputfd, &rfds);
  138. +
  139. + if (-1 == select(inputfd + 1, &rfds, NULL, NULL, NULL))
  140. + continue;
  141. +
  142. + if (0 < (rlen = read(inputfd, buf, READSIZ-1))) {
  143. + char *user = NULL;
  144. + char *group = NULL;
  145. +
  146. + buf[rlen - 1] = '\0';
  147. +
  148. + user = buf;
  149. + if ((group = strchr(user, ' '))) {
  150. + *group = '\0';
  151. + group++;
  152. + }
  153. +
  154. + if (-1 == sambagroups_lookup(user, group))
  155. + writec(outputfd, "ERR\n");
  156. + else
  157. + writec(outputfd, "OK\n");
  158. + } else {
  159. + /* read error or emtpy read */
  160. + exit(23);
  161. + }
  162. +
  163. + }
  164. +
  165. +}
  166. +