Advertisement
Guest User

Untitled

a guest
Mar 29th, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 146.22 KB | None | 0 0
  1. From d112c753cb88a370e8e9ad7d65a11b6f2bca4bce Mon Sep 17 00:00:00 2001
  2. From: Matthew Newton <mcn4@leicester.ac.uk>
  3. Date: Thu, 8 Jan 2015 15:11:15 +0000
  4. Subject: [PATCH 1/9] Make sure response->extra_data.data is always cleared out
  5.  
  6. Otherwise a bad read can sometimes cause the function to return -1 with
  7. an invalid pointer in extra_data.data, which is attempted to be freed
  8. by the caller (e.g. libwbclient/wbc_pam.c wbcAuthenticateUserEx())
  9. by calling winbindd_free_response().
  10.  
  11. Reviewed-by: Volker Lendecke <vl@samba.org>
  12. Reviewed-by: Jeremy Allison <jra@samba.org>
  13. ---
  14. nsswitch/wb_common.c | 13 +++++++------
  15. 1 file changed, 7 insertions(+), 6 deletions(-)
  16.  
  17. diff --git a/nsswitch/wb_common.c b/nsswitch/wb_common.c
  18. index 5fde8d0..df39f60 100644
  19. --- a/nsswitch/wb_common.c
  20. +++ b/nsswitch/wb_common.c
  21. @@ -514,6 +514,13 @@ static int winbindd_read_reply(struct winbindd_response *response)
  22.  
  23. result1 = winbind_read_sock(response,
  24. sizeof(struct winbindd_response));
  25. +
  26. + /* We actually send the pointer value of the extra_data field from
  27. + the server. This has no meaning in the client's address space
  28. + so we clear it out. */
  29. +
  30. + response->extra_data.data = NULL;
  31. +
  32. if (result1 == -1) {
  33. return -1;
  34. }
  35. @@ -522,12 +529,6 @@ static int winbindd_read_reply(struct winbindd_response *response)
  36. return -1;
  37. }
  38.  
  39. - /* We actually send the pointer value of the extra_data field from
  40. - the server. This has no meaning in the client's address space
  41. - so we clear it out. */
  42. -
  43. - response->extra_data.data = NULL;
  44. -
  45. /* Read variable length response */
  46.  
  47. if (response->length > sizeof(struct winbindd_response)) {
  48. --
  49. 2.1.4
  50.  
  51. From a82be8dbef4715f256b64a76a0db6d8f50cc4b4d Mon Sep 17 00:00:00 2001
  52. From: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  53. Date: Fri, 23 Jan 2015 22:35:50 +0000
  54. Subject: [PATCH 2/9] Make winbind client library thread-safe by adding context
  55.  
  56. Rather than keep state in global variables, store the current
  57. context such as the winbind file descriptor in a struct that is
  58. passed in. This makes the winbind client library thread-safe.
  59.  
  60. Signed-off-by: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  61. Reviewed-by: Volker Lendecke <vl@samba.org>
  62. Reviewed-by: Jeremy Allison <jra@samba.org>
  63. ---
  64. nsswitch/wb_common.c | 181 +++++++++++++++++++++++----------
  65. nsswitch/winbind_client.h | 23 +++--
  66. source4/torture/winbind/struct_based.c | 2 +-
  67. 3 files changed, 144 insertions(+), 62 deletions(-)
  68.  
  69. diff --git a/nsswitch/wb_common.c b/nsswitch/wb_common.c
  70. index df39f60..1149d08 100644
  71. --- a/nsswitch/wb_common.c
  72. +++ b/nsswitch/wb_common.c
  73. @@ -6,6 +6,7 @@
  74. Copyright (C) Tim Potter 2000
  75. Copyright (C) Andrew Tridgell 2000
  76. Copyright (C) Andrew Bartlett 2002
  77. + Copyright (C) Matthew Newton 2015
  78.  
  79.  
  80. This library is free software; you can redistribute it and/or
  81. @@ -28,10 +29,19 @@
  82. #include "system/select.h"
  83. #include "winbind_client.h"
  84.  
  85. -/* Global variables. These are effectively the client state information */
  86. +/* Global context */
  87.  
  88. -int winbindd_fd = -1; /* fd for winbindd socket */
  89. -static int is_privileged = 0;
  90. +struct winbindd_context {
  91. + int winbindd_fd; /* winbind file descriptor */
  92. + bool is_privileged; /* using the privileged socket? */
  93. + pid_t our_pid; /* calling process pid */
  94. +};
  95. +
  96. +static struct winbindd_context wb_global_ctx = {
  97. + .winbindd_fd = -1,
  98. + .is_privileged = 0,
  99. + .our_pid = 0
  100. +};
  101.  
  102. /* Free a response structure */
  103.  
  104. @@ -66,15 +76,26 @@ static void init_response(struct winbindd_response *response)
  105.  
  106. /* Close established socket */
  107.  
  108. +static void winbind_close_sock(struct winbindd_context *ctx)
  109. +{
  110. + if (!ctx) {
  111. + return;
  112. + }
  113. +
  114. + if (ctx->winbindd_fd != -1) {
  115. + close(ctx->winbindd_fd);
  116. + ctx->winbindd_fd = -1;
  117. + }
  118. +}
  119. +
  120. +/* Destructor for global context to ensure fd is closed */
  121. +
  122. #if HAVE_FUNCTION_ATTRIBUTE_DESTRUCTOR
  123. __attribute__((destructor))
  124. #endif
  125. -static void winbind_close_sock(void)
  126. +static void winbind_destructor(void)
  127. {
  128. - if (winbindd_fd != -1) {
  129. - close(winbindd_fd);
  130. - winbindd_fd = -1;
  131. - }
  132. + winbind_close_sock(&wb_global_ctx);
  133. }
  134.  
  135. #define CONNECT_TIMEOUT 30
  136. @@ -302,65 +323,76 @@ static const char *winbindd_socket_dir(void)
  137.  
  138. /* Connect to winbindd socket */
  139.  
  140. -static int winbind_open_pipe_sock(int recursing, int need_priv)
  141. +static int winbind_open_pipe_sock(struct winbindd_context *ctx,
  142. + int recursing, int need_priv)
  143. {
  144. #ifdef HAVE_UNIXSOCKET
  145. - static pid_t our_pid;
  146. struct winbindd_request request;
  147. struct winbindd_response response;
  148. +
  149. ZERO_STRUCT(request);
  150. ZERO_STRUCT(response);
  151.  
  152. - if (our_pid != getpid()) {
  153. - winbind_close_sock();
  154. - our_pid = getpid();
  155. + if (!ctx) {
  156. + return -1;
  157. }
  158.  
  159. - if ((need_priv != 0) && (is_privileged == 0)) {
  160. - winbind_close_sock();
  161. + if (ctx->our_pid != getpid()) {
  162. + winbind_close_sock(ctx);
  163. + ctx->our_pid = getpid();
  164. }
  165.  
  166. - if (winbindd_fd != -1) {
  167. - return winbindd_fd;
  168. + if ((need_priv != 0) && (ctx->is_privileged == 0)) {
  169. + winbind_close_sock(ctx);
  170. + }
  171. +
  172. + if (ctx->winbindd_fd != -1) {
  173. + return ctx->winbindd_fd;
  174. }
  175.  
  176. if (recursing) {
  177. return -1;
  178. }
  179.  
  180. - if ((winbindd_fd = winbind_named_pipe_sock(winbindd_socket_dir())) == -1) {
  181. + ctx->winbindd_fd = winbind_named_pipe_sock(winbindd_socket_dir());
  182. +
  183. + if (ctx->winbindd_fd == -1) {
  184. return -1;
  185. }
  186.  
  187. - is_privileged = 0;
  188. + ctx->is_privileged = 0;
  189.  
  190. /* version-check the socket */
  191.  
  192. request.wb_flags = WBFLAG_RECURSE;
  193. - if ((winbindd_request_response(WINBINDD_INTERFACE_VERSION, &request, &response) != NSS_STATUS_SUCCESS) || (response.data.interface_version != WINBIND_INTERFACE_VERSION)) {
  194. - winbind_close_sock();
  195. + if ((winbindd_request_response(ctx, WINBINDD_INTERFACE_VERSION, &request,
  196. + &response) != NSS_STATUS_SUCCESS) ||
  197. + (response.data.interface_version != WINBIND_INTERFACE_VERSION)) {
  198. + winbind_close_sock(ctx);
  199. return -1;
  200. }
  201.  
  202. /* try and get priv pipe */
  203.  
  204. request.wb_flags = WBFLAG_RECURSE;
  205. - if (winbindd_request_response(WINBINDD_PRIV_PIPE_DIR, &request, &response) == NSS_STATUS_SUCCESS) {
  206. + if (winbindd_request_response(ctx, WINBINDD_PRIV_PIPE_DIR, &request,
  207. + &response) == NSS_STATUS_SUCCESS) {
  208. int fd;
  209. - if ((fd = winbind_named_pipe_sock((char *)response.extra_data.data)) != -1) {
  210. - close(winbindd_fd);
  211. - winbindd_fd = fd;
  212. - is_privileged = 1;
  213. + fd = winbind_named_pipe_sock((char *)response.extra_data.data);
  214. + if (fd != -1) {
  215. + close(ctx->winbindd_fd);
  216. + ctx->winbindd_fd = fd;
  217. + ctx->is_privileged = 1;
  218. }
  219. }
  220.  
  221. - if ((need_priv != 0) && (is_privileged == 0)) {
  222. + if ((need_priv != 0) && (ctx->is_privileged == 0)) {
  223. return -1;
  224. }
  225.  
  226. SAFE_FREE(response.extra_data.data);
  227.  
  228. - return winbindd_fd;
  229. + return ctx->winbindd_fd;
  230. #else
  231. return -1;
  232. #endif /* HAVE_UNIXSOCKET */
  233. @@ -368,8 +400,8 @@ static int winbind_open_pipe_sock(int recursing, int need_priv)
  234.  
  235. /* Write data to winbindd socket */
  236.  
  237. -static int winbind_write_sock(void *buffer, int count, int recursing,
  238. - int need_priv)
  239. +static int winbind_write_sock(struct winbindd_context *ctx, void *buffer,
  240. + int count, int recursing, int need_priv)
  241. {
  242. int fd, result, nwritten;
  243.  
  244. @@ -377,7 +409,7 @@ static int winbind_write_sock(void *buffer, int count, int recursing,
  245.  
  246. restart:
  247.  
  248. - fd = winbind_open_pipe_sock(recursing, need_priv);
  249. + fd = winbind_open_pipe_sock(ctx, recursing, need_priv);
  250. if (fd == -1) {
  251. errno = ENOENT;
  252. return -1;
  253. @@ -399,7 +431,7 @@ static int winbind_write_sock(void *buffer, int count, int recursing,
  254.  
  255. ret = poll(&pfd, 1, -1);
  256. if (ret == -1) {
  257. - winbind_close_sock();
  258. + winbind_close_sock(ctx);
  259. return -1; /* poll error */
  260. }
  261.  
  262. @@ -409,7 +441,7 @@ static int winbind_write_sock(void *buffer, int count, int recursing,
  263.  
  264. /* Pipe has closed on remote end */
  265.  
  266. - winbind_close_sock();
  267. + winbind_close_sock(ctx);
  268. goto restart;
  269. }
  270.  
  271. @@ -422,7 +454,7 @@ static int winbind_write_sock(void *buffer, int count, int recursing,
  272.  
  273. /* Write failed */
  274.  
  275. - winbind_close_sock();
  276. + winbind_close_sock(ctx);
  277. return -1;
  278. }
  279.  
  280. @@ -434,13 +466,14 @@ static int winbind_write_sock(void *buffer, int count, int recursing,
  281.  
  282. /* Read data from winbindd socket */
  283.  
  284. -static int winbind_read_sock(void *buffer, int count)
  285. +static int winbind_read_sock(struct winbindd_context *ctx,
  286. + void *buffer, int count)
  287. {
  288. int fd;
  289. int nread = 0;
  290. int total_time = 0;
  291.  
  292. - fd = winbind_open_pipe_sock(false, false);
  293. + fd = winbind_open_pipe_sock(ctx, false, false);
  294. if (fd == -1) {
  295. return -1;
  296. }
  297. @@ -460,7 +493,7 @@ static int winbind_read_sock(void *buffer, int count)
  298.  
  299. ret = poll(&pfd, 1, 5000);
  300. if (ret == -1) {
  301. - winbind_close_sock();
  302. + winbind_close_sock(ctx);
  303. return -1; /* poll error */
  304. }
  305.  
  306. @@ -468,7 +501,7 @@ static int winbind_read_sock(void *buffer, int count)
  307. /* Not ready for read yet... */
  308. if (total_time >= 30) {
  309. /* Timeout */
  310. - winbind_close_sock();
  311. + winbind_close_sock(ctx);
  312. return -1;
  313. }
  314. total_time += 5;
  315. @@ -488,7 +521,7 @@ static int winbind_read_sock(void *buffer, int count)
  316. can do here is just return -1 and fail since the
  317. transaction has failed half way through. */
  318.  
  319. - winbind_close_sock();
  320. + winbind_close_sock(ctx);
  321. return -1;
  322. }
  323.  
  324. @@ -502,7 +535,8 @@ static int winbind_read_sock(void *buffer, int count)
  325.  
  326. /* Read reply */
  327.  
  328. -static int winbindd_read_reply(struct winbindd_response *response)
  329. +static int winbindd_read_reply(struct winbindd_context *ctx,
  330. + struct winbindd_response *response)
  331. {
  332. int result1, result2 = 0;
  333.  
  334. @@ -512,7 +546,7 @@ static int winbindd_read_reply(struct winbindd_response *response)
  335.  
  336. /* Read fixed length response */
  337.  
  338. - result1 = winbind_read_sock(response,
  339. + result1 = winbind_read_sock(ctx, response,
  340. sizeof(struct winbindd_response));
  341.  
  342. /* We actually send the pointer value of the extra_data field from
  343. @@ -541,7 +575,7 @@ static int winbindd_read_reply(struct winbindd_response *response)
  344. return -1;
  345. }
  346.  
  347. - result2 = winbind_read_sock(response->extra_data.data,
  348. + result2 = winbind_read_sock(ctx, response->extra_data.data,
  349. extra_data_len);
  350. if (result2 == -1) {
  351. winbindd_free_response(response);
  352. @@ -558,7 +592,8 @@ static int winbindd_read_reply(struct winbindd_response *response)
  353. * send simple types of requests
  354. */
  355.  
  356. -NSS_STATUS winbindd_send_request(int req_type, int need_priv,
  357. +NSS_STATUS winbindd_send_request(struct winbindd_context *ctx,
  358. + int req_type, int need_priv,
  359. struct winbindd_request *request)
  360. {
  361. struct winbindd_request lrequest;
  362. @@ -578,7 +613,7 @@ NSS_STATUS winbindd_send_request(int req_type, int need_priv,
  363.  
  364. winbindd_init_request(request, req_type);
  365.  
  366. - if (winbind_write_sock(request, sizeof(*request),
  367. + if (winbind_write_sock(ctx, request, sizeof(*request),
  368. request->wb_flags & WBFLAG_RECURSE,
  369. need_priv) == -1)
  370. {
  371. @@ -589,7 +624,7 @@ NSS_STATUS winbindd_send_request(int req_type, int need_priv,
  372. }
  373.  
  374. if ((request->extra_len != 0) &&
  375. - (winbind_write_sock(request->extra_data.data,
  376. + (winbind_write_sock(ctx, request->extra_data.data,
  377. request->extra_len,
  378. request->wb_flags & WBFLAG_RECURSE,
  379. need_priv) == -1))
  380. @@ -607,7 +642,8 @@ NSS_STATUS winbindd_send_request(int req_type, int need_priv,
  381. * Get results from winbindd request
  382. */
  383.  
  384. -NSS_STATUS winbindd_get_response(struct winbindd_response *response)
  385. +NSS_STATUS winbindd_get_response(struct winbindd_context *ctx,
  386. + struct winbindd_response *response)
  387. {
  388. struct winbindd_response lresponse;
  389.  
  390. @@ -619,7 +655,7 @@ NSS_STATUS winbindd_get_response(struct winbindd_response *response)
  391. init_response(response);
  392.  
  393. /* Wait for reply */
  394. - if (winbindd_read_reply(response) == -1) {
  395. + if (winbindd_read_reply(ctx, response) == -1) {
  396. /* Set ENOENT for consistency. Required by some apps */
  397. errno = ENOENT;
  398.  
  399. @@ -641,38 +677,73 @@ NSS_STATUS winbindd_get_response(struct winbindd_response *response)
  400.  
  401. /* Handle simple types of requests */
  402.  
  403. -NSS_STATUS winbindd_request_response(int req_type,
  404. - struct winbindd_request *request,
  405. - struct winbindd_response *response)
  406. +NSS_STATUS winbindd_request_response(struct winbindd_context *ctx,
  407. + int req_type,
  408. + struct winbindd_request *request,
  409. + struct winbindd_response *response)
  410. {
  411. NSS_STATUS status = NSS_STATUS_UNAVAIL;
  412. int count = 0;
  413. + struct winbindd_context *wb_ctx = ctx;
  414. +
  415. + if (ctx == NULL) {
  416. + wb_ctx = &wb_global_ctx;
  417. + }
  418.  
  419. while ((status == NSS_STATUS_UNAVAIL) && (count < 10)) {
  420. - status = winbindd_send_request(req_type, 0, request);
  421. + status = winbindd_send_request(wb_ctx, req_type, 0, request);
  422. if (status != NSS_STATUS_SUCCESS)
  423. return(status);
  424. - status = winbindd_get_response(response);
  425. + status = winbindd_get_response(wb_ctx, response);
  426. count += 1;
  427. }
  428.  
  429. return status;
  430. }
  431.  
  432. -NSS_STATUS winbindd_priv_request_response(int req_type,
  433. +NSS_STATUS winbindd_priv_request_response(struct winbindd_context *ctx,
  434. + int req_type,
  435. struct winbindd_request *request,
  436. struct winbindd_response *response)
  437. {
  438. NSS_STATUS status = NSS_STATUS_UNAVAIL;
  439. int count = 0;
  440. + struct winbindd_context *wb_ctx;
  441. +
  442. + if (ctx == NULL) {
  443. + wb_ctx = &wb_global_ctx;
  444. + }
  445.  
  446. while ((status == NSS_STATUS_UNAVAIL) && (count < 10)) {
  447. - status = winbindd_send_request(req_type, 1, request);
  448. + status = winbindd_send_request(wb_ctx, req_type, 1, request);
  449. if (status != NSS_STATUS_SUCCESS)
  450. return(status);
  451. - status = winbindd_get_response(response);
  452. + status = winbindd_get_response(wb_ctx, response);
  453. count += 1;
  454. }
  455.  
  456. return status;
  457. }
  458. +
  459. +/* Create and free winbindd context */
  460. +
  461. +struct winbindd_context *winbindd_ctx_create(void)
  462. +{
  463. + struct winbindd_context *ctx;
  464. +
  465. + ctx = calloc(1, sizeof(struct winbindd_context));
  466. +
  467. + if (!ctx) {
  468. + return NULL;
  469. + }
  470. +
  471. + ctx->winbindd_fd = -1;
  472. +
  473. + return ctx;
  474. +}
  475. +
  476. +void winbindd_ctx_free(struct winbindd_context *ctx)
  477. +{
  478. + winbind_close_sock(ctx);
  479. + free(ctx);
  480. +}
  481. diff --git a/nsswitch/winbind_client.h b/nsswitch/winbind_client.h
  482. index 905a189..d6b46fc 100644
  483. --- a/nsswitch/winbind_client.h
  484. +++ b/nsswitch/winbind_client.h
  485. @@ -6,6 +6,7 @@
  486. Copyright (C) Tim Potter 2000
  487. Copyright (C) Andrew Tridgell 2000
  488. Copyright (C) Andrew Bartlett 2002
  489. + Copyright (C) Matthew Newton 2015
  490.  
  491.  
  492. This library is free software; you can redistribute it and/or
  493. @@ -28,16 +29,26 @@
  494. #include "winbind_nss_config.h"
  495. #include "winbind_struct_protocol.h"
  496.  
  497. +struct winbindd_context;
  498. +
  499. +struct winbindd_context *winbindd_ctx_create(void);
  500. +void winbindd_ctx_free(struct winbindd_context *ctx);
  501. +
  502. void winbindd_free_response(struct winbindd_response *response);
  503. -NSS_STATUS winbindd_send_request(int req_type, int need_priv,
  504. +NSS_STATUS winbindd_send_request(struct winbindd_context *ctx,
  505. + int req_type, int need_priv,
  506. struct winbindd_request *request);
  507. -NSS_STATUS winbindd_get_response(struct winbindd_response *response);
  508. -NSS_STATUS winbindd_request_response(int req_type,
  509. - struct winbindd_request *request,
  510. - struct winbindd_response *response);
  511. -NSS_STATUS winbindd_priv_request_response(int req_type,
  512. +NSS_STATUS winbindd_get_response(struct winbindd_context *ctx,
  513. + struct winbindd_response *response);
  514. +NSS_STATUS winbindd_request_response(struct winbindd_context *ctx,
  515. + int req_type,
  516. + struct winbindd_request *request,
  517. + struct winbindd_response *response);
  518. +NSS_STATUS winbindd_priv_request_response(struct winbindd_context *ctx,
  519. + int req_type,
  520. struct winbindd_request *request,
  521. struct winbindd_response *response);
  522. +
  523. #define winbind_env_set() \
  524. (strcmp(getenv(WINBINDD_DONT_ENV)?getenv(WINBINDD_DONT_ENV):"0","1") == 0)
  525.  
  526. diff --git a/source4/torture/winbind/struct_based.c b/source4/torture/winbind/struct_based.c
  527. index 2bab940..4893cfc 100644
  528. --- a/source4/torture/winbind/struct_based.c
  529. +++ b/source4/torture/winbind/struct_based.c
  530. @@ -29,7 +29,7 @@
  531.  
  532. #define DO_STRUCT_REQ_REP_EXT(op,req,rep,expected,strict,warnaction,cmt) do { \
  533. NSS_STATUS __got, __expected = (expected); \
  534. - __got = winbindd_request_response(op, req, rep); \
  535. + __got = winbindd_request_response(NULL, op, req, rep); \
  536. if (__got != __expected) { \
  537. const char *__cmt = (cmt); \
  538. if (strict) { \
  539. --
  540. 2.1.4
  541.  
  542. From 9f9c7fa1c750ecda7e1fbb8b073977fe6604c1ac Mon Sep 17 00:00:00 2001
  543. From: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  544. Date: Fri, 23 Jan 2015 23:58:53 +0000
  545. Subject: [PATCH 3/9] Use global context for winbindd_request_response
  546.  
  547. Updating API call in libwbclient, wbinfo, ntlm_auth and
  548. winbind_nss_* as per previous commit to wb_common.c.
  549.  
  550. Signed-off-by: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  551. Reviewed-by: Volker Lendecke <vl@samba.org>
  552. Reviewed-by: Jeremy Allison <jra@samba.org>
  553. ---
  554. nsswitch/libwbclient/wbclient.c | 10 +++++----
  555. nsswitch/wbinfo.c | 4 ++--
  556. nsswitch/winbind_nss_aix.c | 30 ++++++++++++++++---------
  557. nsswitch/winbind_nss_linux.c | 49 +++++++++++++++++++++++++----------------
  558. nsswitch/winbind_nss_netbsd.c | 3 ++-
  559. nsswitch/winbind_nss_solaris.c | 9 +++++---
  560. source3/utils/ntlm_auth.c | 16 +++++++-------
  561. 7 files changed, 74 insertions(+), 47 deletions(-)
  562.  
  563. diff --git a/nsswitch/libwbclient/wbclient.c b/nsswitch/libwbclient/wbclient.c
  564. index 19bb3e9..93c0318e 100644
  565. --- a/nsswitch/libwbclient/wbclient.c
  566. +++ b/nsswitch/libwbclient/wbclient.c
  567. @@ -27,10 +27,12 @@
  568.  
  569. /* From wb_common.c */
  570.  
  571. -NSS_STATUS winbindd_request_response(int req_type,
  572. +NSS_STATUS winbindd_request_response(struct winbindd_context *wbctx,
  573. + int req_type,
  574. struct winbindd_request *request,
  575. struct winbindd_response *response);
  576. -NSS_STATUS winbindd_priv_request_response(int req_type,
  577. +NSS_STATUS winbindd_priv_request_response(struct winbindd_context *wbctx,
  578. + int req_type,
  579. struct winbindd_request *request,
  580. struct winbindd_response *response);
  581.  
  582. @@ -51,7 +53,7 @@ static wbcErr wbcRequestResponseInt(
  583. int cmd,
  584. struct winbindd_request *request,
  585. struct winbindd_response *response,
  586. - NSS_STATUS (*fn)(int req_type,
  587. + NSS_STATUS (*fn)(struct winbindd_context *wbctx, int req_type,
  588. struct winbindd_request *request,
  589. struct winbindd_response *response))
  590. {
  591. @@ -60,7 +62,7 @@ static wbcErr wbcRequestResponseInt(
  592.  
  593. /* for some calls the request and/or response can be NULL */
  594.  
  595. - nss_status = fn(cmd, request, response);
  596. + nss_status = fn(NULL, cmd, request, response);
  597.  
  598. switch (nss_status) {
  599. case NSS_STATUS_SUCCESS:
  600. diff --git a/nsswitch/wbinfo.c b/nsswitch/wbinfo.c
  601. index 0a5ec40..124eb13 100644
  602. --- a/nsswitch/wbinfo.c
  603. +++ b/nsswitch/wbinfo.c
  604. @@ -688,7 +688,7 @@ static bool wbinfo_getdcname(const char *domain_name)
  605.  
  606. /* Send request */
  607.  
  608. - if (winbindd_request_response(WINBINDD_GETDCNAME, &request,
  609. + if (winbindd_request_response(NULL, WINBINDD_GETDCNAME, &request,
  610. &response) != NSS_STATUS_SUCCESS) {
  611. d_fprintf(stderr, "Could not get dc name for %s\n",domain_name);
  612. return false;
  613. @@ -1894,7 +1894,7 @@ static bool wbinfo_klog(char *username)
  614.  
  615. request.flags |= WBFLAG_PAM_AFS_TOKEN;
  616.  
  617. - result = winbindd_request_response(WINBINDD_PAM_AUTH, &request,
  618. + result = winbindd_request_response(NULL, WINBINDD_PAM_AUTH, &request,
  619. &response);
  620.  
  621. /* Display response */
  622. diff --git a/nsswitch/winbind_nss_aix.c b/nsswitch/winbind_nss_aix.c
  623. index 66200f3..7a847b2 100644
  624. --- a/nsswitch/winbind_nss_aix.c
  625. +++ b/nsswitch/winbind_nss_aix.c
  626. @@ -279,7 +279,8 @@ static struct group *wb_aix_getgrgid(gid_t gid)
  627.  
  628. request.data.gid = gid;
  629.  
  630. - ret = winbindd_request_response(WINBINDD_GETGRGID, &request, &response);
  631. + ret = winbindd_request_response(NULL, WINBINDD_GETGRGID,
  632. + &request, &response);
  633.  
  634. logit("getgrgid ret=%d\n", ret);
  635.  
  636. @@ -311,7 +312,8 @@ static struct group *wb_aix_getgrnam(const char *name)
  637.  
  638. STRCPY_RETNULL(request.data.groupname, name);
  639.  
  640. - ret = winbindd_request_response(WINBINDD_GETGRNAM, &request, &response);
  641. + ret = winbindd_request_response(NULL, WINBINDD_GETGRNAM,
  642. + &request, &response);
  643.  
  644. HANDLE_ERRORS(ret);
  645.  
  646. @@ -370,7 +372,8 @@ static char *wb_aix_getgrset(char *user)
  647. free(r_user);
  648. }
  649.  
  650. - ret = winbindd_request_response(WINBINDD_GETGROUPS, &request, &response);
  651. + ret = winbindd_request_response(NULL, WINBINDD_GETGROUPS,
  652. + &request, &response);
  653.  
  654. HANDLE_ERRORS(ret);
  655.  
  656. @@ -409,7 +412,8 @@ static struct passwd *wb_aix_getpwuid(uid_t uid)
  657.  
  658. request.data.uid = uid;
  659.  
  660. - ret = winbindd_request_response(WINBINDD_GETPWUID, &request, &response);
  661. + ret = winbindd_request_response(NULL, WINBINDD_GETPWUID,
  662. + &request, &response);
  663.  
  664. HANDLE_ERRORS(ret);
  665.  
  666. @@ -442,7 +446,8 @@ static struct passwd *wb_aix_getpwnam(const char *name)
  667.  
  668. STRCPY_RETNULL(request.data.username, name);
  669.  
  670. - ret = winbindd_request_response(WINBINDD_GETPWNAM, &request, &response);
  671. + ret = winbindd_request_response(NULL, WINBINDD_GETPWNAM,
  672. + &request, &response);
  673.  
  674. HANDLE_ERRORS(ret);
  675.  
  676. @@ -475,7 +480,8 @@ static int wb_aix_lsuser(char *attributes[], attrval_t results[], int size)
  677. ZERO_STRUCT(request);
  678. ZERO_STRUCT(response);
  679.  
  680. - ret = winbindd_request_response(WINBINDD_LIST_USERS, &request, &response);
  681. + ret = winbindd_request_response(NULL, WINBINDD_LIST_USERS,
  682. + &request, &response);
  683. if (ret != 0) {
  684. errno = EINVAL;
  685. return -1;
  686. @@ -523,7 +529,8 @@ static int wb_aix_lsgroup(char *attributes[], attrval_t results[], int size)
  687. ZERO_STRUCT(request);
  688. ZERO_STRUCT(response);
  689.  
  690. - ret = winbindd_request_response(WINBINDD_LIST_GROUPS, &request, &response);
  691. + ret = winbindd_request_response(NULL, WINBINDD_LIST_GROUPS,
  692. + &request, &response);
  693. if (ret != 0) {
  694. errno = EINVAL;
  695. return -1;
  696. @@ -602,7 +609,8 @@ static attrval_t pwd_to_sid(struct passwd *pwd)
  697.  
  698. request.data.uid = pwd->pw_uid;
  699.  
  700. - if (winbindd_request_response(WINBINDD_UID_TO_SID, &request, &response) !=
  701. + if (winbindd_request_response(NULL, WINBINDD_UID_TO_SID,
  702. + &request, &response) !=
  703. NSS_STATUS_SUCCESS) {
  704. r.attr_flag = ENOENT;
  705. } else {
  706. @@ -888,7 +896,8 @@ static int wb_aix_authenticate(char *user, char *pass,
  707. free(r_user);
  708. }
  709.  
  710. - result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
  711. + result = winbindd_request_response(NULL, WINBINDD_PAM_AUTH,
  712. + &request, &response);
  713.  
  714. winbindd_free_response(&response);
  715.  
  716. @@ -937,7 +946,8 @@ static int wb_aix_chpass(char *user, char *oldpass, char *newpass, char **messag
  717. free(r_user);
  718. }
  719.  
  720. - result = winbindd_request_response(WINBINDD_PAM_CHAUTHTOK, &request, &response);
  721. + result = winbindd_request_response(NULL, WINBINDD_PAM_CHAUTHTOK,
  722. + &request, &response);
  723.  
  724. winbindd_free_response(&response);
  725.  
  726. diff --git a/nsswitch/winbind_nss_linux.c b/nsswitch/winbind_nss_linux.c
  727. index 70ede3e..58020e3 100644
  728. --- a/nsswitch/winbind_nss_linux.c
  729. +++ b/nsswitch/winbind_nss_linux.c
  730. @@ -401,7 +401,7 @@ _nss_winbind_setpwent(void)
  731. winbindd_free_response(&getpwent_response);
  732. }
  733.  
  734. - ret = winbindd_request_response(WINBINDD_SETPWENT, NULL, NULL);
  735. + ret = winbindd_request_response(NULL, WINBINDD_SETPWENT, NULL, NULL);
  736. #ifdef DEBUG_NSS
  737. fprintf(stderr, "[%5d]: setpwent returns %s (%d)\n", getpid(),
  738. nss_err_str(ret), ret);
  739. @@ -432,7 +432,7 @@ _nss_winbind_endpwent(void)
  740. winbindd_free_response(&getpwent_response);
  741. }
  742.  
  743. - ret = winbindd_request_response(WINBINDD_ENDPWENT, NULL, NULL);
  744. + ret = winbindd_request_response(NULL, WINBINDD_ENDPWENT, NULL, NULL);
  745. #ifdef DEBUG_NSS
  746. fprintf(stderr, "[%5d]: endpwent returns %s (%d)\n", getpid(),
  747. nss_err_str(ret), ret);
  748. @@ -481,7 +481,7 @@ _nss_winbind_getpwent_r(struct passwd *result, char *buffer,
  749.  
  750. request.data.num_entries = MAX_GETPWENT_USERS;
  751.  
  752. - ret = winbindd_request_response(WINBINDD_GETPWENT, &request,
  753. + ret = winbindd_request_response(NULL, WINBINDD_GETPWENT, &request,
  754. &getpwent_response);
  755.  
  756. if (ret == NSS_STATUS_SUCCESS) {
  757. @@ -569,7 +569,7 @@ _nss_winbind_getpwuid_r(uid_t uid, struct passwd *result, char *buffer,
  758.  
  759. request.data.uid = uid;
  760.  
  761. - ret = winbindd_request_response(WINBINDD_GETPWUID, &request, &response);
  762. + ret = winbindd_request_response(NULL, WINBINDD_GETPWUID, &request, &response);
  763.  
  764. if (ret == NSS_STATUS_SUCCESS) {
  765. ret = fill_pwent(result, &response.data.pw,
  766. @@ -645,7 +645,7 @@ _nss_winbind_getpwnam_r(const char *name, struct passwd *result, char *buffer,
  767. request.data.username
  768. [sizeof(request.data.username) - 1] = '\0';
  769.  
  770. - ret = winbindd_request_response(WINBINDD_GETPWNAM, &request, &response);
  771. + ret = winbindd_request_response(NULL, WINBINDD_GETPWNAM, &request, &response);
  772.  
  773. if (ret == NSS_STATUS_SUCCESS) {
  774. ret = fill_pwent(result, &response.data.pw, &buffer,
  775. @@ -716,7 +716,7 @@ _nss_winbind_setgrent(void)
  776. winbindd_free_response(&getgrent_response);
  777. }
  778.  
  779. - ret = winbindd_request_response(WINBINDD_SETGRENT, NULL, NULL);
  780. + ret = winbindd_request_response(NULL, WINBINDD_SETGRENT, NULL, NULL);
  781. #ifdef DEBUG_NSS
  782. fprintf(stderr, "[%5d]: setgrent returns %s (%d)\n", getpid(),
  783. nss_err_str(ret), ret);
  784. @@ -748,7 +748,7 @@ _nss_winbind_endgrent(void)
  785. winbindd_free_response(&getgrent_response);
  786. }
  787.  
  788. - ret = winbindd_request_response(WINBINDD_ENDGRENT, NULL, NULL);
  789. + ret = winbindd_request_response(NULL, WINBINDD_ENDGRENT, NULL, NULL);
  790. #ifdef DEBUG_NSS
  791. fprintf(stderr, "[%5d]: endgrent returns %s (%d)\n", getpid(),
  792. nss_err_str(ret), ret);
  793. @@ -799,7 +799,7 @@ winbind_getgrent(enum winbindd_cmd cmd,
  794.  
  795. request.data.num_entries = MAX_GETGRENT_USERS;
  796.  
  797. - ret = winbindd_request_response(cmd, &request,
  798. + ret = winbindd_request_response(NULL, cmd, &request,
  799. &getgrent_response);
  800.  
  801. if (ret == NSS_STATUS_SUCCESS) {
  802. @@ -918,7 +918,8 @@ _nss_winbind_getgrnam_r(const char *name,
  803. request.data.groupname
  804. [sizeof(request.data.groupname) - 1] = '\0';
  805.  
  806. - ret = winbindd_request_response(WINBINDD_GETGRNAM, &request, &response);
  807. + ret = winbindd_request_response(NULL, WINBINDD_GETGRNAM,
  808. + &request, &response);
  809.  
  810. if (ret == NSS_STATUS_SUCCESS) {
  811. ret = fill_grent(result, &response.data.gr,
  812. @@ -996,7 +997,8 @@ _nss_winbind_getgrgid_r(gid_t gid,
  813.  
  814. request.data.gid = gid;
  815.  
  816. - ret = winbindd_request_response(WINBINDD_GETGRGID, &request, &response);
  817. + ret = winbindd_request_response(NULL, WINBINDD_GETGRGID,
  818. + &request, &response);
  819.  
  820. if (ret == NSS_STATUS_SUCCESS) {
  821.  
  822. @@ -1069,7 +1071,8 @@ _nss_winbind_initgroups_dyn(char *user, gid_t group, long int *start,
  823. strncpy(request.data.username, user,
  824. sizeof(request.data.username) - 1);
  825.  
  826. - ret = winbindd_request_response(WINBINDD_GETGROUPS, &request, &response);
  827. + ret = winbindd_request_response(NULL, WINBINDD_GETGROUPS,
  828. + &request, &response);
  829.  
  830. if (ret == NSS_STATUS_SUCCESS) {
  831. int num_gids = response.data.num_entries;
  832. @@ -1181,7 +1184,8 @@ _nss_winbind_getusersids(const char *user_sid, char **group_sids,
  833. strncpy(request.data.sid, user_sid,sizeof(request.data.sid) - 1);
  834. request.data.sid[sizeof(request.data.sid) - 1] = '\0';
  835.  
  836. - ret = winbindd_request_response(WINBINDD_GETUSERSIDS, &request, &response);
  837. + ret = winbindd_request_response(NULL, WINBINDD_GETUSERSIDS,
  838. + &request, &response);
  839.  
  840. if (ret != NSS_STATUS_SUCCESS) {
  841. goto done;
  842. @@ -1233,7 +1237,8 @@ _nss_winbind_nametosid(const char *name, char **sid, char *buffer,
  843. sizeof(request.data.name.name) - 1);
  844. request.data.name.name[sizeof(request.data.name.name) - 1] = '\0';
  845.  
  846. - ret = winbindd_request_response(WINBINDD_LOOKUPNAME, &request, &response);
  847. + ret = winbindd_request_response(NULL, WINBINDD_LOOKUPNAME,
  848. + &request, &response);
  849. if (ret != NSS_STATUS_SUCCESS) {
  850. *errnop = errno = EINVAL;
  851. goto failed;
  852. @@ -1283,7 +1288,8 @@ _nss_winbind_sidtoname(const char *sid, char **name, char *buffer,
  853.  
  854. /* we need to fetch the separator first time through */
  855. if (!sep_char) {
  856. - ret = winbindd_request_response(WINBINDD_INFO, &request, &response);
  857. + ret = winbindd_request_response(NULL, WINBINDD_INFO,
  858. + &request, &response);
  859. if (ret != NSS_STATUS_SUCCESS) {
  860. *errnop = errno = EINVAL;
  861. goto failed;
  862. @@ -1298,7 +1304,8 @@ _nss_winbind_sidtoname(const char *sid, char **name, char *buffer,
  863. sizeof(request.data.sid) - 1);
  864. request.data.sid[sizeof(request.data.sid) - 1] = '\0';
  865.  
  866. - ret = winbindd_request_response(WINBINDD_LOOKUPSID, &request, &response);
  867. + ret = winbindd_request_response(NULL, WINBINDD_LOOKUPSID,
  868. + &request, &response);
  869. if (ret != NSS_STATUS_SUCCESS) {
  870. *errnop = errno = EINVAL;
  871. goto failed;
  872. @@ -1354,7 +1361,8 @@ _nss_winbind_sidtouid(const char *sid, uid_t *uid, int *errnop)
  873. strncpy(request.data.sid, sid, sizeof(request.data.sid) - 1);
  874. request.data.sid[sizeof(request.data.sid) - 1] = '\0';
  875.  
  876. - ret = winbindd_request_response(WINBINDD_SID_TO_UID, &request, &response);
  877. + ret = winbindd_request_response(NULL, WINBINDD_SID_TO_UID,
  878. + &request, &response);
  879. if (ret != NSS_STATUS_SUCCESS) {
  880. *errnop = errno = EINVAL;
  881. goto failed;
  882. @@ -1393,7 +1401,8 @@ _nss_winbind_sidtogid(const char *sid, gid_t *gid, int *errnop)
  883. strncpy(request.data.sid, sid, sizeof(request.data.sid) - 1);
  884. request.data.sid[sizeof(request.data.sid) - 1] = '\0';
  885.  
  886. - ret = winbindd_request_response(WINBINDD_SID_TO_GID, &request, &response);
  887. + ret = winbindd_request_response(NULL, WINBINDD_SID_TO_GID,
  888. + &request, &response);
  889. if (ret != NSS_STATUS_SUCCESS) {
  890. *errnop = errno = EINVAL;
  891. goto failed;
  892. @@ -1432,7 +1441,8 @@ _nss_winbind_uidtosid(uid_t uid, char **sid, char *buffer,
  893.  
  894. request.data.uid = uid;
  895.  
  896. - ret = winbindd_request_response(WINBINDD_UID_TO_SID, &request, &response);
  897. + ret = winbindd_request_response(NULL, WINBINDD_UID_TO_SID,
  898. + &request, &response);
  899. if (ret != NSS_STATUS_SUCCESS) {
  900. *errnop = errno = EINVAL;
  901. goto failed;
  902. @@ -1480,7 +1490,8 @@ _nss_winbind_gidtosid(gid_t gid, char **sid, char *buffer,
  903.  
  904. request.data.gid = gid;
  905.  
  906. - ret = winbindd_request_response(WINBINDD_GID_TO_SID, &request, &response);
  907. + ret = winbindd_request_response(NULL, WINBINDD_GID_TO_SID,
  908. + &request, &response);
  909. if (ret != NSS_STATUS_SUCCESS) {
  910. *errnop = errno = EINVAL;
  911. goto failed;
  912. diff --git a/nsswitch/winbind_nss_netbsd.c b/nsswitch/winbind_nss_netbsd.c
  913. index f673806..eb843ee 100644
  914. --- a/nsswitch/winbind_nss_netbsd.c
  915. +++ b/nsswitch/winbind_nss_netbsd.c
  916. @@ -228,7 +228,8 @@ netbsdwinbind_getgroupmembership(void *nsrv, void *nscb, va_list ap)
  917. ZERO_STRUCT(response);
  918. strncpy(request.data.username, uname,
  919. sizeof(request.data.username) - 1);
  920. - i = winbindd_request_response(WINBINDD_GETGROUPS, &request, &response);
  921. + i = winbindd_request_response(NULL, WINBINDD_GETGROUPS,
  922. + &request, &response);
  923. if (i != NSS_STATUS_SUCCESS)
  924. return NS_NOTFOUND;
  925. wblistv = (gid_t *)response.extra_data.data;
  926. diff --git a/nsswitch/winbind_nss_solaris.c b/nsswitch/winbind_nss_solaris.c
  927. index 6d3c8a9..1d0ac90 100644
  928. --- a/nsswitch/winbind_nss_solaris.c
  929. +++ b/nsswitch/winbind_nss_solaris.c
  930. @@ -515,7 +515,8 @@ _nss_winbind_ipnodes_getbyname(nss_backend_t* be, void *args)
  931. strncpy(request.data.winsreq, argp->key.name, sizeof(request.data.winsreq) - 1);
  932. request.data.winsreq[sizeof(request.data.winsreq) - 1] = '\0';
  933.  
  934. - if( (ret = winbindd_request_response(WINBINDD_WINS_BYNAME, &request, &response))
  935. + if( (ret = winbindd_request_response(NULL, WINBINDD_WINS_BYNAME,
  936. + &request, &response))
  937. == NSS_STATUS_SUCCESS ) {
  938. ret = parse_response(af, argp, &response);
  939. }
  940. @@ -538,7 +539,8 @@ _nss_winbind_hosts_getbyname(nss_backend_t* be, void *args)
  941. strncpy(request.data.winsreq, argp->key.name, sizeof(request.data.winsreq) - 1);
  942. request.data.winsreq[sizeof(request.data.winsreq) - 1] = '\0';
  943.  
  944. - if( (ret = winbindd_request_response(WINBINDD_WINS_BYNAME, &request, &response))
  945. + if( (ret = winbindd_request_response(NULL, WINBINDD_WINS_BYNAME,
  946. + &request, &response))
  947. == NSS_STATUS_SUCCESS ) {
  948. ret = parse_response(AF_INET, argp, &response);
  949. }
  950. @@ -577,7 +579,8 @@ _nss_winbind_hosts_getbyaddr(nss_backend_t* be, void *args)
  951. ((unsigned char *)argp->key.hostaddr.addr)[3]);
  952. #endif
  953.  
  954. - ret = winbindd_request_response(WINBINDD_WINS_BYIP, &request, &response);
  955. + ret = winbindd_request_response(NULL, WINBINDD_WINS_BYIP,
  956. + &request, &response);
  957.  
  958. if( ret == NSS_STATUS_SUCCESS) {
  959. parse_response(argp->key.hostaddr.type, argp, &response);
  960. diff --git a/source3/utils/ntlm_auth.c b/source3/utils/ntlm_auth.c
  961. index b3bbaa4..ee9c82d 100644
  962. --- a/source3/utils/ntlm_auth.c
  963. +++ b/source3/utils/ntlm_auth.c
  964. @@ -269,7 +269,7 @@ static char winbind_separator(void)
  965.  
  966. /* Send off request */
  967.  
  968. - if (winbindd_request_response(WINBINDD_INFO, NULL, &response) !=
  969. + if (winbindd_request_response(NULL, WINBINDD_INFO, NULL, &response) !=
  970. NSS_STATUS_SUCCESS) {
  971. d_printf("could not obtain winbind separator!\n");
  972. return *lp_winbind_separator();
  973. @@ -299,7 +299,7 @@ const char *get_winbind_domain(void)
  974.  
  975. /* Send off request */
  976.  
  977. - if (winbindd_request_response(WINBINDD_DOMAIN_NAME, NULL, &response) !=
  978. + if (winbindd_request_response(NULL, WINBINDD_DOMAIN_NAME, NULL, &response) !=
  979. NSS_STATUS_SUCCESS) {
  980. DEBUG(1, ("could not obtain winbind domain name!\n"));
  981. return lp_workgroup();
  982. @@ -325,7 +325,7 @@ const char *get_winbind_netbios_name(void)
  983.  
  984. /* Send off request */
  985.  
  986. - if (winbindd_request_response(WINBINDD_NETBIOS_NAME, NULL, &response) !=
  987. + if (winbindd_request_response(NULL, WINBINDD_NETBIOS_NAME, NULL, &response) !=
  988. NSS_STATUS_SUCCESS) {
  989. DEBUG(1, ("could not obtain winbind netbios name!\n"));
  990. return lp_netbios_name();
  991. @@ -393,7 +393,7 @@ static bool get_require_membership_sid(void) {
  992. return False;
  993. }
  994.  
  995. - if (winbindd_request_response(WINBINDD_LOOKUPNAME, &request, &response) !=
  996. + if (winbindd_request_response(NULL, WINBINDD_LOOKUPNAME, &request, &response) !=
  997. NSS_STATUS_SUCCESS) {
  998. DEBUG(0, ("Winbindd lookupname failed to resolve %s into a SID!\n",
  999. require_membership_of));
  1000. @@ -463,7 +463,7 @@ static bool check_plaintext_auth(const char *user, const char *pass,
  1001. sizeof(request.data.auth.require_membership_of_sid));
  1002. }
  1003.  
  1004. - result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
  1005. + result = winbindd_request_response(NULL, WINBINDD_PAM_AUTH, &request, &response);
  1006.  
  1007. /* Display response */
  1008.  
  1009. @@ -558,7 +558,7 @@ NTSTATUS contact_winbind_auth_crap(const char *username,
  1010. request.data.auth_crap.nt_resp_len = nt_response->length;
  1011. }
  1012.  
  1013. - result = winbindd_request_response(WINBINDD_PAM_AUTH_CRAP, &request, &response);
  1014. + result = winbindd_request_response(NULL, WINBINDD_PAM_AUTH_CRAP, &request, &response);
  1015. SAFE_FREE(request.extra_data.data);
  1016.  
  1017. /* Display response */
  1018. @@ -653,7 +653,7 @@ static NTSTATUS contact_winbind_change_pswd_auth_crap(const char *username,
  1019. request.data.chng_pswd_auth_crap.old_lm_hash_enc_len = old_lm_hash_enc.length;
  1020. }
  1021.  
  1022. - result = winbindd_request_response(WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP, &request, &response);
  1023. + result = winbindd_request_response(NULL, WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP, &request, &response);
  1024.  
  1025. /* Display response */
  1026.  
  1027. @@ -1194,7 +1194,7 @@ static NTSTATUS do_ccache_ntlm_auth(DATA_BLOB initial_msg, DATA_BLOB challenge_m
  1028. challenge_msg.data, challenge_msg.length);
  1029. }
  1030.  
  1031. - result = winbindd_request_response(WINBINDD_CCACHE_NTLMAUTH, &wb_request, &wb_response);
  1032. + result = winbindd_request_response(NULL, WINBINDD_CCACHE_NTLMAUTH, &wb_request, &wb_response);
  1033. SAFE_FREE(wb_request.extra_data.data);
  1034.  
  1035. if (result != NSS_STATUS_SUCCESS) {
  1036. --
  1037. 2.1.4
  1038.  
  1039. From 1d6a4b5c2c858b487f87179da1d8054d02700992 Mon Sep 17 00:00:00 2001
  1040. From: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  1041. Date: Sat, 21 Feb 2015 00:19:32 +0000
  1042. Subject: [PATCH 4/9] Add wbcContext struct, create and free functions
  1043.  
  1044. The basic context structure and functions for libwbclient so that
  1045. libwbclient can be made thread-safe.
  1046.  
  1047. Signed-off-by: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  1048. Reviewed-by: Volker Lendecke <vl@samba.org>
  1049. Reviewed-by: Jeremy Allison <jra@samba.org>
  1050. ---
  1051. nsswitch/libwbclient/wbclient.c | 44 ++++++++++++++++++++++++++++++++
  1052. nsswitch/libwbclient/wbclient.h | 30 ++++++++++++++++++++++
  1053. nsswitch/libwbclient/wbclient_internal.h | 4 +++
  1054. 3 files changed, 78 insertions(+)
  1055.  
  1056. diff --git a/nsswitch/libwbclient/wbclient.c b/nsswitch/libwbclient/wbclient.c
  1057. index 93c0318e..e6b3e4e 100644
  1058. --- a/nsswitch/libwbclient/wbclient.c
  1059. +++ b/nsswitch/libwbclient/wbclient.c
  1060. @@ -4,6 +4,7 @@
  1061. Winbind client API
  1062.  
  1063. Copyright (C) Gerald (Jerry) Carter 2007
  1064. + Copyright (C) Matthew Newton 2015
  1065.  
  1066.  
  1067. This library is free software; you can redistribute it and/or
  1068. @@ -27,6 +28,8 @@
  1069.  
  1070. /* From wb_common.c */
  1071.  
  1072. +struct winbindd_context;
  1073. +
  1074. NSS_STATUS winbindd_request_response(struct winbindd_context *wbctx,
  1075. int req_type,
  1076. struct winbindd_request *request,
  1077. @@ -35,6 +38,9 @@ NSS_STATUS winbindd_priv_request_response(struct winbindd_context *wbctx,
  1078. int req_type,
  1079. struct winbindd_request *request,
  1080. struct winbindd_response *response);
  1081. +struct winbindd_context *winbindd_ctx_create(void);
  1082. +void winbindd_ctx_free(struct winbindd_context *ctx);
  1083. +
  1084.  
  1085. /*
  1086. result == NSS_STATUS_UNAVAIL: winbind not around
  1087. @@ -259,3 +265,41 @@ wbcErr wbcLibraryDetails(struct wbcLibraryDetails **_details)
  1088. *_details = info;
  1089. return WBC_ERR_SUCCESS;
  1090. }
  1091. +
  1092. +/* Context handling functions */
  1093. +
  1094. +static void wbcContextDestructor(void *ptr)
  1095. +{
  1096. + struct wbcContext *ctx = (struct wbcContext *)ptr;
  1097. +
  1098. + winbindd_ctx_free(ctx->winbindd_ctx);
  1099. +}
  1100. +
  1101. +struct wbcContext *wbcCtxCreate(void)
  1102. +{
  1103. + struct wbcContext *ctx;
  1104. + struct winbindd_context *wbctx;
  1105. +
  1106. + ctx = (struct wbcContext *)wbcAllocateMemory(
  1107. + 1, sizeof(struct wbcContext), wbcContextDestructor);
  1108. +
  1109. + if (!ctx) {
  1110. + return NULL;
  1111. + }
  1112. +
  1113. + wbctx = winbindd_ctx_create();
  1114. +
  1115. + if (!wbctx) {
  1116. + wbcFreeMemory(ctx);
  1117. + return NULL;
  1118. + }
  1119. +
  1120. + ctx->winbindd_ctx = wbctx;
  1121. +
  1122. + return ctx;
  1123. +}
  1124. +
  1125. +void wbcCtxFree(struct wbcContext *ctx)
  1126. +{
  1127. + wbcFreeMemory(ctx);
  1128. +}
  1129. diff --git a/nsswitch/libwbclient/wbclient.h b/nsswitch/libwbclient/wbclient.h
  1130. index dc3e822..265cf43 100644
  1131. --- a/nsswitch/libwbclient/wbclient.h
  1132. +++ b/nsswitch/libwbclient/wbclient.h
  1133. @@ -5,6 +5,7 @@
  1134.  
  1135. Copyright (C) Gerald (Jerry) Carter 2007
  1136. Copyright (C) Volker Lendecke 2009
  1137. + Copyright (C) Matthew Newton 2015
  1138.  
  1139. This library is free software; you can redistribute it and/or
  1140. modify it under the terms of the GNU Lesser General Public
  1141. @@ -94,6 +95,13 @@ struct wbcInterfaceDetails {
  1142. char *dns_domain;
  1143. };
  1144.  
  1145. +/**
  1146. + * @brief Library context data
  1147. + *
  1148. + **/
  1149. +
  1150. +struct wbcContext;
  1151. +
  1152. /*
  1153. * Data types used by the Winbind Client API
  1154. */
  1155. @@ -523,6 +531,28 @@ struct wbcDomainControllerInfoEx {
  1156. void wbcFreeMemory(void*);
  1157.  
  1158.  
  1159. +/**********************************************************
  1160. + * Context Management
  1161. + **********************************************************/
  1162. +
  1163. +/**
  1164. + * @brief Create a new wbcContext context
  1165. + *
  1166. + * @return wbcContext
  1167. + **/
  1168. +struct wbcContext *wbcCtxCreate(void);
  1169. +
  1170. +/**
  1171. + * @brief Free a library context
  1172. + *
  1173. + * @param ctx wbcContext to free
  1174. + *
  1175. + * @return void
  1176. + **/
  1177. +void wbcCtxFree(struct wbcContext *ctx);
  1178. +
  1179. +
  1180. +
  1181. /*
  1182. * Utility functions for dealing with SIDs
  1183. */
  1184. diff --git a/nsswitch/libwbclient/wbclient_internal.h b/nsswitch/libwbclient/wbclient_internal.h
  1185. index 31f4130..e55bf27 100644
  1186. --- a/nsswitch/libwbclient/wbclient_internal.h
  1187. +++ b/nsswitch/libwbclient/wbclient_internal.h
  1188. @@ -22,6 +22,10 @@
  1189. #ifndef _WBCLIENT_INTERNAL_H
  1190. #define _WBCLIENT_INTERNAL_H
  1191.  
  1192. +struct wbcContext {
  1193. + struct winbindd_context *winbindd_ctx;
  1194. +};
  1195. +
  1196. /* Private functions */
  1197.  
  1198. wbcErr wbcRequestResponse(int cmd,
  1199. --
  1200. 2.1.4
  1201.  
  1202. From 81454e6fc953a57ddb874c3d3d0684e75ce563e7 Mon Sep 17 00:00:00 2001
  1203. From: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  1204. Date: Sat, 24 Jan 2015 00:30:00 +0000
  1205. Subject: [PATCH 5/9] Add wbcContext to wbcRequestResponse
  1206.  
  1207. To enable libwbclient to pass winbindd context through
  1208. to the winbind client library in wb_common.
  1209.  
  1210. Signed-off-by: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  1211. Reviewed-by: Volker Lendecke <vl@samba.org>
  1212. Reviewed-by: Jeremy Allison <jra@samba.org>
  1213. ---
  1214. nsswitch/libwbclient/wbclient.c | 24 +++++++++++++++++++-----
  1215. nsswitch/libwbclient/wbclient_internal.h | 4 ++--
  1216. 2 files changed, 21 insertions(+), 7 deletions(-)
  1217.  
  1218. diff --git a/nsswitch/libwbclient/wbclient.c b/nsswitch/libwbclient/wbclient.c
  1219. index e6b3e4e..ab1159a 100644
  1220. --- a/nsswitch/libwbclient/wbclient.c
  1221. +++ b/nsswitch/libwbclient/wbclient.c
  1222. @@ -56,6 +56,7 @@ void winbindd_ctx_free(struct winbindd_context *ctx);
  1223. */
  1224.  
  1225. static wbcErr wbcRequestResponseInt(
  1226. + struct winbindd_context *wbctx,
  1227. int cmd,
  1228. struct winbindd_request *request,
  1229. struct winbindd_response *response,
  1230. @@ -68,7 +69,7 @@ static wbcErr wbcRequestResponseInt(
  1231.  
  1232. /* for some calls the request and/or response can be NULL */
  1233.  
  1234. - nss_status = fn(NULL, cmd, request, response);
  1235. + nss_status = fn(wbctx, cmd, request, response);
  1236.  
  1237. switch (nss_status) {
  1238. case NSS_STATUS_SUCCESS:
  1239. @@ -91,25 +92,38 @@ static wbcErr wbcRequestResponseInt(
  1240. /**
  1241. * @brief Wrapper around Winbind's send/receive API call
  1242. *
  1243. + * @param ctx Context
  1244. * @param cmd Winbind command operation to perform
  1245. * @param request Send structure
  1246. * @param response Receive structure
  1247. *
  1248. * @return #wbcErr
  1249. */
  1250. -wbcErr wbcRequestResponse(int cmd,
  1251. +wbcErr wbcRequestResponse(struct wbcContext *ctx, int cmd,
  1252. struct winbindd_request *request,
  1253. struct winbindd_response *response)
  1254. {
  1255. - return wbcRequestResponseInt(cmd, request, response,
  1256. + struct winbindd_context *wbctx = NULL;
  1257. +
  1258. + if (ctx) {
  1259. + wbctx = ctx->winbindd_ctx;
  1260. + }
  1261. +
  1262. + return wbcRequestResponseInt(wbctx, cmd, request, response,
  1263. winbindd_request_response);
  1264. }
  1265.  
  1266. -wbcErr wbcRequestResponsePriv(int cmd,
  1267. +wbcErr wbcRequestResponsePriv(struct wbcContext *ctx, int cmd,
  1268. struct winbindd_request *request,
  1269. struct winbindd_response *response)
  1270. {
  1271. - return wbcRequestResponseInt(cmd, request, response,
  1272. + struct winbindd_context *wbctx = NULL;
  1273. +
  1274. + if (ctx) {
  1275. + wbctx = ctx->winbindd_ctx;
  1276. + }
  1277. +
  1278. + return wbcRequestResponseInt(wbctx, cmd, request, response,
  1279. winbindd_priv_request_response);
  1280. }
  1281.  
  1282. diff --git a/nsswitch/libwbclient/wbclient_internal.h b/nsswitch/libwbclient/wbclient_internal.h
  1283. index e55bf27..becddac 100644
  1284. --- a/nsswitch/libwbclient/wbclient_internal.h
  1285. +++ b/nsswitch/libwbclient/wbclient_internal.h
  1286. @@ -28,11 +28,11 @@ struct wbcContext {
  1287.  
  1288. /* Private functions */
  1289.  
  1290. -wbcErr wbcRequestResponse(int cmd,
  1291. +wbcErr wbcRequestResponse(struct wbcContext *ctx, int cmd,
  1292. struct winbindd_request *request,
  1293. struct winbindd_response *response);
  1294.  
  1295. -wbcErr wbcRequestResponsePriv(int cmd,
  1296. +wbcErr wbcRequestResponsePriv(struct wbcContext *ctx, int cmd,
  1297. struct winbindd_request *request,
  1298. struct winbindd_response *response);
  1299.  
  1300. --
  1301. 2.1.4
  1302.  
  1303. From 556c90df20b745420dd15bf0b6101295ba53d26c Mon Sep 17 00:00:00 2001
  1304. From: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  1305. Date: Sat, 21 Feb 2015 22:30:11 +0000
  1306. Subject: [PATCH 6/9] Add context versions of wbclient functions
  1307.  
  1308. To make the libwbclient library thread-safe, all functions
  1309. that call through to wb_common winbindd_request_response need
  1310. to have context that they can use. This commit adds all the
  1311. necessary functions.
  1312.  
  1313. Signed-off-by: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  1314. Reviewed-by: Volker Lendecke <vl@samba.org>
  1315. Reviewed-by: Jeremy Allison <jra@samba.org>
  1316. ---
  1317. nsswitch/libwbclient/wbc_idmap.c | 70 ++++-
  1318. nsswitch/libwbclient/wbc_pam.c | 198 +++++++++---
  1319. nsswitch/libwbclient/wbc_pwd.c | 127 ++++++--
  1320. nsswitch/libwbclient/wbc_sid.c | 169 +++++++---
  1321. nsswitch/libwbclient/wbc_util.c | 123 ++++++--
  1322. nsswitch/libwbclient/wbclient.h | 650 ++++++++++++++++++++++++++++++++++++++-
  1323. 6 files changed, 1161 insertions(+), 176 deletions(-)
  1324.  
  1325. diff --git a/nsswitch/libwbclient/wbc_idmap.c b/nsswitch/libwbclient/wbc_idmap.c
  1326. index 04e7d02..3e8366a 100644
  1327. --- a/nsswitch/libwbclient/wbc_idmap.c
  1328. +++ b/nsswitch/libwbclient/wbc_idmap.c
  1329. @@ -26,7 +26,8 @@
  1330. #include "../winbind_client.h"
  1331.  
  1332. /* Convert a Windows SID to a Unix uid, allocating an uid if needed */
  1333. -wbcErr wbcSidToUid(const struct wbcDomainSid *sid, uid_t *puid)
  1334. +wbcErr wbcCtxSidToUid(struct wbcContext *ctx, const struct wbcDomainSid *sid,
  1335. + uid_t *puid)
  1336. {
  1337. struct winbindd_request request;
  1338. struct winbindd_response response;
  1339. @@ -46,7 +47,7 @@ wbcErr wbcSidToUid(const struct wbcDomainSid *sid, uid_t *puid)
  1340.  
  1341. /* Make request */
  1342.  
  1343. - wbc_status = wbcRequestResponse(WINBINDD_SID_TO_UID,
  1344. + wbc_status = wbcRequestResponse(ctx, WINBINDD_SID_TO_UID,
  1345. &request,
  1346. &response);
  1347. BAIL_ON_WBC_ERROR(wbc_status);
  1348. @@ -59,6 +60,11 @@ wbcErr wbcSidToUid(const struct wbcDomainSid *sid, uid_t *puid)
  1349. return wbc_status;
  1350. }
  1351.  
  1352. +wbcErr wbcSidToUid(const struct wbcDomainSid *sid, uid_t *puid)
  1353. +{
  1354. + return wbcCtxSidToUid(NULL, sid, puid);
  1355. +}
  1356. +
  1357. /* Convert a Windows SID to a Unix uid if there already is a mapping */
  1358. wbcErr wbcQuerySidToUid(const struct wbcDomainSid *sid,
  1359. uid_t *puid)
  1360. @@ -67,7 +73,8 @@ wbcErr wbcQuerySidToUid(const struct wbcDomainSid *sid,
  1361. }
  1362.  
  1363. /* Convert a Unix uid to a Windows SID, allocating a SID if needed */
  1364. -wbcErr wbcUidToSid(uid_t uid, struct wbcDomainSid *sid)
  1365. +wbcErr wbcCtxUidToSid(struct wbcContext *ctx, uid_t uid,
  1366. + struct wbcDomainSid *sid)
  1367. {
  1368. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  1369. struct winbindd_request request;
  1370. @@ -87,7 +94,7 @@ wbcErr wbcUidToSid(uid_t uid, struct wbcDomainSid *sid)
  1371.  
  1372. /* Make request */
  1373.  
  1374. - wbc_status = wbcRequestResponse(WINBINDD_UID_TO_SID,
  1375. + wbc_status = wbcRequestResponse(ctx, WINBINDD_UID_TO_SID,
  1376. &request,
  1377. &response);
  1378. BAIL_ON_WBC_ERROR(wbc_status);
  1379. @@ -99,6 +106,11 @@ done:
  1380. return wbc_status;
  1381. }
  1382.  
  1383. +wbcErr wbcUidToSid(uid_t uid, struct wbcDomainSid *sid)
  1384. +{
  1385. + return wbcCtxUidToSid(NULL, uid, sid);
  1386. +}
  1387. +
  1388. /* Convert a Unix uid to a Windows SID if there already is a mapping */
  1389. wbcErr wbcQueryUidToSid(uid_t uid,
  1390. struct wbcDomainSid *sid)
  1391. @@ -115,7 +127,8 @@ wbcErr wbcQueryUidToSid(uid_t uid,
  1392. *
  1393. **/
  1394.  
  1395. -wbcErr wbcSidToGid(const struct wbcDomainSid *sid, gid_t *pgid)
  1396. +wbcErr wbcCtxSidToGid(struct wbcContext *ctx, const struct wbcDomainSid *sid,
  1397. + gid_t *pgid)
  1398. {
  1399. struct winbindd_request request;
  1400. struct winbindd_response response;
  1401. @@ -135,7 +148,7 @@ wbcErr wbcSidToGid(const struct wbcDomainSid *sid, gid_t *pgid)
  1402.  
  1403. /* Make request */
  1404.  
  1405. - wbc_status = wbcRequestResponse(WINBINDD_SID_TO_GID,
  1406. + wbc_status = wbcRequestResponse(ctx, WINBINDD_SID_TO_GID,
  1407. &request,
  1408. &response);
  1409. BAIL_ON_WBC_ERROR(wbc_status);
  1410. @@ -148,6 +161,10 @@ wbcErr wbcSidToGid(const struct wbcDomainSid *sid, gid_t *pgid)
  1411. return wbc_status;
  1412. }
  1413.  
  1414. +wbcErr wbcSidToGid(const struct wbcDomainSid *sid, gid_t *pgid)
  1415. +{
  1416. + return wbcCtxSidToGid(NULL, sid, pgid);
  1417. +}
  1418.  
  1419. /* Convert a Windows SID to a Unix gid if there already is a mapping */
  1420.  
  1421. @@ -159,7 +176,8 @@ wbcErr wbcQuerySidToGid(const struct wbcDomainSid *sid,
  1422.  
  1423.  
  1424. /* Convert a Unix gid to a Windows SID, allocating a SID if needed */
  1425. -wbcErr wbcGidToSid(gid_t gid, struct wbcDomainSid *sid)
  1426. +wbcErr wbcCtxGidToSid(struct wbcContext *ctx, gid_t gid,
  1427. + struct wbcDomainSid *sid)
  1428. {
  1429. struct winbindd_request request;
  1430. struct winbindd_response response;
  1431. @@ -179,7 +197,7 @@ wbcErr wbcGidToSid(gid_t gid, struct wbcDomainSid *sid)
  1432.  
  1433. /* Make request */
  1434.  
  1435. - wbc_status = wbcRequestResponse(WINBINDD_GID_TO_SID,
  1436. + wbc_status = wbcRequestResponse(ctx, WINBINDD_GID_TO_SID,
  1437. &request,
  1438. &response);
  1439. BAIL_ON_WBC_ERROR(wbc_status);
  1440. @@ -191,6 +209,11 @@ done:
  1441. return wbc_status;
  1442. }
  1443.  
  1444. +wbcErr wbcGidToSid(gid_t gid, struct wbcDomainSid *sid)
  1445. +{
  1446. + return wbcCtxGidToSid(NULL, gid, sid);
  1447. +}
  1448. +
  1449. /* Convert a Unix gid to a Windows SID if there already is a mapping */
  1450. wbcErr wbcQueryGidToSid(gid_t gid,
  1451. struct wbcDomainSid *sid)
  1452. @@ -199,7 +222,7 @@ wbcErr wbcQueryGidToSid(gid_t gid,
  1453. }
  1454.  
  1455. /* Obtain a new uid from Winbind */
  1456. -wbcErr wbcAllocateUid(uid_t *puid)
  1457. +wbcErr wbcCtxAllocateUid(struct wbcContext *ctx, uid_t *puid)
  1458. {
  1459. struct winbindd_request request;
  1460. struct winbindd_response response;
  1461. @@ -215,7 +238,7 @@ wbcErr wbcAllocateUid(uid_t *puid)
  1462.  
  1463. /* Make request */
  1464.  
  1465. - wbc_status = wbcRequestResponsePriv(WINBINDD_ALLOCATE_UID,
  1466. + wbc_status = wbcRequestResponsePriv(ctx, WINBINDD_ALLOCATE_UID,
  1467. &request, &response);
  1468. BAIL_ON_WBC_ERROR(wbc_status);
  1469.  
  1470. @@ -228,8 +251,13 @@ wbcErr wbcAllocateUid(uid_t *puid)
  1471. return wbc_status;
  1472. }
  1473.  
  1474. +wbcErr wbcAllocateUid(uid_t *puid)
  1475. +{
  1476. + return wbcCtxAllocateUid(NULL, puid);
  1477. +}
  1478. +
  1479. /* Obtain a new gid from Winbind */
  1480. -wbcErr wbcAllocateGid(gid_t *pgid)
  1481. +wbcErr wbcCtxAllocateGid(struct wbcContext *ctx, gid_t *pgid)
  1482. {
  1483. struct winbindd_request request;
  1484. struct winbindd_response response;
  1485. @@ -245,7 +273,7 @@ wbcErr wbcAllocateGid(gid_t *pgid)
  1486.  
  1487. /* Make request */
  1488.  
  1489. - wbc_status = wbcRequestResponsePriv(WINBINDD_ALLOCATE_GID,
  1490. + wbc_status = wbcRequestResponsePriv(ctx, WINBINDD_ALLOCATE_GID,
  1491. &request, &response);
  1492. BAIL_ON_WBC_ERROR(wbc_status);
  1493.  
  1494. @@ -258,6 +286,11 @@ wbcErr wbcAllocateGid(gid_t *pgid)
  1495. return wbc_status;
  1496. }
  1497.  
  1498. +wbcErr wbcAllocateGid(gid_t *pgid)
  1499. +{
  1500. + return wbcCtxAllocateGid(NULL, pgid);
  1501. +}
  1502. +
  1503. /* we can't include smb.h here... */
  1504. #define _ID_TYPE_UID 1
  1505. #define _ID_TYPE_GID 2
  1506. @@ -299,8 +332,9 @@ wbcErr wbcSetGidHwm(gid_t gid_hwm)
  1507. }
  1508.  
  1509. /* Convert a list of SIDs */
  1510. -wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids,
  1511. - struct wbcUnixId *ids)
  1512. +wbcErr wbcCtxSidsToUnixIds(struct wbcContext *ctx,
  1513. + const struct wbcDomainSid *sids,
  1514. + uint32_t num_sids, struct wbcUnixId *ids)
  1515. {
  1516. struct winbindd_request request;
  1517. struct winbindd_response response;
  1518. @@ -341,7 +375,7 @@ wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids,
  1519. request.extra_data.data = sidlist;
  1520. request.extra_len = p - sidlist;
  1521.  
  1522. - wbc_status = wbcRequestResponse(WINBINDD_SIDS_TO_XIDS,
  1523. + wbc_status = wbcRequestResponse(ctx, WINBINDD_SIDS_TO_XIDS,
  1524. &request, &response);
  1525. free(sidlist);
  1526. if (!WBC_ERROR_IS_OK(wbc_status)) {
  1527. @@ -393,3 +427,9 @@ done:
  1528. winbindd_free_response(&response);
  1529. return wbc_status;
  1530. }
  1531. +
  1532. +wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids,
  1533. + struct wbcUnixId *ids)
  1534. +{
  1535. + return wbcCtxSidsToUnixIds(NULL, sids, num_sids, ids);
  1536. +}
  1537. diff --git a/nsswitch/libwbclient/wbc_pam.c b/nsswitch/libwbclient/wbc_pam.c
  1538. index ae70d67..2f62953 100644
  1539. --- a/nsswitch/libwbclient/wbc_pam.c
  1540. +++ b/nsswitch/libwbclient/wbc_pam.c
  1541. @@ -29,8 +29,8 @@
  1542. #include "../winbind_client.h"
  1543.  
  1544. /* Authenticate a username/password pair */
  1545. -wbcErr wbcAuthenticateUser(const char *username,
  1546. - const char *password)
  1547. +wbcErr wbcCtxAuthenticateUser(struct wbcContext *ctx,
  1548. + const char *username, const char *password)
  1549. {
  1550. wbcErr wbc_status = WBC_ERR_SUCCESS;
  1551. struct wbcAuthUserParams params;
  1552. @@ -41,13 +41,18 @@ wbcErr wbcAuthenticateUser(const char *username,
  1553. params.level = WBC_AUTH_USER_LEVEL_PLAIN;
  1554. params.password.plaintext = password;
  1555.  
  1556. - wbc_status = wbcAuthenticateUserEx(&params, NULL, NULL);
  1557. + wbc_status = wbcCtxAuthenticateUserEx(ctx, &params, NULL, NULL);
  1558. BAIL_ON_WBC_ERROR(wbc_status);
  1559.  
  1560. done:
  1561. return wbc_status;
  1562. }
  1563.  
  1564. +wbcErr wbcAuthenticateUser(const char *username, const char *password)
  1565. +{
  1566. + return wbcCtxAuthenticateUser(NULL, username, password);
  1567. +}
  1568. +
  1569. static bool sid_attr_compose(struct wbcSidWithAttr *s,
  1570. const struct wbcDomainSid *d,
  1571. uint32_t rid, uint32_t attr)
  1572. @@ -343,9 +348,10 @@ done:
  1573.  
  1574.  
  1575. /* Authenticate with more detailed information */
  1576. -wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
  1577. - struct wbcAuthUserInfo **info,
  1578. - struct wbcAuthErrorInfo **error)
  1579. +wbcErr wbcCtxAuthenticateUserEx(struct wbcContext *ctx,
  1580. + const struct wbcAuthUserParams *params,
  1581. + struct wbcAuthUserInfo **info,
  1582. + struct wbcAuthErrorInfo **error)
  1583. {
  1584. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  1585. int cmd = 0;
  1586. @@ -389,7 +395,7 @@ wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
  1587.  
  1588. ZERO_STRUCT(sep_response);
  1589.  
  1590. - wbc_status = wbcRequestResponse(WINBINDD_INFO,
  1591. + wbc_status = wbcRequestResponse(ctx, WINBINDD_INFO,
  1592. NULL, &sep_response);
  1593. BAIL_ON_WBC_ERROR(wbc_status);
  1594.  
  1595. @@ -519,9 +525,11 @@ wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
  1596. }
  1597.  
  1598. if (cmd == WINBINDD_PAM_AUTH_CRAP) {
  1599. - wbc_status = wbcRequestResponsePriv(cmd, &request, &response);
  1600. + wbc_status = wbcRequestResponsePriv(ctx, cmd,
  1601. + &request, &response);
  1602. } else {
  1603. - wbc_status = wbcRequestResponse(cmd, &request, &response);
  1604. + wbc_status = wbcRequestResponse(ctx, cmd,
  1605. + &request, &response);
  1606. }
  1607. if (response.data.auth.nt_status != 0) {
  1608. if (error) {
  1609. @@ -548,9 +556,16 @@ done:
  1610. return wbc_status;
  1611. }
  1612.  
  1613. +wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
  1614. + struct wbcAuthUserInfo **info,
  1615. + struct wbcAuthErrorInfo **error)
  1616. +{
  1617. + return wbcCtxAuthenticateUserEx(NULL, params, info, error);
  1618. +}
  1619. +
  1620. /* Trigger a verification of the trust credentials of a specific domain */
  1621. -wbcErr wbcCheckTrustCredentials(const char *domain,
  1622. - struct wbcAuthErrorInfo **error)
  1623. +wbcErr wbcCtxCheckTrustCredentials(struct wbcContext *ctx, const char *domain,
  1624. + struct wbcAuthErrorInfo **error)
  1625. {
  1626. struct winbindd_request request;
  1627. struct winbindd_response response;
  1628. @@ -566,7 +581,7 @@ wbcErr wbcCheckTrustCredentials(const char *domain,
  1629.  
  1630. /* Send request */
  1631.  
  1632. - wbc_status = wbcRequestResponsePriv(WINBINDD_CHECK_MACHACC,
  1633. + wbc_status = wbcRequestResponsePriv(ctx, WINBINDD_CHECK_MACHACC,
  1634. &request, &response);
  1635. if (response.data.auth.nt_status != 0) {
  1636. if (error) {
  1637. @@ -584,9 +599,15 @@ wbcErr wbcCheckTrustCredentials(const char *domain,
  1638. return wbc_status;
  1639. }
  1640.  
  1641. +wbcErr wbcCheckTrustCredentials(const char *domain,
  1642. + struct wbcAuthErrorInfo **error)
  1643. +{
  1644. + return wbcCtxCheckTrustCredentials(NULL, domain, error);
  1645. +}
  1646. +
  1647. /* Trigger a change of the trust credentials for a specific domain */
  1648. -wbcErr wbcChangeTrustCredentials(const char *domain,
  1649. - struct wbcAuthErrorInfo **error)
  1650. +wbcErr wbcCtxChangeTrustCredentials(struct wbcContext *ctx, const char *domain,
  1651. + struct wbcAuthErrorInfo **error)
  1652. {
  1653. struct winbindd_request request;
  1654. struct winbindd_response response;
  1655. @@ -602,8 +623,8 @@ wbcErr wbcChangeTrustCredentials(const char *domain,
  1656.  
  1657. /* Send request */
  1658.  
  1659. - wbc_status = wbcRequestResponsePriv(WINBINDD_CHANGE_MACHACC,
  1660. - &request, &response);
  1661. + wbc_status = wbcRequestResponsePriv(ctx, WINBINDD_CHANGE_MACHACC,
  1662. + &request, &response);
  1663. if (response.data.auth.nt_status != 0) {
  1664. if (error) {
  1665. wbc_status = wbc_create_error_info(&response,
  1666. @@ -620,10 +641,22 @@ wbcErr wbcChangeTrustCredentials(const char *domain,
  1667. return wbc_status;
  1668. }
  1669.  
  1670. +wbcErr wbcChangeTrustCredentials(const char *domain,
  1671. + struct wbcAuthErrorInfo **error)
  1672. +{
  1673. + return wbcCtxChangeTrustCredentials(NULL, domain, error);
  1674. +}
  1675. +
  1676. /*
  1677. * Trigger a no-op NETLOGON call. Lightweight version of
  1678. * wbcCheckTrustCredentials
  1679. */
  1680. +wbcErr wbcCtxPingDc(struct wbcContext *ctx, const char *domain,
  1681. + struct wbcAuthErrorInfo **error)
  1682. +{
  1683. + return wbcCtxPingDc2(ctx, domain, error, NULL);
  1684. +}
  1685. +
  1686. wbcErr wbcPingDc(const char *domain, struct wbcAuthErrorInfo **error)
  1687. {
  1688. return wbcPingDc2(domain, error, NULL);
  1689. @@ -633,8 +666,8 @@ wbcErr wbcPingDc(const char *domain, struct wbcAuthErrorInfo **error)
  1690. * Trigger a no-op NETLOGON call. Lightweight version of
  1691. * wbcCheckTrustCredentials, optionally return attempted DC
  1692. */
  1693. -wbcErr wbcPingDc2(const char *domain, struct wbcAuthErrorInfo **error,
  1694. - char **dcname)
  1695. +wbcErr wbcCtxPingDc2(struct wbcContext *ctx, const char *domain,
  1696. + struct wbcAuthErrorInfo **error, char **dcname)
  1697. {
  1698. struct winbindd_request request;
  1699. struct winbindd_response response;
  1700. @@ -654,7 +687,7 @@ wbcErr wbcPingDc2(const char *domain, struct wbcAuthErrorInfo **error,
  1701.  
  1702. /* Send request */
  1703.  
  1704. - wbc_status = wbcRequestResponse(WINBINDD_PING_DC,
  1705. + wbc_status = wbcRequestResponse(ctx, WINBINDD_PING_DC,
  1706. &request,
  1707. &response);
  1708.  
  1709. @@ -684,9 +717,16 @@ wbcErr wbcPingDc2(const char *domain, struct wbcAuthErrorInfo **error,
  1710. return wbc_status;
  1711. }
  1712.  
  1713. +wbcErr wbcPingDc2(const char *domain, struct wbcAuthErrorInfo **error,
  1714. + char **dcname)
  1715. +{
  1716. + return wbcCtxPingDc2(NULL, domain, error, dcname);
  1717. +}
  1718. +
  1719. /* Trigger an extended logoff notification to Winbind for a specific user */
  1720. -wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
  1721. - struct wbcAuthErrorInfo **error)
  1722. +wbcErr wbcCtxLogoffUserEx(struct wbcContext *ctx,
  1723. + const struct wbcLogoffUserParams *params,
  1724. + struct wbcAuthErrorInfo **error)
  1725. {
  1726. struct winbindd_request request;
  1727. struct winbindd_response response;
  1728. @@ -749,7 +789,7 @@ wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
  1729.  
  1730. /* Send request */
  1731.  
  1732. - wbc_status = wbcRequestResponse(WINBINDD_PAM_LOGOFF,
  1733. + wbc_status = wbcRequestResponse(ctx, WINBINDD_PAM_LOGOFF,
  1734. &request,
  1735. &response);
  1736.  
  1737. @@ -770,10 +810,16 @@ wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
  1738. return wbc_status;
  1739. }
  1740.  
  1741. +wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
  1742. + struct wbcAuthErrorInfo **error)
  1743. +{
  1744. + return wbcCtxLogoffUserEx(NULL, params, error);
  1745. +}
  1746. +
  1747. /* Trigger a logoff notification to Winbind for a specific user */
  1748. -wbcErr wbcLogoffUser(const char *username,
  1749. - uid_t uid,
  1750. - const char *ccfilename)
  1751. +wbcErr wbcCtxLogoffUser(struct wbcContext *ctx,
  1752. + const char *username, uid_t uid,
  1753. + const char *ccfilename)
  1754. {
  1755. struct winbindd_request request;
  1756. struct winbindd_response response;
  1757. @@ -800,7 +846,7 @@ wbcErr wbcLogoffUser(const char *username,
  1758.  
  1759. /* Send request */
  1760.  
  1761. - wbc_status = wbcRequestResponse(WINBINDD_PAM_LOGOFF,
  1762. + wbc_status = wbcRequestResponse(ctx, WINBINDD_PAM_LOGOFF,
  1763. &request,
  1764. &response);
  1765.  
  1766. @@ -810,11 +856,19 @@ wbcErr wbcLogoffUser(const char *username,
  1767. return wbc_status;
  1768. }
  1769.  
  1770. +wbcErr wbcLogoffUser(const char *username,
  1771. + uid_t uid,
  1772. + const char *ccfilename)
  1773. +{
  1774. + return wbcCtxLogoffUser(NULL, username, uid, ccfilename);
  1775. +}
  1776. +
  1777. /* Change a password for a user with more detailed information upon failure */
  1778. -wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
  1779. - struct wbcAuthErrorInfo **error,
  1780. - enum wbcPasswordChangeRejectReason *reject_reason,
  1781. - struct wbcUserPasswordPolicyInfo **policy)
  1782. +wbcErr wbcCtxChangeUserPasswordEx(struct wbcContext *ctx,
  1783. + const struct wbcChangePasswordParams *params,
  1784. + struct wbcAuthErrorInfo **error,
  1785. + enum wbcPasswordChangeRejectReason *reject_reason,
  1786. + struct wbcUserPasswordPolicyInfo **policy)
  1787. {
  1788. struct winbindd_request request;
  1789. struct winbindd_response response;
  1790. @@ -973,7 +1027,7 @@ wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
  1791.  
  1792. /* Send request */
  1793.  
  1794. - wbc_status = wbcRequestResponse(cmd,
  1795. + wbc_status = wbcRequestResponse(ctx, cmd,
  1796. &request,
  1797. &response);
  1798. if (WBC_ERROR_IS_OK(wbc_status)) {
  1799. @@ -1008,10 +1062,20 @@ wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
  1800. return wbc_status;
  1801. }
  1802.  
  1803. +wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
  1804. + struct wbcAuthErrorInfo **error,
  1805. + enum wbcPasswordChangeRejectReason *reject_reason,
  1806. + struct wbcUserPasswordPolicyInfo **policy)
  1807. +{
  1808. + return wbcCtxChangeUserPasswordEx(NULL, params, error,
  1809. + reject_reason, policy);
  1810. +}
  1811. +
  1812. /* Change a password for a user */
  1813. -wbcErr wbcChangeUserPassword(const char *username,
  1814. - const char *old_password,
  1815. - const char *new_password)
  1816. +wbcErr wbcCtxChangeUserPassword(struct wbcContext *ctx,
  1817. + const char *username,
  1818. + const char *old_password,
  1819. + const char *new_password)
  1820. {
  1821. wbcErr wbc_status = WBC_ERR_SUCCESS;
  1822. struct wbcChangePasswordParams params;
  1823. @@ -1023,21 +1087,30 @@ wbcErr wbcChangeUserPassword(const char *username,
  1824. params.old_password.plaintext = old_password;
  1825. params.new_password.plaintext = new_password;
  1826.  
  1827. - wbc_status = wbcChangeUserPasswordEx(&params,
  1828. - NULL,
  1829. - NULL,
  1830. - NULL);
  1831. + wbc_status = wbcCtxChangeUserPasswordEx(ctx, &params,
  1832. + NULL,
  1833. + NULL,
  1834. + NULL);
  1835. BAIL_ON_WBC_ERROR(wbc_status);
  1836.  
  1837. done:
  1838. return wbc_status;
  1839. }
  1840.  
  1841. +wbcErr wbcChangeUserPassword(const char *username,
  1842. + const char *old_password,
  1843. + const char *new_password)
  1844. +{
  1845. + return wbcCtxChangeUserPassword(NULL, username,
  1846. + old_password, new_password);
  1847. +}
  1848. +
  1849. /* Logon a User */
  1850. -wbcErr wbcLogonUser(const struct wbcLogonUserParams *params,
  1851. - struct wbcLogonUserInfo **info,
  1852. - struct wbcAuthErrorInfo **error,
  1853. - struct wbcUserPasswordPolicyInfo **policy)
  1854. +wbcErr wbcCtxLogonUser(struct wbcContext *ctx,
  1855. + const struct wbcLogonUserParams *params,
  1856. + struct wbcLogonUserInfo **info,
  1857. + struct wbcAuthErrorInfo **error,
  1858. + struct wbcUserPasswordPolicyInfo **policy)
  1859. {
  1860. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  1861. struct winbindd_request request;
  1862. @@ -1139,7 +1212,7 @@ wbcErr wbcLogonUser(const struct wbcLogonUserParams *params,
  1863. }
  1864. }
  1865.  
  1866. - wbc_status = wbcRequestResponse(WINBINDD_PAM_AUTH,
  1867. + wbc_status = wbcRequestResponse(ctx, WINBINDD_PAM_AUTH,
  1868. &request,
  1869. &response);
  1870.  
  1871. @@ -1173,6 +1246,14 @@ done:
  1872. return wbc_status;
  1873. }
  1874.  
  1875. +wbcErr wbcLogonUser(const struct wbcLogonUserParams *params,
  1876. + struct wbcLogonUserInfo **info,
  1877. + struct wbcAuthErrorInfo **error,
  1878. + struct wbcUserPasswordPolicyInfo **policy)
  1879. +{
  1880. + return wbcCtxLogonUser(NULL, params, info, error, policy);
  1881. +}
  1882. +
  1883. static void wbcCredentialCacheInfoDestructor(void *ptr)
  1884. {
  1885. struct wbcCredentialCacheInfo *i =
  1886. @@ -1181,9 +1262,10 @@ static void wbcCredentialCacheInfoDestructor(void *ptr)
  1887. }
  1888.  
  1889. /* Authenticate a user with cached credentials */
  1890. -wbcErr wbcCredentialCache(struct wbcCredentialCacheParams *params,
  1891. - struct wbcCredentialCacheInfo **info,
  1892. - struct wbcAuthErrorInfo **error)
  1893. +wbcErr wbcCtxCredentialCache(struct wbcContext *ctx,
  1894. + struct wbcCredentialCacheParams *params,
  1895. + struct wbcCredentialCacheInfo **info,
  1896. + struct wbcAuthErrorInfo **error)
  1897. {
  1898. wbcErr status = WBC_ERR_UNKNOWN_FAILURE;
  1899. struct wbcCredentialCacheInfo *result = NULL;
  1900. @@ -1228,7 +1310,8 @@ wbcErr wbcCredentialCache(struct wbcCredentialCacheParams *params,
  1901. }
  1902.  
  1903. if (params->domain_name != NULL) {
  1904. - status = wbcRequestResponse(WINBINDD_INFO, NULL, &response);
  1905. + status = wbcRequestResponse(ctx, WINBINDD_INFO,
  1906. + NULL, &response);
  1907. if (!WBC_ERROR_IS_OK(status)) {
  1908. goto fail;
  1909. }
  1910. @@ -1277,8 +1360,8 @@ wbcErr wbcCredentialCache(struct wbcCredentialCacheParams *params,
  1911. challenge_blob->blob.length);
  1912. }
  1913.  
  1914. - status = wbcRequestResponse(WINBINDD_CCACHE_NTLMAUTH, &request,
  1915. - &response);
  1916. + status = wbcRequestResponse(ctx, WINBINDD_CCACHE_NTLMAUTH,
  1917. + &request, &response);
  1918. if (!WBC_ERROR_IS_OK(status)) {
  1919. goto fail;
  1920. }
  1921. @@ -1317,8 +1400,16 @@ fail:
  1922. return status;
  1923. }
  1924.  
  1925. +wbcErr wbcCredentialCache(struct wbcCredentialCacheParams *params,
  1926. + struct wbcCredentialCacheInfo **info,
  1927. + struct wbcAuthErrorInfo **error)
  1928. +{
  1929. + return wbcCtxCredentialCache(NULL, params, info, error);
  1930. +}
  1931. +
  1932. /* Authenticate a user with cached credentials */
  1933. -wbcErr wbcCredentialSave(const char *user, const char *password)
  1934. +wbcErr wbcCtxCredentialSave(struct wbcContext *ctx,
  1935. + const char *user, const char *password)
  1936. {
  1937. struct winbindd_request request;
  1938. struct winbindd_response response;
  1939. @@ -1332,5 +1423,10 @@ wbcErr wbcCredentialSave(const char *user, const char *password)
  1940. sizeof(request.data.ccache_save.pass)-1);
  1941. request.data.ccache_save.uid = getuid();
  1942.  
  1943. - return wbcRequestResponse(WINBINDD_CCACHE_SAVE, &request, &response);
  1944. + return wbcRequestResponse(ctx, WINBINDD_CCACHE_SAVE, &request, &response);
  1945. +}
  1946. +
  1947. +wbcErr wbcCredentialSave(const char *user, const char *password)
  1948. +{
  1949. + return wbcCtxCredentialSave(NULL, user, password);
  1950. }
  1951. diff --git a/nsswitch/libwbclient/wbc_pwd.c b/nsswitch/libwbclient/wbc_pwd.c
  1952. index 6df694d..0b05133 100644
  1953. --- a/nsswitch/libwbclient/wbc_pwd.c
  1954. +++ b/nsswitch/libwbclient/wbc_pwd.c
  1955. @@ -167,7 +167,8 @@ fail:
  1956. }
  1957.  
  1958. /* Fill in a struct passwd* for a domain user based on username */
  1959. -wbcErr wbcGetpwnam(const char *name, struct passwd **pwd)
  1960. +wbcErr wbcCtxGetpwnam(struct wbcContext *ctx,
  1961. + const char *name, struct passwd **pwd)
  1962. {
  1963. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  1964. struct winbindd_request request;
  1965. @@ -187,7 +188,7 @@ wbcErr wbcGetpwnam(const char *name, struct passwd **pwd)
  1966.  
  1967. strncpy(request.data.username, name, sizeof(request.data.username)-1);
  1968.  
  1969. - wbc_status = wbcRequestResponse(WINBINDD_GETPWNAM,
  1970. + wbc_status = wbcRequestResponse(ctx, WINBINDD_GETPWNAM,
  1971. &request,
  1972. &response);
  1973. BAIL_ON_WBC_ERROR(wbc_status);
  1974. @@ -199,8 +200,13 @@ wbcErr wbcGetpwnam(const char *name, struct passwd **pwd)
  1975. return wbc_status;
  1976. }
  1977.  
  1978. +wbcErr wbcGetpwnam(const char *name, struct passwd **pwd)
  1979. +{
  1980. + return wbcCtxGetpwnam(NULL, name, pwd);
  1981. +}
  1982. +
  1983. /* Fill in a struct passwd* for a domain user based on uid */
  1984. -wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd)
  1985. +wbcErr wbcCtxGetpwuid(struct wbcContext *ctx, uid_t uid, struct passwd **pwd)
  1986. {
  1987. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  1988. struct winbindd_request request;
  1989. @@ -218,7 +224,7 @@ wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd)
  1990.  
  1991. request.data.uid = uid;
  1992.  
  1993. - wbc_status = wbcRequestResponse(WINBINDD_GETPWUID,
  1994. + wbc_status = wbcRequestResponse(ctx, WINBINDD_GETPWUID,
  1995. &request,
  1996. &response);
  1997. BAIL_ON_WBC_ERROR(wbc_status);
  1998. @@ -230,8 +236,14 @@ wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd)
  1999. return wbc_status;
  2000. }
  2001.  
  2002. +wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd)
  2003. +{
  2004. + return wbcCtxGetpwuid(NULL, uid, pwd);
  2005. +}
  2006. +
  2007. /* Fill in a struct passwd* for a domain user based on sid */
  2008. -wbcErr wbcGetpwsid(struct wbcDomainSid *sid, struct passwd **pwd)
  2009. +wbcErr wbcCtxGetpwsid(struct wbcContext *ctx,
  2010. + struct wbcDomainSid *sid, struct passwd **pwd)
  2011. {
  2012. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2013. struct winbindd_request request;
  2014. @@ -249,7 +261,7 @@ wbcErr wbcGetpwsid(struct wbcDomainSid *sid, struct passwd **pwd)
  2015.  
  2016. wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid));
  2017.  
  2018. - wbc_status = wbcRequestResponse(WINBINDD_GETPWSID,
  2019. + wbc_status = wbcRequestResponse(ctx, WINBINDD_GETPWSID,
  2020. &request,
  2021. &response);
  2022. BAIL_ON_WBC_ERROR(wbc_status);
  2023. @@ -261,8 +273,14 @@ wbcErr wbcGetpwsid(struct wbcDomainSid *sid, struct passwd **pwd)
  2024. return wbc_status;
  2025. }
  2026.  
  2027. +wbcErr wbcGetpwsid(struct wbcDomainSid *sid, struct passwd **pwd)
  2028. +{
  2029. + return wbcCtxGetpwsid(NULL, sid, pwd);
  2030. +}
  2031. +
  2032. /* Fill in a struct passwd* for a domain user based on username */
  2033. -wbcErr wbcGetgrnam(const char *name, struct group **grp)
  2034. +wbcErr wbcCtxGetgrnam(struct wbcContext *ctx,
  2035. + const char *name, struct group **grp)
  2036. {
  2037. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2038. struct winbindd_request request;
  2039. @@ -282,7 +300,7 @@ wbcErr wbcGetgrnam(const char *name, struct group **grp)
  2040.  
  2041. strncpy(request.data.groupname, name, sizeof(request.data.groupname)-1);
  2042.  
  2043. - wbc_status = wbcRequestResponse(WINBINDD_GETGRNAM,
  2044. + wbc_status = wbcRequestResponse(ctx, WINBINDD_GETGRNAM,
  2045. &request,
  2046. &response);
  2047. BAIL_ON_WBC_ERROR(wbc_status);
  2048. @@ -297,8 +315,13 @@ wbcErr wbcGetgrnam(const char *name, struct group **grp)
  2049. return wbc_status;
  2050. }
  2051.  
  2052. +wbcErr wbcGetgrnam(const char *name, struct group **grp)
  2053. +{
  2054. + return wbcCtxGetgrnam(NULL, name, grp);
  2055. +}
  2056. +
  2057. /* Fill in a struct passwd* for a domain user based on uid */
  2058. -wbcErr wbcGetgrgid(gid_t gid, struct group **grp)
  2059. +wbcErr wbcCtxGetgrgid(struct wbcContext *ctx, gid_t gid, struct group **grp)
  2060. {
  2061. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2062. struct winbindd_request request;
  2063. @@ -316,7 +339,7 @@ wbcErr wbcGetgrgid(gid_t gid, struct group **grp)
  2064.  
  2065. request.data.gid = gid;
  2066.  
  2067. - wbc_status = wbcRequestResponse(WINBINDD_GETGRGID,
  2068. + wbc_status = wbcRequestResponse(ctx, WINBINDD_GETGRGID,
  2069. &request,
  2070. &response);
  2071. BAIL_ON_WBC_ERROR(wbc_status);
  2072. @@ -331,6 +354,11 @@ wbcErr wbcGetgrgid(gid_t gid, struct group **grp)
  2073. return wbc_status;
  2074. }
  2075.  
  2076. +wbcErr wbcGetgrgid(gid_t gid, struct group **grp)
  2077. +{
  2078. + return wbcCtxGetgrgid(NULL, gid, grp);
  2079. +}
  2080. +
  2081. /** @brief Number of cached passwd structs
  2082. *
  2083. */
  2084. @@ -347,7 +375,7 @@ static uint32_t pw_cache_idx;
  2085. static struct winbindd_response pw_response;
  2086.  
  2087. /* Reset the passwd iterator */
  2088. -wbcErr wbcSetpwent(void)
  2089. +wbcErr wbcCtxSetpwent(struct wbcContext *ctx)
  2090. {
  2091. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2092.  
  2093. @@ -358,7 +386,7 @@ wbcErr wbcSetpwent(void)
  2094.  
  2095. ZERO_STRUCT(pw_response);
  2096.  
  2097. - wbc_status = wbcRequestResponse(WINBINDD_SETPWENT,
  2098. + wbc_status = wbcRequestResponse(ctx, WINBINDD_SETPWENT,
  2099. NULL, NULL);
  2100. BAIL_ON_WBC_ERROR(wbc_status);
  2101.  
  2102. @@ -366,8 +394,13 @@ wbcErr wbcSetpwent(void)
  2103. return wbc_status;
  2104. }
  2105.  
  2106. +wbcErr wbcSetpwent(void)
  2107. +{
  2108. + return wbcCtxSetpwent(NULL);
  2109. +}
  2110. +
  2111. /* Close the passwd iterator */
  2112. -wbcErr wbcEndpwent(void)
  2113. +wbcErr wbcCtxEndpwent(struct wbcContext *ctx)
  2114. {
  2115. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2116.  
  2117. @@ -376,7 +409,7 @@ wbcErr wbcEndpwent(void)
  2118. winbindd_free_response(&pw_response);
  2119. }
  2120.  
  2121. - wbc_status = wbcRequestResponse(WINBINDD_ENDPWENT,
  2122. + wbc_status = wbcRequestResponse(ctx, WINBINDD_ENDPWENT,
  2123. NULL, NULL);
  2124. BAIL_ON_WBC_ERROR(wbc_status);
  2125.  
  2126. @@ -384,8 +417,13 @@ wbcErr wbcEndpwent(void)
  2127. return wbc_status;
  2128. }
  2129.  
  2130. +wbcErr wbcEndpwent(void)
  2131. +{
  2132. + return wbcCtxEndpwent(NULL);
  2133. +}
  2134. +
  2135. /* Return the next struct passwd* entry from the pwent iterator */
  2136. -wbcErr wbcGetpwent(struct passwd **pwd)
  2137. +wbcErr wbcCtxGetpwent(struct wbcContext *ctx, struct passwd **pwd)
  2138. {
  2139. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2140. struct winbindd_request request;
  2141. @@ -405,7 +443,7 @@ wbcErr wbcGetpwent(struct passwd **pwd)
  2142. ZERO_STRUCT(request);
  2143. request.data.num_entries = MAX_GETPWENT_USERS;
  2144.  
  2145. - wbc_status = wbcRequestResponse(WINBINDD_GETPWENT, &request,
  2146. + wbc_status = wbcRequestResponse(ctx, WINBINDD_GETPWENT, &request,
  2147. &pw_response);
  2148.  
  2149. BAIL_ON_WBC_ERROR(wbc_status);
  2150. @@ -426,6 +464,11 @@ done:
  2151. return wbc_status;
  2152. }
  2153.  
  2154. +wbcErr wbcGetpwent(struct passwd **pwd)
  2155. +{
  2156. + return wbcCtxGetpwent(NULL, pwd);
  2157. +}
  2158. +
  2159. /** @brief Number of cached group structs
  2160. *
  2161. */
  2162. @@ -442,7 +485,7 @@ static uint32_t gr_cache_idx;
  2163. static struct winbindd_response gr_response;
  2164.  
  2165. /* Reset the group iterator */
  2166. -wbcErr wbcSetgrent(void)
  2167. +wbcErr wbcCtxSetgrent(struct wbcContext *ctx)
  2168. {
  2169. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2170.  
  2171. @@ -453,7 +496,7 @@ wbcErr wbcSetgrent(void)
  2172.  
  2173. ZERO_STRUCT(gr_response);
  2174.  
  2175. - wbc_status = wbcRequestResponse(WINBINDD_SETGRENT,
  2176. + wbc_status = wbcRequestResponse(ctx, WINBINDD_SETGRENT,
  2177. NULL, NULL);
  2178. BAIL_ON_WBC_ERROR(wbc_status);
  2179.  
  2180. @@ -461,8 +504,13 @@ wbcErr wbcSetgrent(void)
  2181. return wbc_status;
  2182. }
  2183.  
  2184. +wbcErr wbcSetgrent(void)
  2185. +{
  2186. + return wbcCtxSetgrent(NULL);
  2187. +}
  2188. +
  2189. /* Close the group iterator */
  2190. -wbcErr wbcEndgrent(void)
  2191. +wbcErr wbcCtxEndgrent(struct wbcContext *ctx)
  2192. {
  2193. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2194.  
  2195. @@ -471,7 +519,7 @@ wbcErr wbcEndgrent(void)
  2196. winbindd_free_response(&gr_response);
  2197. }
  2198.  
  2199. - wbc_status = wbcRequestResponse(WINBINDD_ENDGRENT,
  2200. + wbc_status = wbcRequestResponse(ctx, WINBINDD_ENDGRENT,
  2201. NULL, NULL);
  2202. BAIL_ON_WBC_ERROR(wbc_status);
  2203.  
  2204. @@ -479,8 +527,13 @@ wbcErr wbcEndgrent(void)
  2205. return wbc_status;
  2206. }
  2207.  
  2208. +wbcErr wbcEndgrent(void)
  2209. +{
  2210. + return wbcCtxEndgrent(NULL);
  2211. +}
  2212. +
  2213. /* Return the next struct group* entry from the pwent iterator */
  2214. -wbcErr wbcGetgrent(struct group **grp)
  2215. +wbcErr wbcCtxGetgrent(struct wbcContext *ctx, struct group **grp)
  2216. {
  2217. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2218. struct winbindd_request request;
  2219. @@ -501,8 +554,8 @@ wbcErr wbcGetgrent(struct group **grp)
  2220. ZERO_STRUCT(request);
  2221. request.data.num_entries = MAX_GETGRENT_GROUPS;
  2222.  
  2223. - wbc_status = wbcRequestResponse(WINBINDD_GETGRENT, &request,
  2224. - &gr_response);
  2225. + wbc_status = wbcRequestResponse(ctx, WINBINDD_GETGRENT,
  2226. + &request, &gr_response);
  2227.  
  2228. BAIL_ON_WBC_ERROR(wbc_status);
  2229.  
  2230. @@ -526,8 +579,13 @@ done:
  2231. return wbc_status;
  2232. }
  2233.  
  2234. +wbcErr wbcGetgrent(struct group **grp)
  2235. +{
  2236. + return wbcCtxGetgrent(NULL, grp);
  2237. +}
  2238. +
  2239. /* Return the next struct group* entry from the pwent iterator */
  2240. -wbcErr wbcGetgrlist(struct group **grp)
  2241. +wbcErr wbcCtxGetgrlist(struct wbcContext *ctx, struct group **grp)
  2242. {
  2243. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2244. struct winbindd_request request;
  2245. @@ -548,8 +606,8 @@ wbcErr wbcGetgrlist(struct group **grp)
  2246. ZERO_STRUCT(request);
  2247. request.data.num_entries = MAX_GETGRENT_GROUPS;
  2248.  
  2249. - wbc_status = wbcRequestResponse(WINBINDD_GETGRLST, &request,
  2250. - &gr_response);
  2251. + wbc_status = wbcRequestResponse(ctx, WINBINDD_GETGRLST,
  2252. + &request, &gr_response);
  2253.  
  2254. BAIL_ON_WBC_ERROR(wbc_status);
  2255.  
  2256. @@ -569,10 +627,14 @@ done:
  2257. return wbc_status;
  2258. }
  2259.  
  2260. +wbcErr wbcGetgrlist(struct group **grp)
  2261. +{
  2262. + return wbcCtxGetgrlist(NULL, grp);
  2263. +}
  2264. +
  2265. /* Return the unix group array belonging to the given user */
  2266. -wbcErr wbcGetGroups(const char *account,
  2267. - uint32_t *num_groups,
  2268. - gid_t **_groups)
  2269. +wbcErr wbcCtxGetGroups(struct wbcContext *ctx, const char *account,
  2270. + uint32_t *num_groups, gid_t **_groups)
  2271. {
  2272. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2273. struct winbindd_request request;
  2274. @@ -594,7 +656,7 @@ wbcErr wbcGetGroups(const char *account,
  2275.  
  2276. strncpy(request.data.username, account, sizeof(request.data.username)-1);
  2277.  
  2278. - wbc_status = wbcRequestResponse(WINBINDD_GETGROUPS,
  2279. + wbc_status = wbcRequestResponse(ctx, WINBINDD_GETGROUPS,
  2280. &request,
  2281. &response);
  2282. BAIL_ON_WBC_ERROR(wbc_status);
  2283. @@ -618,3 +680,8 @@ wbcErr wbcGetGroups(const char *account,
  2284. wbcFreeMemory(groups);
  2285. return wbc_status;
  2286. }
  2287. +
  2288. +wbcErr wbcGetGroups(const char *account, uint32_t *num_groups, gid_t **_groups)
  2289. +{
  2290. + return wbcCtxGetGroups(NULL, account, num_groups, _groups);
  2291. +}
  2292. diff --git a/nsswitch/libwbclient/wbc_sid.c b/nsswitch/libwbclient/wbc_sid.c
  2293. index 82ac339..2df9aa8 100644
  2294. --- a/nsswitch/libwbclient/wbc_sid.c
  2295. +++ b/nsswitch/libwbclient/wbc_sid.c
  2296. @@ -174,10 +174,11 @@ done:
  2297.  
  2298.  
  2299. /* Convert a domain and name to SID */
  2300. -wbcErr wbcLookupName(const char *domain,
  2301. - const char *name,
  2302. - struct wbcDomainSid *sid,
  2303. - enum wbcSidType *name_type)
  2304. +wbcErr wbcCtxLookupName(struct wbcContext *ctx,
  2305. + const char *domain,
  2306. + const char *name,
  2307. + struct wbcDomainSid *sid,
  2308. + enum wbcSidType *name_type)
  2309. {
  2310. struct winbindd_request request;
  2311. struct winbindd_response response;
  2312. @@ -200,7 +201,7 @@ wbcErr wbcLookupName(const char *domain,
  2313. strncpy(request.data.name.name, name,
  2314. sizeof(request.data.name.name)-1);
  2315.  
  2316. - wbc_status = wbcRequestResponse(WINBINDD_LOOKUPNAME,
  2317. + wbc_status = wbcRequestResponse(ctx, WINBINDD_LOOKUPNAME,
  2318. &request,
  2319. &response);
  2320. BAIL_ON_WBC_ERROR(wbc_status);
  2321. @@ -216,12 +217,21 @@ wbcErr wbcLookupName(const char *domain,
  2322. return wbc_status;
  2323. }
  2324.  
  2325. +wbcErr wbcLookupName(const char *domain,
  2326. + const char *name,
  2327. + struct wbcDomainSid *sid,
  2328. + enum wbcSidType *name_type)
  2329. +{
  2330. + return wbcCtxLookupName(NULL, domain, name, sid, name_type);
  2331. +}
  2332. +
  2333.  
  2334. /* Convert a SID to a domain and name */
  2335. -wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
  2336. - char **pdomain,
  2337. - char **pname,
  2338. - enum wbcSidType *pname_type)
  2339. +wbcErr wbcCtxLookupSid(struct wbcContext *ctx,
  2340. + const struct wbcDomainSid *sid,
  2341. + char **pdomain,
  2342. + char **pname,
  2343. + enum wbcSidType *pname_type)
  2344. {
  2345. struct winbindd_request request;
  2346. struct winbindd_response response;
  2347. @@ -241,7 +251,8 @@ wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
  2348.  
  2349. /* Make request */
  2350.  
  2351. - wbc_status = wbcRequestResponse(WINBINDD_LOOKUPSID, &request,
  2352. + wbc_status = wbcRequestResponse(ctx, WINBINDD_LOOKUPSID,
  2353. + &request,
  2354. &response);
  2355. if (!WBC_ERROR_IS_OK(wbc_status)) {
  2356. return wbc_status;
  2357. @@ -279,6 +290,14 @@ done:
  2358. return wbc_status;
  2359. }
  2360.  
  2361. +wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
  2362. + char **pdomain,
  2363. + char **pname,
  2364. + enum wbcSidType *pname_type)
  2365. +{
  2366. + return wbcCtxLookupSid(NULL, sid, pdomain, pname, pname_type);
  2367. +}
  2368. +
  2369. static void wbcDomainInfosDestructor(void *ptr)
  2370. {
  2371. struct wbcDomainInfo *i = (struct wbcDomainInfo *)ptr;
  2372. @@ -300,9 +319,10 @@ static void wbcTranslatedNamesDestructor(void *ptr)
  2373. }
  2374. }
  2375.  
  2376. -wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids,
  2377. - struct wbcDomainInfo **pdomains, int *pnum_domains,
  2378. - struct wbcTranslatedName **pnames)
  2379. +wbcErr wbcCtxLookupSids(struct wbcContext *ctx,
  2380. + const struct wbcDomainSid *sids, int num_sids,
  2381. + struct wbcDomainInfo **pdomains, int *pnum_domains,
  2382. + struct wbcTranslatedName **pnames)
  2383. {
  2384. struct winbindd_request request;
  2385. struct winbindd_response response;
  2386. @@ -344,7 +364,7 @@ wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids,
  2387. request.extra_data.data = sidlist;
  2388. request.extra_len = p - sidlist;
  2389.  
  2390. - wbc_status = wbcRequestResponse(WINBINDD_LOOKUPSIDS,
  2391. + wbc_status = wbcRequestResponse(ctx, WINBINDD_LOOKUPSIDS,
  2392. &request, &response);
  2393. free(sidlist);
  2394. if (!WBC_ERROR_IS_OK(wbc_status)) {
  2395. @@ -469,9 +489,17 @@ fail:
  2396. return wbc_status;
  2397. }
  2398.  
  2399. +wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids,
  2400. + struct wbcDomainInfo **pdomains, int *pnum_domains,
  2401. + struct wbcTranslatedName **pnames)
  2402. +{
  2403. + return wbcCtxLookupSids(NULL, sids, num_sids, pdomains,
  2404. + pnum_domains, pnames);
  2405. +}
  2406. +
  2407. /* Translate a collection of RIDs within a domain to names */
  2408.  
  2409. -wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
  2410. +wbcErr wbcCtxLookupRids(struct wbcContext *ctx, struct wbcDomainSid *dom_sid,
  2411. int num_rids,
  2412. uint32_t *rids,
  2413. const char **pp_domain_name,
  2414. @@ -521,7 +549,7 @@ wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
  2415. request.extra_data.data = ridlist;
  2416. request.extra_len = len;
  2417.  
  2418. - wbc_status = wbcRequestResponse(WINBINDD_LOOKUPRIDS,
  2419. + wbc_status = wbcRequestResponse(ctx, WINBINDD_LOOKUPRIDS,
  2420. &request,
  2421. &response);
  2422. free(ridlist);
  2423. @@ -593,11 +621,23 @@ wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
  2424. return wbc_status;
  2425. }
  2426.  
  2427. +wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
  2428. + int num_rids,
  2429. + uint32_t *rids,
  2430. + const char **pp_domain_name,
  2431. + const char ***pnames,
  2432. + enum wbcSidType **ptypes)
  2433. +{
  2434. + return wbcCtxLookupRids(NULL, dom_sid, num_rids, rids,
  2435. + pp_domain_name, pnames, ptypes);
  2436. +}
  2437. +
  2438. /* Get the groups a user belongs to */
  2439. -wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
  2440. - bool domain_groups_only,
  2441. - uint32_t *num_sids,
  2442. - struct wbcDomainSid **_sids)
  2443. +wbcErr wbcCtxLookupUserSids(struct wbcContext *ctx,
  2444. + const struct wbcDomainSid *user_sid,
  2445. + bool domain_groups_only,
  2446. + uint32_t *num_sids,
  2447. + struct wbcDomainSid **_sids)
  2448. {
  2449. uint32_t i;
  2450. const char *s;
  2451. @@ -625,7 +665,7 @@ wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
  2452. cmd = WINBINDD_GETUSERSIDS;
  2453. }
  2454.  
  2455. - wbc_status = wbcRequestResponse(cmd,
  2456. + wbc_status = wbcRequestResponse(ctx, cmd,
  2457. &request,
  2458. &response);
  2459. BAIL_ON_WBC_ERROR(wbc_status);
  2460. @@ -666,6 +706,15 @@ wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
  2461. return wbc_status;
  2462. }
  2463.  
  2464. +wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
  2465. + bool domain_groups_only,
  2466. + uint32_t *num_sids,
  2467. + struct wbcDomainSid **_sids)
  2468. +{
  2469. + return wbcCtxLookupUserSids(NULL, user_sid, domain_groups_only,
  2470. + num_sids, _sids);
  2471. +}
  2472. +
  2473. static inline
  2474. wbcErr _sid_to_rid(struct wbcDomainSid *sid, uint32_t *rid)
  2475. {
  2476. @@ -678,11 +727,12 @@ wbcErr _sid_to_rid(struct wbcDomainSid *sid, uint32_t *rid)
  2477. }
  2478.  
  2479. /* Get alias membership for sids */
  2480. -wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
  2481. - struct wbcDomainSid *sids,
  2482. - uint32_t num_sids,
  2483. - uint32_t **alias_rids,
  2484. - uint32_t *num_alias_rids)
  2485. +wbcErr wbcCtxGetSidAliases(struct wbcContext *ctx,
  2486. + const struct wbcDomainSid *dom_sid,
  2487. + struct wbcDomainSid *sids,
  2488. + uint32_t num_sids,
  2489. + uint32_t **alias_rids,
  2490. + uint32_t *num_alias_rids)
  2491. {
  2492. uint32_t i;
  2493. const char *s;
  2494. @@ -743,7 +793,7 @@ wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
  2495. request.extra_data.data = extra_data;
  2496. request.extra_len = extra_data_len;
  2497.  
  2498. - wbc_status = wbcRequestResponse(WINBINDD_GETSIDALIASES,
  2499. + wbc_status = wbcRequestResponse(ctx, WINBINDD_GETSIDALIASES,
  2500. &request,
  2501. &response);
  2502. BAIL_ON_WBC_ERROR(wbc_status);
  2503. @@ -783,11 +833,22 @@ wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
  2504. return wbc_status;
  2505. }
  2506.  
  2507. +wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
  2508. + struct wbcDomainSid *sids,
  2509. + uint32_t num_sids,
  2510. + uint32_t **alias_rids,
  2511. + uint32_t *num_alias_rids)
  2512. +{
  2513. + return wbcCtxGetSidAliases(NULL, dom_sid, sids, num_sids,
  2514. + alias_rids, num_alias_rids);
  2515. +}
  2516. +
  2517.  
  2518. /* Lists Users */
  2519. -wbcErr wbcListUsers(const char *domain_name,
  2520. - uint32_t *_num_users,
  2521. - const char ***_users)
  2522. +wbcErr wbcCtxListUsers(struct wbcContext *ctx,
  2523. + const char *domain_name,
  2524. + uint32_t *_num_users,
  2525. + const char ***_users)
  2526. {
  2527. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2528. struct winbindd_request request;
  2529. @@ -806,7 +867,7 @@ wbcErr wbcListUsers(const char *domain_name,
  2530. sizeof(request.domain_name)-1);
  2531. }
  2532.  
  2533. - wbc_status = wbcRequestResponse(WINBINDD_LIST_USERS,
  2534. + wbc_status = wbcRequestResponse(ctx, WINBINDD_LIST_USERS,
  2535. &request,
  2536. &response);
  2537. BAIL_ON_WBC_ERROR(wbc_status);
  2538. @@ -858,10 +919,18 @@ wbcErr wbcListUsers(const char *domain_name,
  2539. return wbc_status;
  2540. }
  2541.  
  2542. +wbcErr wbcListUsers(const char *domain_name,
  2543. + uint32_t *_num_users,
  2544. + const char ***_users)
  2545. +{
  2546. + return wbcCtxListUsers(NULL, domain_name, _num_users, _users);
  2547. +}
  2548. +
  2549. /* Lists Groups */
  2550. -wbcErr wbcListGroups(const char *domain_name,
  2551. - uint32_t *_num_groups,
  2552. - const char ***_groups)
  2553. +wbcErr wbcCtxListGroups(struct wbcContext *ctx,
  2554. + const char *domain_name,
  2555. + uint32_t *_num_groups,
  2556. + const char ***_groups)
  2557. {
  2558. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2559. struct winbindd_request request;
  2560. @@ -880,7 +949,7 @@ wbcErr wbcListGroups(const char *domain_name,
  2561. sizeof(request.domain_name)-1);
  2562. }
  2563.  
  2564. - wbc_status = wbcRequestResponse(WINBINDD_LIST_GROUPS,
  2565. + wbc_status = wbcRequestResponse(ctx, WINBINDD_LIST_GROUPS,
  2566. &request,
  2567. &response);
  2568. BAIL_ON_WBC_ERROR(wbc_status);
  2569. @@ -932,27 +1001,35 @@ wbcErr wbcListGroups(const char *domain_name,
  2570. return wbc_status;
  2571. }
  2572.  
  2573. -wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
  2574. - char **pdomain,
  2575. - char **pfullname,
  2576. - enum wbcSidType *pname_type)
  2577. +wbcErr wbcListGroups(const char *domain_name,
  2578. + uint32_t *_num_groups,
  2579. + const char ***_groups)
  2580. +{
  2581. + return wbcCtxListGroups(NULL, domain_name, _num_groups, _groups);
  2582. +}
  2583. +
  2584. +wbcErr wbcCtxGetDisplayName(struct wbcContext *ctx,
  2585. + const struct wbcDomainSid *sid,
  2586. + char **pdomain,
  2587. + char **pfullname,
  2588. + enum wbcSidType *pname_type)
  2589. {
  2590. wbcErr wbc_status;
  2591. char *domain = NULL;
  2592. char *name = NULL;
  2593. enum wbcSidType name_type;
  2594.  
  2595. - wbc_status = wbcLookupSid(sid, &domain, &name, &name_type);
  2596. + wbc_status = wbcCtxLookupSid(ctx, sid, &domain, &name, &name_type);
  2597. BAIL_ON_WBC_ERROR(wbc_status);
  2598.  
  2599. if (name_type == WBC_SID_NAME_USER) {
  2600. uid_t uid;
  2601. struct passwd *pwd;
  2602.  
  2603. - wbc_status = wbcSidToUid(sid, &uid);
  2604. + wbc_status = wbcCtxSidToUid(ctx, sid, &uid);
  2605. BAIL_ON_WBC_ERROR(wbc_status);
  2606.  
  2607. - wbc_status = wbcGetpwuid(uid, &pwd);
  2608. + wbc_status = wbcCtxGetpwuid(ctx, uid, &pwd);
  2609. BAIL_ON_WBC_ERROR(wbc_status);
  2610.  
  2611. wbcFreeMemory(name);
  2612. @@ -977,6 +1054,14 @@ wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
  2613. return wbc_status;
  2614. }
  2615.  
  2616. +wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
  2617. + char **pdomain,
  2618. + char **pfullname,
  2619. + enum wbcSidType *pname_type)
  2620. +{
  2621. + return wbcCtxGetDisplayName(NULL, sid, pdomain, pfullname, pname_type);
  2622. +}
  2623. +
  2624. const char* wbcSidTypeString(enum wbcSidType type)
  2625. {
  2626. switch (type) {
  2627. diff --git a/nsswitch/libwbclient/wbc_util.c b/nsswitch/libwbclient/wbc_util.c
  2628. index 4060e25..3dab0a2 100644
  2629. --- a/nsswitch/libwbclient/wbc_util.c
  2630. +++ b/nsswitch/libwbclient/wbc_util.c
  2631. @@ -28,9 +28,11 @@
  2632.  
  2633. /** @brief Ping winbindd to see if the daemon is running
  2634. *
  2635. + * @param *ctx wbclient Context
  2636. + *
  2637. * @return #wbcErr
  2638. **/
  2639. -wbcErr wbcPing(void)
  2640. +wbcErr wbcCtxPing(struct wbcContext *ctx)
  2641. {
  2642. struct winbindd_request request;
  2643. struct winbindd_response response;
  2644. @@ -40,7 +42,12 @@ wbcErr wbcPing(void)
  2645. ZERO_STRUCT(request);
  2646. ZERO_STRUCT(response);
  2647.  
  2648. - return wbcRequestResponse(WINBINDD_PING, &request, &response);
  2649. + return wbcRequestResponse(ctx, WINBINDD_PING, &request, &response);
  2650. +}
  2651. +
  2652. +wbcErr wbcPing(void)
  2653. +{
  2654. + return wbcCtxPing(NULL);
  2655. }
  2656.  
  2657. static void wbcInterfaceDetailsDestructor(void *ptr)
  2658. @@ -60,7 +67,8 @@ static void wbcInterfaceDetailsDestructor(void *ptr)
  2659. * @return #wbcErr
  2660. */
  2661.  
  2662. -wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **_details)
  2663. +wbcErr wbcCtxInterfaceDetails(struct wbcContext *ctx,
  2664. + struct wbcInterfaceDetails **_details)
  2665. {
  2666. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2667. struct wbcInterfaceDetails *info;
  2668. @@ -79,12 +87,13 @@ wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **_details)
  2669. BAIL_ON_PTR_ERROR(info, wbc_status);
  2670.  
  2671. /* first the interface version */
  2672. - wbc_status = wbcRequestResponse(WINBINDD_INTERFACE_VERSION, NULL, &response);
  2673. + wbc_status = wbcRequestResponse(ctx, WINBINDD_INTERFACE_VERSION,
  2674. + NULL, &response);
  2675. BAIL_ON_WBC_ERROR(wbc_status);
  2676. info->interface_version = response.data.interface_version;
  2677.  
  2678. /* then the samba version and the winbind separator */
  2679. - wbc_status = wbcRequestResponse(WINBINDD_INFO, NULL, &response);
  2680. + wbc_status = wbcRequestResponse(ctx, WINBINDD_INFO, NULL, &response);
  2681. BAIL_ON_WBC_ERROR(wbc_status);
  2682.  
  2683. info->winbind_version = strdup(response.data.info.samba_version);
  2684. @@ -92,20 +101,22 @@ wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **_details)
  2685. info->winbind_separator = response.data.info.winbind_separator;
  2686.  
  2687. /* then the local netbios name */
  2688. - wbc_status = wbcRequestResponse(WINBINDD_NETBIOS_NAME, NULL, &response);
  2689. + wbc_status = wbcRequestResponse(ctx, WINBINDD_NETBIOS_NAME,
  2690. + NULL, &response);
  2691. BAIL_ON_WBC_ERROR(wbc_status);
  2692.  
  2693. info->netbios_name = strdup(response.data.netbios_name);
  2694. BAIL_ON_PTR_ERROR(info->netbios_name, wbc_status);
  2695.  
  2696. /* then the local workgroup name */
  2697. - wbc_status = wbcRequestResponse(WINBINDD_DOMAIN_NAME, NULL, &response);
  2698. + wbc_status = wbcRequestResponse(ctx, WINBINDD_DOMAIN_NAME,
  2699. + NULL, &response);
  2700. BAIL_ON_WBC_ERROR(wbc_status);
  2701.  
  2702. info->netbios_domain = strdup(response.data.domain_name);
  2703. BAIL_ON_PTR_ERROR(info->netbios_domain, wbc_status);
  2704.  
  2705. - wbc_status = wbcDomainInfo(info->netbios_domain, &domain);
  2706. + wbc_status = wbcCtxDomainInfo(ctx, info->netbios_domain, &domain);
  2707. if (wbc_status == WBC_ERR_DOMAIN_NOT_FOUND) {
  2708. /* maybe it's a standalone server */
  2709. domain = NULL;
  2710. @@ -132,6 +143,11 @@ done:
  2711. return wbc_status;
  2712. }
  2713.  
  2714. +wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **_details)
  2715. +{
  2716. + return wbcCtxInterfaceDetails(NULL, _details);
  2717. +}
  2718. +
  2719. static void wbcDomainInfoDestructor(void *ptr)
  2720. {
  2721. struct wbcDomainInfo *i = (struct wbcDomainInfo *)ptr;
  2722. @@ -147,7 +163,9 @@ static void wbcDomainInfoDestructor(void *ptr)
  2723. * @return #wbcErr
  2724. */
  2725.  
  2726. -wbcErr wbcDomainInfo(const char *domain, struct wbcDomainInfo **dinfo)
  2727. +wbcErr wbcCtxDomainInfo(struct wbcContext *ctx,
  2728. + const char *domain,
  2729. + struct wbcDomainInfo **dinfo)
  2730. {
  2731. struct winbindd_request request;
  2732. struct winbindd_response response;
  2733. @@ -167,7 +185,7 @@ wbcErr wbcDomainInfo(const char *domain, struct wbcDomainInfo **dinfo)
  2734. strncpy(request.domain_name, domain,
  2735. sizeof(request.domain_name)-1);
  2736.  
  2737. - wbc_status = wbcRequestResponse(WINBINDD_DOMAIN_INFO,
  2738. + wbc_status = wbcRequestResponse(ctx, WINBINDD_DOMAIN_INFO,
  2739. &request,
  2740. &response);
  2741. BAIL_ON_WBC_ERROR(wbc_status);
  2742. @@ -203,9 +221,15 @@ wbcErr wbcDomainInfo(const char *domain, struct wbcDomainInfo **dinfo)
  2743. return wbc_status;
  2744. }
  2745.  
  2746. +wbcErr wbcDomainInfo(const char *domain, struct wbcDomainInfo **dinfo)
  2747. +{
  2748. + return wbcCtxDomainInfo(NULL, domain, dinfo);
  2749. +}
  2750. +
  2751. /* Get the list of current DCs */
  2752. -wbcErr wbcDcInfo(const char *domain, size_t *num_dcs,
  2753. - const char ***dc_names, const char ***dc_ips)
  2754. +wbcErr wbcCtxDcInfo(struct wbcContext *ctx,
  2755. + const char *domain, size_t *num_dcs,
  2756. + const char ***dc_names, const char ***dc_ips)
  2757. {
  2758. struct winbindd_request request;
  2759. struct winbindd_response response;
  2760. @@ -226,7 +250,7 @@ wbcErr wbcDcInfo(const char *domain, size_t *num_dcs,
  2761. sizeof(request.domain_name) - 1);
  2762. }
  2763.  
  2764. - wbc_status = wbcRequestResponse(WINBINDD_DC_INFO,
  2765. + wbc_status = wbcRequestResponse(ctx, WINBINDD_DC_INFO,
  2766. &request, &response);
  2767. BAIL_ON_WBC_ERROR(wbc_status);
  2768.  
  2769. @@ -290,8 +314,15 @@ done:
  2770. return wbc_status;
  2771. }
  2772.  
  2773. +wbcErr wbcDcInfo(const char *domain, size_t *num_dcs,
  2774. + const char ***dc_names, const char ***dc_ips)
  2775. +{
  2776. + return wbcCtxDcInfo(NULL, domain, num_dcs, dc_names, dc_ips);
  2777. +}
  2778. +
  2779. /* Resolve a NetbiosName via WINS */
  2780. -wbcErr wbcResolveWinsByName(const char *name, char **ip)
  2781. +wbcErr wbcCtxResolveWinsByName(struct wbcContext *ctx,
  2782. + const char *name, char **ip)
  2783. {
  2784. struct winbindd_request request;
  2785. struct winbindd_response response;
  2786. @@ -306,7 +337,7 @@ wbcErr wbcResolveWinsByName(const char *name, char **ip)
  2787. strncpy(request.data.winsreq, name,
  2788. sizeof(request.data.winsreq)-1);
  2789.  
  2790. - wbc_status = wbcRequestResponse(WINBINDD_WINS_BYNAME,
  2791. + wbc_status = wbcRequestResponse(ctx, WINBINDD_WINS_BYNAME,
  2792. &request,
  2793. &response);
  2794. BAIL_ON_WBC_ERROR(wbc_status);
  2795. @@ -323,8 +354,14 @@ wbcErr wbcResolveWinsByName(const char *name, char **ip)
  2796. return wbc_status;
  2797. }
  2798.  
  2799. +wbcErr wbcResolveWinsByName(const char *name, char **ip)
  2800. +{
  2801. + return wbcCtxResolveWinsByName(NULL, name, ip);
  2802. +}
  2803. +
  2804. /* Resolve an IP address via WINS into a NetbiosName */
  2805. -wbcErr wbcResolveWinsByIP(const char *ip, char **name)
  2806. +wbcErr wbcCtxResolveWinsByIP(struct wbcContext *ctx,
  2807. + const char *ip, char **name)
  2808. {
  2809. struct winbindd_request request;
  2810. struct winbindd_response response;
  2811. @@ -339,7 +376,7 @@ wbcErr wbcResolveWinsByIP(const char *ip, char **name)
  2812. strncpy(request.data.winsreq, ip,
  2813. sizeof(request.data.winsreq)-1);
  2814.  
  2815. - wbc_status = wbcRequestResponse(WINBINDD_WINS_BYIP,
  2816. + wbc_status = wbcRequestResponse(ctx, WINBINDD_WINS_BYIP,
  2817. &request,
  2818. &response);
  2819. BAIL_ON_WBC_ERROR(wbc_status);
  2820. @@ -356,6 +393,11 @@ wbcErr wbcResolveWinsByIP(const char *ip, char **name)
  2821. return wbc_status;
  2822. }
  2823.  
  2824. +wbcErr wbcResolveWinsByIP(const char *ip, char **name)
  2825. +{
  2826. + return wbcCtxResolveWinsByIP(NULL, ip, name);
  2827. +}
  2828. +
  2829. /**
  2830. */
  2831.  
  2832. @@ -489,7 +531,8 @@ static void wbcDomainInfoListDestructor(void *ptr)
  2833. }
  2834.  
  2835. /* Enumerate the domain trusts known by Winbind */
  2836. -wbcErr wbcListTrusts(struct wbcDomainInfo **domains, size_t *num_domains)
  2837. +wbcErr wbcCtxListTrusts(struct wbcContext *ctx,
  2838. + struct wbcDomainInfo **domains, size_t *num_domains)
  2839. {
  2840. struct winbindd_response response;
  2841. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2842. @@ -505,7 +548,7 @@ wbcErr wbcListTrusts(struct wbcDomainInfo **domains, size_t *num_domains)
  2843.  
  2844. /* Send request */
  2845.  
  2846. - wbc_status = wbcRequestResponse(WINBINDD_LIST_TRUSTDOM,
  2847. + wbc_status = wbcRequestResponse(ctx, WINBINDD_LIST_TRUSTDOM,
  2848. NULL,
  2849. &response);
  2850. BAIL_ON_WBC_ERROR(wbc_status);
  2851. @@ -559,6 +602,11 @@ wbcErr wbcListTrusts(struct wbcDomainInfo **domains, size_t *num_domains)
  2852. return wbc_status;
  2853. }
  2854.  
  2855. +wbcErr wbcListTrusts(struct wbcDomainInfo **domains, size_t *num_domains)
  2856. +{
  2857. + return wbcCtxListTrusts(NULL, domains, num_domains);
  2858. +}
  2859. +
  2860. static void wbcDomainControllerInfoDestructor(void *ptr)
  2861. {
  2862. struct wbcDomainControllerInfo *i =
  2863. @@ -567,9 +615,9 @@ static void wbcDomainControllerInfoDestructor(void *ptr)
  2864. }
  2865.  
  2866. /* Enumerate the domain trusts known by Winbind */
  2867. -wbcErr wbcLookupDomainController(const char *domain,
  2868. - uint32_t flags,
  2869. - struct wbcDomainControllerInfo **dc_info)
  2870. +wbcErr wbcCtxLookupDomainController(struct wbcContext *ctx,
  2871. + const char *domain, uint32_t flags,
  2872. + struct wbcDomainControllerInfo **dc_info)
  2873. {
  2874. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2875. struct winbindd_request request;
  2876. @@ -598,7 +646,7 @@ wbcErr wbcLookupDomainController(const char *domain,
  2877.  
  2878. /* Send request */
  2879.  
  2880. - wbc_status = wbcRequestResponse(WINBINDD_DSGETDCNAME,
  2881. + wbc_status = wbcRequestResponse(ctx, WINBINDD_DSGETDCNAME,
  2882. &request,
  2883. &response);
  2884. BAIL_ON_WBC_ERROR(wbc_status);
  2885. @@ -614,6 +662,12 @@ done:
  2886. return wbc_status;
  2887. }
  2888.  
  2889. +wbcErr wbcLookupDomainController(const char *domain, uint32_t flags,
  2890. + struct wbcDomainControllerInfo **dc_info)
  2891. +{
  2892. + return wbcCtxLookupDomainController(NULL, domain, flags, dc_info);
  2893. +}
  2894. +
  2895. static void wbcDomainControllerInfoExDestructor(void *ptr)
  2896. {
  2897. struct wbcDomainControllerInfoEx *i =
  2898. @@ -688,11 +742,12 @@ done:
  2899. }
  2900.  
  2901. /* Get extended domain controller information */
  2902. -wbcErr wbcLookupDomainControllerEx(const char *domain,
  2903. - struct wbcGuid *guid,
  2904. - const char *site,
  2905. - uint32_t flags,
  2906. - struct wbcDomainControllerInfoEx **dc_info)
  2907. +wbcErr wbcCtxLookupDomainControllerEx(struct wbcContext *ctx,
  2908. + const char *domain,
  2909. + struct wbcGuid *guid,
  2910. + const char *site,
  2911. + uint32_t flags,
  2912. + struct wbcDomainControllerInfoEx **dc_info)
  2913. {
  2914. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  2915. struct winbindd_request request;
  2916. @@ -732,7 +787,7 @@ wbcErr wbcLookupDomainControllerEx(const char *domain,
  2917.  
  2918. /* Send request */
  2919.  
  2920. - wbc_status = wbcRequestResponse(WINBINDD_DSGETDCNAME,
  2921. + wbc_status = wbcRequestResponse(ctx, WINBINDD_DSGETDCNAME,
  2922. &request,
  2923. &response);
  2924. BAIL_ON_WBC_ERROR(wbc_status);
  2925. @@ -748,6 +803,16 @@ done:
  2926. return wbc_status;
  2927. }
  2928.  
  2929. +wbcErr wbcLookupDomainControllerEx(const char *domain,
  2930. + struct wbcGuid *guid,
  2931. + const char *site,
  2932. + uint32_t flags,
  2933. + struct wbcDomainControllerInfoEx **dc_info)
  2934. +{
  2935. + return wbcCtxLookupDomainControllerEx(NULL, domain, guid, site,
  2936. + flags, dc_info);
  2937. +}
  2938. +
  2939. static void wbcNamedBlobDestructor(void *ptr)
  2940. {
  2941. struct wbcNamedBlob *b = (struct wbcNamedBlob *)ptr;
  2942. diff --git a/nsswitch/libwbclient/wbclient.h b/nsswitch/libwbclient/wbclient.h
  2943. index 265cf43..6aa4e12 100644
  2944. --- a/nsswitch/libwbclient/wbclient.h
  2945. +++ b/nsswitch/libwbclient/wbclient.h
  2946. @@ -630,12 +630,23 @@ wbcErr wbcStringToGuid(const char *guid_string,
  2947. /**
  2948. * @brief Ping winbindd to see if the daemon is running
  2949. *
  2950. + * @param *ctx wbclient Context
  2951. + *
  2952. + * @return #wbcErr
  2953. + **/
  2954. +wbcErr wbcCtxPing(struct wbcContext *ctx);
  2955. +
  2956. +/**
  2957. + * @brief Ping winbindd to see if the daemon is running
  2958. + *
  2959. * @return #wbcErr
  2960. **/
  2961. wbcErr wbcPing(void);
  2962.  
  2963. wbcErr wbcLibraryDetails(struct wbcLibraryDetails **details);
  2964.  
  2965. +wbcErr wbcCtxInterfaceDetails(struct wbcContext *ctx,
  2966. + struct wbcInterfaceDetails **details);
  2967. wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **details);
  2968.  
  2969. /**********************************************************
  2970. @@ -645,6 +656,23 @@ wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **details);
  2971. /**
  2972. * @brief Convert a domain and name to SID
  2973. *
  2974. + * @param *ctx wbclient Context
  2975. + * @param dom_name Domain name (possibly "")
  2976. + * @param name User or group name
  2977. + * @param *sid Pointer to the resolved domain SID
  2978. + * @param *name_type Pointer to the SID type
  2979. + *
  2980. + * @return #wbcErr
  2981. + **/
  2982. +wbcErr wbcCtxLookupName(struct wbcContext *ctx,
  2983. + const char *dom_name,
  2984. + const char *name,
  2985. + struct wbcDomainSid *sid,
  2986. + enum wbcSidType *name_type);
  2987. +
  2988. +/**
  2989. + * @brief Convert a domain and name to SID
  2990. + *
  2991. * @param dom_name Domain name (possibly "")
  2992. * @param name User or group name
  2993. * @param *sid Pointer to the resolved domain SID
  2994. @@ -660,7 +688,24 @@ wbcErr wbcLookupName(const char *dom_name,
  2995. /**
  2996. * @brief Convert a SID to a domain and name
  2997. *
  2998. - * @param *sid Pointer to the domain SID to be resolved
  2999. + * @param *ctx wbclient Context
  3000. + * @param *sid Pointer to the domain SID to be resolved
  3001. + * @param domain Resolved Domain name (possibly "")
  3002. + * @param name Resolved User or group name
  3003. + * @param *name_type Pointer to the resolved SID type
  3004. + *
  3005. + * @return #wbcErr
  3006. + **/
  3007. +wbcErr wbcCtxLookupSid(struct wbcContext *ctx,
  3008. + const struct wbcDomainSid *sid,
  3009. + char **domain,
  3010. + char **name,
  3011. + enum wbcSidType *name_type);
  3012. +
  3013. +/**
  3014. + * @brief Convert a SID to a domain and name
  3015. + *
  3016. + * @param *sid Pointer to the domain SID to be resolved
  3017. * @param domain Resolved Domain name (possibly "")
  3018. * @param name Resolved User or group name
  3019. * @param *name_type Pointer to the resolved SID type
  3020. @@ -678,6 +723,11 @@ struct wbcTranslatedName {
  3021. int domain_index;
  3022. };
  3023.  
  3024. +wbcErr wbcCtxLookupSids(struct wbcContext *ctx,
  3025. + const struct wbcDomainSid *sids, int num_sids,
  3026. + struct wbcDomainInfo **domains, int *num_domains,
  3027. + struct wbcTranslatedName **names);
  3028. +
  3029. wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids,
  3030. struct wbcDomainInfo **domains, int *num_domains,
  3031. struct wbcTranslatedName **names);
  3032. @@ -685,6 +735,17 @@ wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids,
  3033. /**
  3034. * @brief Translate a collection of RIDs within a domain to names
  3035. */
  3036. +wbcErr wbcCtxLookupRids(struct wbcContext *ctx,
  3037. + struct wbcDomainSid *dom_sid,
  3038. + int num_rids,
  3039. + uint32_t *rids,
  3040. + const char **domain_name,
  3041. + const char ***names,
  3042. + enum wbcSidType **types);
  3043. +
  3044. +/**
  3045. + * @brief Translate a collection of RIDs within a domain to names
  3046. + */
  3047. wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
  3048. int num_rids,
  3049. uint32_t *rids,
  3050. @@ -695,6 +756,15 @@ wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
  3051. /*
  3052. * @brief Get the groups a user belongs to
  3053. **/
  3054. +wbcErr wbcCtxLookupUserSids(struct wbcContext *ctx,
  3055. + const struct wbcDomainSid *user_sid,
  3056. + bool domain_groups_only,
  3057. + uint32_t *num_sids,
  3058. + struct wbcDomainSid **sids);
  3059. +
  3060. +/*
  3061. + * @brief Get the groups a user belongs to
  3062. + **/
  3063. wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
  3064. bool domain_groups_only,
  3065. uint32_t *num_sids,
  3066. @@ -703,6 +773,16 @@ wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
  3067. /*
  3068. * @brief Get alias membership for sids
  3069. **/
  3070. +wbcErr wbcCtxGetSidAliases(struct wbcContext *ctx,
  3071. + const struct wbcDomainSid *dom_sid,
  3072. + struct wbcDomainSid *sids,
  3073. + uint32_t num_sids,
  3074. + uint32_t **alias_rids,
  3075. + uint32_t *num_alias_rids);
  3076. +
  3077. +/*
  3078. + * @brief Get alias membership for sids
  3079. + **/
  3080. wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
  3081. struct wbcDomainSid *sids,
  3082. uint32_t num_sids,
  3083. @@ -712,6 +792,14 @@ wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
  3084. /**
  3085. * @brief Lists Users
  3086. **/
  3087. +wbcErr wbcCtxListUsers(struct wbcContext *ctx,
  3088. + const char *domain_name,
  3089. + uint32_t *num_users,
  3090. + const char ***users);
  3091. +
  3092. +/**
  3093. + * @brief Lists Users
  3094. + **/
  3095. wbcErr wbcListUsers(const char *domain_name,
  3096. uint32_t *num_users,
  3097. const char ***users);
  3098. @@ -719,10 +807,24 @@ wbcErr wbcListUsers(const char *domain_name,
  3099. /**
  3100. * @brief Lists Groups
  3101. **/
  3102. +wbcErr wbcCtxListGroups(struct wbcContext *ctx,
  3103. + const char *domain_name,
  3104. + uint32_t *num_groups,
  3105. + const char ***groups);
  3106. +
  3107. +/**
  3108. + * @brief Lists Groups
  3109. + **/
  3110. wbcErr wbcListGroups(const char *domain_name,
  3111. uint32_t *num_groups,
  3112. const char ***groups);
  3113.  
  3114. +wbcErr wbcCtxGetDisplayName(struct wbcContext *ctx,
  3115. + const struct wbcDomainSid *sid,
  3116. + char **pdomain,
  3117. + char **pfullname,
  3118. + enum wbcSidType *pname_type);
  3119. +
  3120. wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
  3121. char **pdomain,
  3122. char **pfullname,
  3123. @@ -735,6 +837,20 @@ wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
  3124. /**
  3125. * @brief Convert a Windows SID to a Unix uid, allocating an uid if needed
  3126. *
  3127. + * @param *ctx wbclient Context
  3128. + * @param *sid Pointer to the domain SID to be resolved
  3129. + * @param *puid Pointer to the resolved uid_t value
  3130. + *
  3131. + * @return #wbcErr
  3132. + *
  3133. + **/
  3134. +wbcErr wbcCtxSidToUid(struct wbcContext *ctx,
  3135. + const struct wbcDomainSid *sid,
  3136. + uid_t *puid);
  3137. +
  3138. +/**
  3139. + * @brief Convert a Windows SID to a Unix uid, allocating an uid if needed
  3140. + *
  3141. * @param *sid Pointer to the domain SID to be resolved
  3142. * @param *puid Pointer to the resolved uid_t value
  3143. *
  3144. @@ -759,6 +875,19 @@ wbcErr wbcQuerySidToUid(const struct wbcDomainSid *sid,
  3145. /**
  3146. * @brief Convert a Unix uid to a Windows SID, allocating a SID if needed
  3147. *
  3148. + * @param *ctx wbclient Context
  3149. + * @param uid Unix uid to be resolved
  3150. + * @param *sid Pointer to the resolved domain SID
  3151. + *
  3152. + * @return #wbcErr
  3153. + *
  3154. + **/
  3155. +wbcErr wbcCtxUidToSid(struct wbcContext *ctx, uid_t uid,
  3156. + struct wbcDomainSid *sid);
  3157. +
  3158. +/**
  3159. + * @brief Convert a Unix uid to a Windows SID, allocating a SID if needed
  3160. + *
  3161. * @param uid Unix uid to be resolved
  3162. * @param *sid Pointer to the resolved domain SID
  3163. *
  3164. @@ -783,6 +912,20 @@ wbcErr wbcQueryUidToSid(uid_t uid,
  3165. /**
  3166. * @brief Convert a Windows SID to a Unix gid, allocating a gid if needed
  3167. *
  3168. + * @param *ctx wbclient Context
  3169. + * @param *sid Pointer to the domain SID to be resolved
  3170. + * @param *pgid Pointer to the resolved gid_t value
  3171. + *
  3172. + * @return #wbcErr
  3173. + *
  3174. + **/
  3175. +wbcErr wbcCtxSidToGid(struct wbcContext *ctx,
  3176. + const struct wbcDomainSid *sid,
  3177. + gid_t *pgid);
  3178. +
  3179. +/**
  3180. + * @brief Convert a Windows SID to a Unix gid, allocating a gid if needed
  3181. + *
  3182. * @param *sid Pointer to the domain SID to be resolved
  3183. * @param *pgid Pointer to the resolved gid_t value
  3184. *
  3185. @@ -807,6 +950,19 @@ wbcErr wbcQuerySidToGid(const struct wbcDomainSid *sid,
  3186. /**
  3187. * @brief Convert a Unix gid to a Windows SID, allocating a SID if needed
  3188. *
  3189. + * @param *ctx wbclient Context
  3190. + * @param gid Unix gid to be resolved
  3191. + * @param *sid Pointer to the resolved domain SID
  3192. + *
  3193. + * @return #wbcErr
  3194. + *
  3195. + **/
  3196. +wbcErr wbcCtxGidToSid(struct wbcContext *ctx, gid_t gid,
  3197. + struct wbcDomainSid *sid);
  3198. +
  3199. +/**
  3200. + * @brief Convert a Unix gid to a Windows SID, allocating a SID if needed
  3201. + *
  3202. * @param gid Unix gid to be resolved
  3203. * @param *sid Pointer to the resolved domain SID
  3204. *
  3205. @@ -848,6 +1004,21 @@ struct wbcUnixId {
  3206. /**
  3207. * @brief Convert a list of sids to unix ids
  3208. *
  3209. + * @param *ctx wbclient Context
  3210. + * @param sids Pointer to an array of SIDs to convert
  3211. + * @param num_sids Number of SIDs
  3212. + * @param ids Preallocated output array for translated IDs
  3213. + *
  3214. + * @return #wbcErr
  3215. + *
  3216. + **/
  3217. +wbcErr wbcCtxSidsToUnixIds(struct wbcContext *ctx,
  3218. + const struct wbcDomainSid *sids, uint32_t num_sids,
  3219. + struct wbcUnixId *ids);
  3220. +
  3221. +/**
  3222. + * @brief Convert a list of sids to unix ids
  3223. + *
  3224. * @param sids Pointer to an array of SIDs to convert
  3225. * @param num_sids Number of SIDs
  3226. * @param ids Preallocated output array for translated IDs
  3227. @@ -861,7 +1032,17 @@ wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids,
  3228. /**
  3229. * @brief Obtain a new uid from Winbind
  3230. *
  3231. - * @param *puid *pointer to the allocated uid
  3232. + * @param *ctx wbclient Context
  3233. + * @param *puid Pointer to the allocated uid
  3234. + *
  3235. + * @return #wbcErr
  3236. + **/
  3237. +wbcErr wbcCtxAllocateUid(struct wbcContext *ctx, uid_t *puid);
  3238. +
  3239. +/**
  3240. + * @brief Obtain a new uid from Winbind
  3241. + *
  3242. + * @param *puid Pointer to the allocated uid
  3243. *
  3244. * @return #wbcErr
  3245. **/
  3246. @@ -870,7 +1051,17 @@ wbcErr wbcAllocateUid(uid_t *puid);
  3247. /**
  3248. * @brief Obtain a new gid from Winbind
  3249. *
  3250. - * @param *pgid Pointer to the allocated gid
  3251. + * @param *ctx wbclient Context
  3252. + * @param *pgid Pointer to the allocated gid
  3253. + *
  3254. + * @return #wbcErr
  3255. + **/
  3256. +wbcErr wbcCtxAllocateGid(struct wbcContext *ctx, gid_t *pgid);
  3257. +
  3258. +/**
  3259. + * @brief Obtain a new gid from Winbind
  3260. + *
  3261. + * @param *pgid Pointer to the allocated gid
  3262. *
  3263. * @return #wbcErr
  3264. **/
  3265. @@ -960,6 +1151,19 @@ wbcErr wbcSetGidHwm(gid_t gid_hwm);
  3266. * @brief Fill in a struct passwd* for a domain user based
  3267. * on username
  3268. *
  3269. + * @param *ctx wbclient Context
  3270. + * @param *name Username to lookup
  3271. + * @param **pwd Pointer to resulting struct passwd* from the query.
  3272. + *
  3273. + * @return #wbcErr
  3274. + **/
  3275. +wbcErr wbcCtxGetpwnam(struct wbcContext *ctx,
  3276. + const char *name, struct passwd **pwd);
  3277. +
  3278. +/**
  3279. + * @brief Fill in a struct passwd* for a domain user based
  3280. + * on username
  3281. + *
  3282. * @param *name Username to lookup
  3283. * @param **pwd Pointer to resulting struct passwd* from the query.
  3284. *
  3285. @@ -971,6 +1175,19 @@ wbcErr wbcGetpwnam(const char *name, struct passwd **pwd);
  3286. * @brief Fill in a struct passwd* for a domain user based
  3287. * on uid
  3288. *
  3289. + * @param *ctx wbclient Context
  3290. + * @param uid Uid to lookup
  3291. + * @param **pwd Pointer to resulting struct passwd* from the query.
  3292. + *
  3293. + * @return #wbcErr
  3294. + **/
  3295. +wbcErr wbcCtxGetpwuid(struct wbcContext *ctx,
  3296. + uid_t uid, struct passwd **pwd);
  3297. +
  3298. +/**
  3299. + * @brief Fill in a struct passwd* for a domain user based
  3300. + * on uid
  3301. + *
  3302. * @param uid Uid to lookup
  3303. * @param **pwd Pointer to resulting struct passwd* from the query.
  3304. *
  3305. @@ -982,6 +1199,19 @@ wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd);
  3306. * @brief Fill in a struct passwd* for a domain user based
  3307. * on sid
  3308. *
  3309. + * @param *ctx wbclient Context
  3310. + * @param sid Sid to lookup
  3311. + * @param **pwd Pointer to resulting struct passwd* from the query.
  3312. + *
  3313. + * @return #wbcErr
  3314. + **/
  3315. +wbcErr wbcCtxGetpwsid(struct wbcContext *ctx,
  3316. + struct wbcDomainSid * sid, struct passwd **pwd);
  3317. +
  3318. +/**
  3319. + * @brief Fill in a struct passwd* for a domain user based
  3320. + * on sid
  3321. + *
  3322. * @param sid Sid to lookup
  3323. * @param **pwd Pointer to resulting struct passwd* from the query.
  3324. *
  3325. @@ -993,6 +1223,19 @@ wbcErr wbcGetpwsid(struct wbcDomainSid * sid, struct passwd **pwd);
  3326. * @brief Fill in a struct passwd* for a domain user based
  3327. * on username
  3328. *
  3329. + * @param *ctx wbclient Context
  3330. + * @param *name Username to lookup
  3331. + * @param **grp Pointer to resulting struct group* from the query.
  3332. + *
  3333. + * @return #wbcErr
  3334. + **/
  3335. +wbcErr wbcCtxGetgrnam(struct wbcContext *ctx,
  3336. + const char *name, struct group **grp);
  3337. +
  3338. +/**
  3339. + * @brief Fill in a struct passwd* for a domain user based
  3340. + * on username
  3341. + *
  3342. * @param *name Username to lookup
  3343. * @param **grp Pointer to resulting struct group* from the query.
  3344. *
  3345. @@ -1004,6 +1247,19 @@ wbcErr wbcGetgrnam(const char *name, struct group **grp);
  3346. * @brief Fill in a struct passwd* for a domain user based
  3347. * on uid
  3348. *
  3349. + * @param *ctx wbclient Context
  3350. + * @param gid Uid to lookup
  3351. + * @param **grp Pointer to resulting struct group* from the query.
  3352. + *
  3353. + * @return #wbcErr
  3354. + **/
  3355. +wbcErr wbcCtxGetgrgid(struct wbcContext *ctx,
  3356. + gid_t gid, struct group **grp);
  3357. +
  3358. +/**
  3359. + * @brief Fill in a struct passwd* for a domain user based
  3360. + * on uid
  3361. + *
  3362. * @param gid Uid to lookup
  3363. * @param **grp Pointer to resulting struct group* from the query.
  3364. *
  3365. @@ -1014,6 +1270,15 @@ wbcErr wbcGetgrgid(gid_t gid, struct group **grp);
  3366. /**
  3367. * @brief Reset the passwd iterator
  3368. *
  3369. + * @param *ctx wbclient Context
  3370. + *
  3371. + * @return #wbcErr
  3372. + **/
  3373. +wbcErr wbcCtxSetpwent(struct wbcContext *ctx);
  3374. +
  3375. +/**
  3376. + * @brief Reset the passwd iterator
  3377. + *
  3378. * @return #wbcErr
  3379. **/
  3380. wbcErr wbcSetpwent(void);
  3381. @@ -1021,6 +1286,15 @@ wbcErr wbcSetpwent(void);
  3382. /**
  3383. * @brief Close the passwd iterator
  3384. *
  3385. + * @param *ctx wbclient Context
  3386. + *
  3387. + * @return #wbcErr
  3388. + **/
  3389. +wbcErr wbcCtxEndpwent(struct wbcContext *ctx);
  3390. +
  3391. +/**
  3392. + * @brief Close the passwd iterator
  3393. + *
  3394. * @return #wbcErr
  3395. **/
  3396. wbcErr wbcEndpwent(void);
  3397. @@ -1028,7 +1302,17 @@ wbcErr wbcEndpwent(void);
  3398. /**
  3399. * @brief Return the next struct passwd* entry from the pwent iterator
  3400. *
  3401. - * @param **pwd Pointer to resulting struct passwd* from the query.
  3402. + * @param *ctx wbclient Context
  3403. + * @param **pwd Pointer to resulting struct passwd* from the query.
  3404. + *
  3405. + * @return #wbcErr
  3406. + **/
  3407. +wbcErr wbcCtxGetpwent(struct wbcContext *ctx, struct passwd **pwd);
  3408. +
  3409. +/**
  3410. + * @brief Return the next struct passwd* entry from the pwent iterator
  3411. + *
  3412. + * @param **pwd Pointer to resulting struct passwd* from the query.
  3413. *
  3414. * @return #wbcErr
  3415. **/
  3416. @@ -1037,6 +1321,15 @@ wbcErr wbcGetpwent(struct passwd **pwd);
  3417. /**
  3418. * @brief Reset the group iterator
  3419. *
  3420. + * @param *ctx wbclient Context
  3421. + *
  3422. + * @return #wbcErr
  3423. + **/
  3424. +wbcErr wbcCtxSetgrent(struct wbcContext *ctx);
  3425. +
  3426. +/**
  3427. + * @brief Reset the group iterator
  3428. + *
  3429. * @return #wbcErr
  3430. **/
  3431. wbcErr wbcSetgrent(void);
  3432. @@ -1044,6 +1337,15 @@ wbcErr wbcSetgrent(void);
  3433. /**
  3434. * @brief Close the group iterator
  3435. *
  3436. + * @param *ctx wbclient Context
  3437. + *
  3438. + * @return #wbcErr
  3439. + **/
  3440. +wbcErr wbcCtxEndgrent(struct wbcContext *ctx);
  3441. +
  3442. +/**
  3443. + * @brief Close the group iterator
  3444. + *
  3445. * @return #wbcErr
  3446. **/
  3447. wbcErr wbcEndgrent(void);
  3448. @@ -1051,7 +1353,17 @@ wbcErr wbcEndgrent(void);
  3449. /**
  3450. * @brief Return the next struct group* entry from the pwent iterator
  3451. *
  3452. - * @param **grp Pointer to resulting struct group* from the query.
  3453. + * @param *ctx wbclient Context
  3454. + * @param **grp Pointer to resulting struct group* from the query.
  3455. + *
  3456. + * @return #wbcErr
  3457. + **/
  3458. +wbcErr wbcCtxGetgrent(struct wbcContext *ctx, struct group **grp);
  3459. +
  3460. +/**
  3461. + * @brief Return the next struct group* entry from the pwent iterator
  3462. + *
  3463. + * @param **grp Pointer to resulting struct group* from the query.
  3464. *
  3465. * @return #wbcErr
  3466. **/
  3467. @@ -1062,7 +1374,19 @@ wbcErr wbcGetgrent(struct group **grp);
  3468. *
  3469. * This is similar to #wbcGetgrent, just that the member list is empty
  3470. *
  3471. - * @param **grp Pointer to resulting struct group* from the query.
  3472. + * @param *ctx wbclient Context
  3473. + * @param **grp Pointer to resulting struct group* from the query.
  3474. + *
  3475. + * @return #wbcErr
  3476. + **/
  3477. +wbcErr wbcCtxGetgrlist(struct wbcContext *ctx, struct group **grp);
  3478. +
  3479. +/**
  3480. + * @brief Return the next struct group* entry from the pwent iterator
  3481. + *
  3482. + * This is similar to #wbcGetgrent, just that the member list is empty
  3483. + *
  3484. + * @param **grp Pointer to resulting struct group* from the query.
  3485. *
  3486. * @return #wbcErr
  3487. **/
  3488. @@ -1071,6 +1395,21 @@ wbcErr wbcGetgrlist(struct group **grp);
  3489. /**
  3490. * @brief Return the unix group array belonging to the given user
  3491. *
  3492. + * @param *ctx wbclient Context
  3493. + * @param *account The given user name
  3494. + * @param *num_groups Number of elements returned in the groups array
  3495. + * @param **_groups Pointer to resulting gid_t array.
  3496. + *
  3497. + * @return #wbcErr
  3498. + **/
  3499. +wbcErr wbcCtxGetGroups(struct wbcContext *ctx,
  3500. + const char *account,
  3501. + uint32_t *num_groups,
  3502. + gid_t **_groups);
  3503. +
  3504. +/**
  3505. + * @brief Return the unix group array belonging to the given user
  3506. + *
  3507. * @param *account The given user name
  3508. * @param *num_groups Number of elements returned in the groups array
  3509. * @param **_groups Pointer to resulting gid_t array.
  3510. @@ -1089,7 +1428,21 @@ wbcErr wbcGetGroups(const char *account,
  3511. /**
  3512. * @brief Lookup the current status of a trusted domain
  3513. *
  3514. - * @param domain The domain to query
  3515. + * @param *ctx wbclient Context
  3516. + * @param domain The domain to query
  3517. + *
  3518. + * @param dinfo A pointer to store the returned domain_info struct.
  3519. + *
  3520. + * @return #wbcErr
  3521. + **/
  3522. +wbcErr wbcCtxDomainInfo(struct wbcContext *ctx,
  3523. + const char *domain,
  3524. + struct wbcDomainInfo **dinfo);
  3525. +
  3526. +/**
  3527. + * @brief Lookup the current status of a trusted domain
  3528. + *
  3529. + * @param domain The domain to query
  3530. *
  3531. * @param dinfo A pointer to store the returned domain_info struct.
  3532. *
  3533. @@ -1101,6 +1454,22 @@ wbcErr wbcDomainInfo(const char *domain,
  3534. /**
  3535. * @brief Lookup the currently contacted DCs
  3536. *
  3537. + * @param *ctx wbclient Context
  3538. + * @param domain The domain to query
  3539. + *
  3540. + * @param num_dcs Number of DCs currently known
  3541. + * @param dc_names Names of the currently known DCs
  3542. + * @param dc_ips IP addresses of the currently known DCs
  3543. + *
  3544. + * @return #wbcErr
  3545. + **/
  3546. +wbcErr wbcCtxDcInfo(struct wbcContext *ctx,
  3547. + const char *domain, size_t *num_dcs,
  3548. + const char ***dc_names, const char ***dc_ips);
  3549. +
  3550. +/**
  3551. + * @brief Lookup the currently contacted DCs
  3552. + *
  3553. * @param domain The domain to query
  3554. *
  3555. * @param num_dcs Number of DCs currently known
  3556. @@ -1115,6 +1484,19 @@ wbcErr wbcDcInfo(const char *domain, size_t *num_dcs,
  3557. /**
  3558. * @brief Enumerate the domain trusts known by Winbind
  3559. *
  3560. + * @param *ctx wbclient Context
  3561. + * @param **domains Pointer to the allocated domain list array
  3562. + * @param *num_domains Pointer to number of domains returned
  3563. + *
  3564. + * @return #wbcErr
  3565. + **/
  3566. +wbcErr wbcCtxListTrusts(struct wbcContext *ctx,
  3567. + struct wbcDomainInfo **domains,
  3568. + size_t *num_domains);
  3569. +
  3570. +/**
  3571. + * @brief Enumerate the domain trusts known by Winbind
  3572. + *
  3573. * @param **domains Pointer to the allocated domain list array
  3574. * @param *num_domains Pointer to number of domains returned
  3575. *
  3576. @@ -1148,6 +1530,21 @@ wbcErr wbcListTrusts(struct wbcDomainInfo **domains,
  3577. /**
  3578. * @brief Enumerate the domain trusts known by Winbind
  3579. *
  3580. + * @param *ctx wbclient Context
  3581. + * @param domain Name of the domain to query for a DC
  3582. + * @param flags Bit flags used to control the domain location query
  3583. + * @param *dc_info Pointer to the returned domain controller information
  3584. + *
  3585. + * @return #wbcErr
  3586. + **/
  3587. +wbcErr wbcCtxLookupDomainController(struct wbcContext *ctx,
  3588. + const char *domain,
  3589. + uint32_t flags,
  3590. + struct wbcDomainControllerInfo **dc_info);
  3591. +
  3592. +/**
  3593. + * @brief Enumerate the domain trusts known by Winbind
  3594. + *
  3595. * @param domain Name of the domain to query for a DC
  3596. * @param flags Bit flags used to control the domain location query
  3597. * @param *dc_info Pointer to the returned domain controller information
  3598. @@ -1161,6 +1558,25 @@ wbcErr wbcLookupDomainController(const char *domain,
  3599. /**
  3600. * @brief Get extended domain controller information
  3601. *
  3602. + * @param *ctx wbclient Context
  3603. + * @param domain Name of the domain to query for a DC
  3604. + * @param guid Guid of the domain to query for a DC
  3605. + * @param site Site of the domain to query for a DC
  3606. + * @param flags Bit flags used to control the domain location query
  3607. + * @param *dc_info Pointer to the returned extended domain controller information
  3608. + *
  3609. + * @return #wbcErr
  3610. + **/
  3611. +wbcErr wbcCtxLookupDomainControllerEx(struct wbcContext *ctx,
  3612. + const char *domain,
  3613. + struct wbcGuid *guid,
  3614. + const char *site,
  3615. + uint32_t flags,
  3616. + struct wbcDomainControllerInfoEx **dc_info);
  3617. +
  3618. +/**
  3619. + * @brief Get extended domain controller information
  3620. + *
  3621. * @param domain Name of the domain to query for a DC
  3622. * @param guid Guid of the domain to query for a DC
  3623. * @param site Site of the domain to query for a DC
  3624. @@ -1182,6 +1598,19 @@ wbcErr wbcLookupDomainControllerEx(const char *domain,
  3625. /**
  3626. * @brief Authenticate a username/password pair
  3627. *
  3628. + * @param *ctx wbclient Context
  3629. + * @param username Name of user to authenticate
  3630. + * @param password Clear text password os user
  3631. + *
  3632. + * @return #wbcErr
  3633. + **/
  3634. +wbcErr wbcCtxAuthenticateUser(struct wbcContext *ctx,
  3635. + const char *username,
  3636. + const char *password);
  3637. +
  3638. +/**
  3639. + * @brief Authenticate a username/password pair
  3640. + *
  3641. * @param username Name of user to authenticate
  3642. * @param password Clear text password os user
  3643. *
  3644. @@ -1193,6 +1622,22 @@ wbcErr wbcAuthenticateUser(const char *username,
  3645. /**
  3646. * @brief Authenticate with more detailed information
  3647. *
  3648. + * @param *ctx wbclient Context
  3649. + * @param params Input parameters, WBC_AUTH_USER_LEVEL_HASH
  3650. + * is not supported yet
  3651. + * @param info Output details on WBC_ERR_SUCCESS
  3652. + * @param error Output details on WBC_ERR_AUTH_ERROR
  3653. + *
  3654. + * @return #wbcErr
  3655. + **/
  3656. +wbcErr wbcCtxAuthenticateUserEx(struct wbcContext *ctx,
  3657. + const struct wbcAuthUserParams *params,
  3658. + struct wbcAuthUserInfo **info,
  3659. + struct wbcAuthErrorInfo **error);
  3660. +
  3661. +/**
  3662. + * @brief Authenticate with more detailed information
  3663. + *
  3664. * @param params Input parameters, WBC_AUTH_USER_LEVEL_HASH
  3665. * is not supported yet
  3666. * @param info Output details on WBC_ERR_SUCCESS
  3667. @@ -1207,6 +1652,23 @@ wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
  3668. /**
  3669. * @brief Logon a User
  3670. *
  3671. + * @param[in] *ctx wbclient Context
  3672. + * @param[in] params Pointer to a wbcLogonUserParams structure
  3673. + * @param[out] info Pointer to a pointer to a wbcLogonUserInfo structure
  3674. + * @param[out] error Pointer to a pointer to a wbcAuthErrorInfo structure
  3675. + * @param[out] policy Pointer to a pointer to a wbcUserPasswordPolicyInfo structure
  3676. + *
  3677. + * @return #wbcErr
  3678. + **/
  3679. +wbcErr wbcCtxLogonUser(struct wbcContext *ctx,
  3680. + const struct wbcLogonUserParams *params,
  3681. + struct wbcLogonUserInfo **info,
  3682. + struct wbcAuthErrorInfo **error,
  3683. + struct wbcUserPasswordPolicyInfo **policy);
  3684. +
  3685. +/**
  3686. + * @brief Logon a User
  3687. + *
  3688. * @param[in] params Pointer to a wbcLogonUserParams structure
  3689. * @param[out] info Pointer to a pointer to a wbcLogonUserInfo structure
  3690. * @param[out] error Pointer to a pointer to a wbcAuthErrorInfo structure
  3691. @@ -1222,6 +1684,22 @@ wbcErr wbcLogonUser(const struct wbcLogonUserParams *params,
  3692. /**
  3693. * @brief Trigger a logoff notification to Winbind for a specific user
  3694. *
  3695. + * @param *ctx wbclient Context
  3696. + * @param username Name of user to remove from Winbind's list of
  3697. + * logged on users.
  3698. + * @param uid Uid assigned to the username
  3699. + * @param ccfilename Absolute path to the Krb5 credentials cache to
  3700. + * be removed
  3701. + *
  3702. + * @return #wbcErr
  3703. + **/
  3704. +wbcErr wbcCtxLogoffUser(struct wbcContext *ctx,
  3705. + const char *username, uid_t uid,
  3706. + const char *ccfilename);
  3707. +
  3708. +/**
  3709. + * @brief Trigger a logoff notification to Winbind for a specific user
  3710. + *
  3711. * @param username Name of user to remove from Winbind's list of
  3712. * logged on users.
  3713. * @param uid Uid assigned to the username
  3714. @@ -1237,6 +1715,19 @@ wbcErr wbcLogoffUser(const char *username,
  3715. /**
  3716. * @brief Trigger an extended logoff notification to Winbind for a specific user
  3717. *
  3718. + * @param *ctx wbclient Context
  3719. + * @param params A wbcLogoffUserParams structure
  3720. + * @param error User output details on error
  3721. + *
  3722. + * @return #wbcErr
  3723. + **/
  3724. +wbcErr wbcCtxLogoffUserEx(struct wbcContext *ctx,
  3725. + const struct wbcLogoffUserParams *params,
  3726. + struct wbcAuthErrorInfo **error);
  3727. +
  3728. +/**
  3729. + * @brief Trigger an extended logoff notification to Winbind for a specific user
  3730. + *
  3731. * @param params A wbcLogoffUserParams structure
  3732. * @param error User output details on error
  3733. *
  3734. @@ -1248,6 +1739,21 @@ wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
  3735. /**
  3736. * @brief Change a password for a user
  3737. *
  3738. + * @param *ctx wbclient Context
  3739. + * @param username Name of user to authenticate
  3740. + * @param old_password Old clear text password of user
  3741. + * @param new_password New clear text password of user
  3742. + *
  3743. + * @return #wbcErr
  3744. + **/
  3745. +wbcErr wbcCtxChangeUserPassword(struct wbcContext *ctx,
  3746. + const char *username,
  3747. + const char *old_password,
  3748. + const char *new_password);
  3749. +
  3750. +/**
  3751. + * @brief Change a password for a user
  3752. + *
  3753. * @param username Name of user to authenticate
  3754. * @param old_password Old clear text password of user
  3755. * @param new_password New clear text password of user
  3756. @@ -1262,6 +1768,24 @@ wbcErr wbcChangeUserPassword(const char *username,
  3757. * @brief Change a password for a user with more detailed information upon
  3758. * failure
  3759. *
  3760. + * @param *ctx wbclient Context
  3761. + * @param params Input parameters
  3762. + * @param error User output details on WBC_ERR_PWD_CHANGE_FAILED
  3763. + * @param reject_reason New password reject reason on WBC_ERR_PWD_CHANGE_FAILED
  3764. + * @param policy Password policy output details on WBC_ERR_PWD_CHANGE_FAILED
  3765. + *
  3766. + * @return #wbcErr
  3767. + **/
  3768. +wbcErr wbcCtxChangeUserPasswordEx(struct wbcContext *ctx,
  3769. + const struct wbcChangePasswordParams *params,
  3770. + struct wbcAuthErrorInfo **error,
  3771. + enum wbcPasswordChangeRejectReason *reject_reason,
  3772. + struct wbcUserPasswordPolicyInfo **policy);
  3773. +
  3774. +/**
  3775. + * @brief Change a password for a user with more detailed information upon
  3776. + * failure
  3777. + *
  3778. * @param params Input parameters
  3779. * @param error User output details on WBC_ERR_PWD_CHANGE_FAILED
  3780. * @param reject_reason New password reject reason on WBC_ERR_PWD_CHANGE_FAILED
  3781. @@ -1277,6 +1801,21 @@ wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
  3782. /**
  3783. * @brief Authenticate a user with cached credentials
  3784. *
  3785. + * @param *ctx wbclient Context
  3786. + * @param *params Pointer to a wbcCredentialCacheParams structure
  3787. + * @param **info Pointer to a pointer to a wbcCredentialCacheInfo structure
  3788. + * @param **error Pointer to a pointer to a wbcAuthErrorInfo structure
  3789. + *
  3790. + * @return #wbcErr
  3791. + **/
  3792. +wbcErr wbcCtxCredentialCache(struct wbcContext *ctx,
  3793. + struct wbcCredentialCacheParams *params,
  3794. + struct wbcCredentialCacheInfo **info,
  3795. + struct wbcAuthErrorInfo **error);
  3796. +
  3797. +/**
  3798. + * @brief Authenticate a user with cached credentials
  3799. + *
  3800. * @param *params Pointer to a wbcCredentialCacheParams structure
  3801. * @param **info Pointer to a pointer to a wbcCredentialCacheInfo structure
  3802. * @param **error Pointer to a pointer to a wbcAuthErrorInfo structure
  3803. @@ -1290,6 +1829,18 @@ wbcErr wbcCredentialCache(struct wbcCredentialCacheParams *params,
  3804. /**
  3805. * @brief Save a password with winbind for doing wbcCredentialCache() later
  3806. *
  3807. + * @param *ctx wbclient Context
  3808. + * @param *user Username
  3809. + * @param *password Password
  3810. + *
  3811. + * @return #wbcErr
  3812. + **/
  3813. +wbcErr wbcCtxCredentialSave(struct wbcContext *ctx,
  3814. + const char *user, const char *password);
  3815. +
  3816. +/**
  3817. + * @brief Save a password with winbind for doing wbcCredentialCache() later
  3818. + *
  3819. * @param *user Username
  3820. * @param *password Password
  3821. *
  3822. @@ -1304,6 +1855,18 @@ wbcErr wbcCredentialSave(const char *user, const char *password);
  3823. /**
  3824. * @brief Resolve a NetbiosName via WINS
  3825. *
  3826. + * @param *ctx wbclient Context
  3827. + * @param name Name to resolve
  3828. + * @param *ip Pointer to the ip address string
  3829. + *
  3830. + * @return #wbcErr
  3831. + **/
  3832. +wbcErr wbcCtxResolveWinsByName(struct wbcContext *ctx,
  3833. + const char *name, char **ip);
  3834. +
  3835. +/**
  3836. + * @brief Resolve a NetbiosName via WINS
  3837. + *
  3838. * @param name Name to resolve
  3839. * @param *ip Pointer to the ip address string
  3840. *
  3841. @@ -1314,8 +1877,21 @@ wbcErr wbcResolveWinsByName(const char *name, char **ip);
  3842. /**
  3843. * @brief Resolve an IP address via WINS into a NetbiosName
  3844. *
  3845. - * @param ip The ip address string
  3846. - * @param *name Pointer to the name
  3847. + * @param *ctx wbclient Context
  3848. + * @param ip The ip address string
  3849. + * @param *name Pointer to the name
  3850. + *
  3851. + * @return #wbcErr
  3852. + *
  3853. + **/
  3854. +wbcErr wbcCtxResolveWinsByIP(struct wbcContext *ctx,
  3855. + const char *ip, char **name);
  3856. +
  3857. +/**
  3858. + * @brief Resolve an IP address via WINS into a NetbiosName
  3859. + *
  3860. + * @param ip The ip address string
  3861. + * @param *name Pointer to the name
  3862. *
  3863. * @return #wbcErr
  3864. *
  3865. @@ -1329,6 +1905,18 @@ wbcErr wbcResolveWinsByIP(const char *ip, char **name);
  3866. /**
  3867. * @brief Trigger a verification of the trust credentials of a specific domain
  3868. *
  3869. + * @param *ctx wbclient Context
  3870. + * @param *domain The name of the domain.
  3871. + * @param error Output details on WBC_ERR_AUTH_ERROR
  3872. + *
  3873. + * @return #wbcErr
  3874. + **/
  3875. +wbcErr wbcCtxCheckTrustCredentials(struct wbcContext *ctx, const char *domain,
  3876. + struct wbcAuthErrorInfo **error);
  3877. +
  3878. +/**
  3879. + * @brief Trigger a verification of the trust credentials of a specific domain
  3880. + *
  3881. * @param *domain The name of the domain.
  3882. * @param error Output details on WBC_ERR_AUTH_ERROR
  3883. *
  3884. @@ -1340,6 +1928,18 @@ wbcErr wbcCheckTrustCredentials(const char *domain,
  3885. /**
  3886. * @brief Trigger a change of the trust credentials for a specific domain
  3887. *
  3888. + * @param *ctx wbclient Context
  3889. + * @param *domain The name of the domain.
  3890. + * @param error Output details on WBC_ERR_AUTH_ERROR
  3891. + *
  3892. + * @return #wbcErr
  3893. + **/
  3894. +wbcErr wbcCtxChangeTrustCredentials(struct wbcContext *ctx, const char *domain,
  3895. + struct wbcAuthErrorInfo **error);
  3896. +
  3897. +/**
  3898. + * @brief Trigger a change of the trust credentials for a specific domain
  3899. + *
  3900. * @param *domain The name of the domain.
  3901. * @param error Output details on WBC_ERR_AUTH_ERROR
  3902. *
  3903. @@ -1352,6 +1952,21 @@ wbcErr wbcChangeTrustCredentials(const char *domain,
  3904. * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
  3905. * version of wbcCheckTrustCredentials
  3906. *
  3907. + * @param *ctx wbclient Context
  3908. + * @param *domain The name of the domain, only NULL for the default domain is
  3909. + * supported yet. Other values than NULL will result in
  3910. + * WBC_ERR_NOT_IMPLEMENTED.
  3911. + * @param error Output details on WBC_ERR_AUTH_ERROR
  3912. + *
  3913. + * @return #wbcErr
  3914. + **/
  3915. +wbcErr wbcCtxPingDc(struct wbcContext *ctx, const char *domain,
  3916. + struct wbcAuthErrorInfo **error);
  3917. +
  3918. +/**
  3919. + * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
  3920. + * version of wbcCheckTrustCredentials
  3921. + *
  3922. * @param *domain The name of the domain, only NULL for the default domain is
  3923. * supported yet. Other values than NULL will result in
  3924. * WBC_ERR_NOT_IMPLEMENTED.
  3925. @@ -1365,6 +1980,23 @@ wbcErr wbcPingDc(const char *domain, struct wbcAuthErrorInfo **error);
  3926. * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
  3927. * version of wbcCheckTrustCredentials
  3928. *
  3929. + * @param *ctx wbclient Context
  3930. + * @param *domain The name of the domain, only NULL for the default domain is
  3931. + * supported yet. Other values than NULL will result in
  3932. + * WBC_ERR_NOT_IMPLEMENTED.
  3933. + * @param error Output details on WBC_ERR_AUTH_ERROR
  3934. + * @param dcname DC that was attempted to ping
  3935. + *
  3936. + * @return #wbcErr
  3937. + **/
  3938. +wbcErr wbcCtxPingDc2(struct wbcContext *ctx, const char *domain,
  3939. + struct wbcAuthErrorInfo **error,
  3940. + char **dcname);
  3941. +
  3942. +/**
  3943. + * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
  3944. + * version of wbcCheckTrustCredentials
  3945. + *
  3946. * @param *domain The name of the domain, only NULL for the default domain is
  3947. * supported yet. Other values than NULL will result in
  3948. * WBC_ERR_NOT_IMPLEMENTED.
  3949. --
  3950. 2.1.4
  3951.  
  3952. From 8df7a9d18b85c51e99daf96610941b24799b101f Mon Sep 17 00:00:00 2001
  3953. From: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  3954. Date: Sun, 22 Feb 2015 23:31:48 +0000
  3955. Subject: [PATCH 7/9] Move wbc global variables into global context instead
  3956.  
  3957. There are some global variables in use in the libwbclient
  3958. library. Now that we have a context, move these into it so that
  3959. they are thread-safe when the wbcCtx* functions are used.
  3960.  
  3961. Signed-off-by: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  3962. Reviewed-by: Volker Lendecke <vl@samba.org>
  3963. Reviewed-by: Jeremy Allison <jra@samba.org>
  3964. ---
  3965. nsswitch/libwbclient/wbc_pwd.c | 99 +++++++++++++++++---------------
  3966. nsswitch/libwbclient/wbclient.c | 14 +++++
  3967. nsswitch/libwbclient/wbclient_internal.h | 5 ++
  3968. 3 files changed, 73 insertions(+), 45 deletions(-)
  3969.  
  3970. diff --git a/nsswitch/libwbclient/wbc_pwd.c b/nsswitch/libwbclient/wbc_pwd.c
  3971. index 0b05133..805ab63 100644
  3972. --- a/nsswitch/libwbclient/wbc_pwd.c
  3973. +++ b/nsswitch/libwbclient/wbc_pwd.c
  3974. @@ -4,6 +4,7 @@
  3975. Winbind client API
  3976.  
  3977. Copyright (C) Gerald (Jerry) Carter 2007
  3978. + Copyright (C) Matthew Newton 2015
  3979.  
  3980.  
  3981. This library is free software; you can redistribute it and/or
  3982. @@ -359,16 +360,6 @@ wbcErr wbcGetgrgid(gid_t gid, struct group **grp)
  3983. return wbcCtxGetgrgid(NULL, gid, grp);
  3984. }
  3985.  
  3986. -/** @brief Number of cached passwd structs
  3987. - *
  3988. - */
  3989. -static uint32_t pw_cache_size;
  3990. -
  3991. -/** @brief Position of the pwent context
  3992. - *
  3993. - */
  3994. -static uint32_t pw_cache_idx;
  3995. -
  3996. /** @brief Winbindd response containing the passwd structs
  3997. *
  3998. */
  3999. @@ -379,8 +370,12 @@ wbcErr wbcCtxSetpwent(struct wbcContext *ctx)
  4000. {
  4001. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  4002.  
  4003. - if (pw_cache_size > 0) {
  4004. - pw_cache_idx = pw_cache_size = 0;
  4005. + if (!ctx) {
  4006. + ctx = wbcGetGlobalCtx();
  4007. + }
  4008. +
  4009. + if (ctx->pw_cache_size > 0) {
  4010. + ctx->pw_cache_idx = ctx->pw_cache_size = 0;
  4011. winbindd_free_response(&pw_response);
  4012. }
  4013.  
  4014. @@ -404,8 +399,12 @@ wbcErr wbcCtxEndpwent(struct wbcContext *ctx)
  4015. {
  4016. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  4017.  
  4018. - if (pw_cache_size > 0) {
  4019. - pw_cache_idx = pw_cache_size = 0;
  4020. + if (!ctx) {
  4021. + ctx = wbcGetGlobalCtx();
  4022. + }
  4023. +
  4024. + if (ctx->pw_cache_size > 0) {
  4025. + ctx->pw_cache_idx = ctx->pw_cache_size = 0;
  4026. winbindd_free_response(&pw_response);
  4027. }
  4028.  
  4029. @@ -429,14 +428,18 @@ wbcErr wbcCtxGetpwent(struct wbcContext *ctx, struct passwd **pwd)
  4030. struct winbindd_request request;
  4031. struct winbindd_pw *wb_pw;
  4032.  
  4033. + if (!ctx) {
  4034. + ctx = wbcGetGlobalCtx();
  4035. + }
  4036. +
  4037. /* If there's a cached result, return that. */
  4038. - if (pw_cache_idx < pw_cache_size) {
  4039. + if (ctx->pw_cache_idx < ctx->pw_cache_size) {
  4040. goto return_result;
  4041. }
  4042.  
  4043. /* Otherwise, query winbindd for some entries. */
  4044.  
  4045. - pw_cache_idx = 0;
  4046. + ctx->pw_cache_idx = 0;
  4047.  
  4048. winbindd_free_response(&pw_response);
  4049.  
  4050. @@ -448,17 +451,17 @@ wbcErr wbcCtxGetpwent(struct wbcContext *ctx, struct passwd **pwd)
  4051.  
  4052. BAIL_ON_WBC_ERROR(wbc_status);
  4053.  
  4054. - pw_cache_size = pw_response.data.num_entries;
  4055. + ctx->pw_cache_size = pw_response.data.num_entries;
  4056.  
  4057. return_result:
  4058.  
  4059. wb_pw = (struct winbindd_pw *) pw_response.extra_data.data;
  4060.  
  4061. - *pwd = copy_passwd_entry(&wb_pw[pw_cache_idx]);
  4062. + *pwd = copy_passwd_entry(&wb_pw[ctx->pw_cache_idx]);
  4063.  
  4064. BAIL_ON_PTR_ERROR(*pwd, wbc_status);
  4065.  
  4066. - pw_cache_idx++;
  4067. + ctx->pw_cache_idx++;
  4068.  
  4069. done:
  4070. return wbc_status;
  4071. @@ -469,16 +472,6 @@ wbcErr wbcGetpwent(struct passwd **pwd)
  4072. return wbcCtxGetpwent(NULL, pwd);
  4073. }
  4074.  
  4075. -/** @brief Number of cached group structs
  4076. - *
  4077. - */
  4078. -static uint32_t gr_cache_size;
  4079. -
  4080. -/** @brief Position of the grent context
  4081. - *
  4082. - */
  4083. -static uint32_t gr_cache_idx;
  4084. -
  4085. /** @brief Winbindd response containing the group structs
  4086. *
  4087. */
  4088. @@ -489,8 +482,12 @@ wbcErr wbcCtxSetgrent(struct wbcContext *ctx)
  4089. {
  4090. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  4091.  
  4092. - if (gr_cache_size > 0) {
  4093. - gr_cache_idx = gr_cache_size = 0;
  4094. + if (!ctx) {
  4095. + ctx = wbcGetGlobalCtx();
  4096. + }
  4097. +
  4098. + if (ctx->gr_cache_size > 0) {
  4099. + ctx->gr_cache_idx = ctx->gr_cache_size = 0;
  4100. winbindd_free_response(&gr_response);
  4101. }
  4102.  
  4103. @@ -514,8 +511,12 @@ wbcErr wbcCtxEndgrent(struct wbcContext *ctx)
  4104. {
  4105. wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
  4106.  
  4107. - if (gr_cache_size > 0) {
  4108. - gr_cache_idx = gr_cache_size = 0;
  4109. + if (!ctx) {
  4110. + ctx = wbcGetGlobalCtx();
  4111. + }
  4112. +
  4113. + if (ctx->gr_cache_size > 0) {
  4114. + ctx->gr_cache_idx = ctx->gr_cache_size = 0;
  4115. winbindd_free_response(&gr_response);
  4116. }
  4117.  
  4118. @@ -540,14 +541,18 @@ wbcErr wbcCtxGetgrent(struct wbcContext *ctx, struct group **grp)
  4119. struct winbindd_gr *wb_gr;
  4120. uint32_t mem_ofs;
  4121.  
  4122. + if (!ctx) {
  4123. + ctx = wbcGetGlobalCtx();
  4124. + }
  4125. +
  4126. /* If there's a cached result, return that. */
  4127. - if (gr_cache_idx < gr_cache_size) {
  4128. + if (ctx->gr_cache_idx < ctx->gr_cache_size) {
  4129. goto return_result;
  4130. }
  4131.  
  4132. /* Otherwise, query winbindd for some entries. */
  4133.  
  4134. - gr_cache_idx = 0;
  4135. + ctx->gr_cache_idx = 0;
  4136.  
  4137. winbindd_free_response(&gr_response);
  4138.  
  4139. @@ -559,21 +564,21 @@ wbcErr wbcCtxGetgrent(struct wbcContext *ctx, struct group **grp)
  4140.  
  4141. BAIL_ON_WBC_ERROR(wbc_status);
  4142.  
  4143. - gr_cache_size = gr_response.data.num_entries;
  4144. + ctx->gr_cache_size = gr_response.data.num_entries;
  4145.  
  4146. return_result:
  4147.  
  4148. wb_gr = (struct winbindd_gr *) gr_response.extra_data.data;
  4149.  
  4150. - mem_ofs = wb_gr[gr_cache_idx].gr_mem_ofs +
  4151. - gr_cache_size * sizeof(struct winbindd_gr);
  4152. + mem_ofs = wb_gr[ctx->gr_cache_idx].gr_mem_ofs +
  4153. + ctx->gr_cache_size * sizeof(struct winbindd_gr);
  4154.  
  4155. - *grp = copy_group_entry(&wb_gr[gr_cache_idx],
  4156. + *grp = copy_group_entry(&wb_gr[ctx->gr_cache_idx],
  4157. ((char *)gr_response.extra_data.data)+mem_ofs);
  4158.  
  4159. BAIL_ON_PTR_ERROR(*grp, wbc_status);
  4160.  
  4161. - gr_cache_idx++;
  4162. + ctx->gr_cache_idx++;
  4163.  
  4164. done:
  4165. return wbc_status;
  4166. @@ -591,14 +596,18 @@ wbcErr wbcCtxGetgrlist(struct wbcContext *ctx, struct group **grp)
  4167. struct winbindd_request request;
  4168. struct winbindd_gr *wb_gr;
  4169.  
  4170. + if (!ctx) {
  4171. + ctx = wbcGetGlobalCtx();
  4172. + }
  4173. +
  4174. /* If there's a cached result, return that. */
  4175. - if (gr_cache_idx < gr_cache_size) {
  4176. + if (ctx->gr_cache_idx < ctx->gr_cache_size) {
  4177. goto return_result;
  4178. }
  4179.  
  4180. /* Otherwise, query winbindd for some entries. */
  4181.  
  4182. - gr_cache_idx = 0;
  4183. + ctx->gr_cache_idx = 0;
  4184.  
  4185. winbindd_free_response(&gr_response);
  4186. ZERO_STRUCT(gr_response);
  4187. @@ -611,17 +620,17 @@ wbcErr wbcCtxGetgrlist(struct wbcContext *ctx, struct group **grp)
  4188.  
  4189. BAIL_ON_WBC_ERROR(wbc_status);
  4190.  
  4191. - gr_cache_size = gr_response.data.num_entries;
  4192. + ctx->gr_cache_size = gr_response.data.num_entries;
  4193.  
  4194. return_result:
  4195.  
  4196. wb_gr = (struct winbindd_gr *) gr_response.extra_data.data;
  4197.  
  4198. - *grp = copy_group_entry(&wb_gr[gr_cache_idx], NULL);
  4199. + *grp = copy_group_entry(&wb_gr[ctx->gr_cache_idx], NULL);
  4200.  
  4201. BAIL_ON_PTR_ERROR(*grp, wbc_status);
  4202.  
  4203. - gr_cache_idx++;
  4204. + ctx->gr_cache_idx++;
  4205.  
  4206. done:
  4207. return wbc_status;
  4208. diff --git a/nsswitch/libwbclient/wbclient.c b/nsswitch/libwbclient/wbclient.c
  4209. index ab1159a..5444e82 100644
  4210. --- a/nsswitch/libwbclient/wbclient.c
  4211. +++ b/nsswitch/libwbclient/wbclient.c
  4212. @@ -41,6 +41,15 @@ NSS_STATUS winbindd_priv_request_response(struct winbindd_context *wbctx,
  4213. struct winbindd_context *winbindd_ctx_create(void);
  4214. void winbindd_ctx_free(struct winbindd_context *ctx);
  4215.  
  4216. +/* Global context used for non-Ctx functions */
  4217. +
  4218. +static struct wbcContext wbcGlobalCtx = {
  4219. + .winbindd_ctx = NULL,
  4220. + .pw_cache_size = 0,
  4221. + .pw_cache_idx = 0,
  4222. + .gr_cache_size = 0,
  4223. + .gr_cache_idx = 0
  4224. +};
  4225.  
  4226. /*
  4227. result == NSS_STATUS_UNAVAIL: winbind not around
  4228. @@ -317,3 +326,8 @@ void wbcCtxFree(struct wbcContext *ctx)
  4229. {
  4230. wbcFreeMemory(ctx);
  4231. }
  4232. +
  4233. +struct wbcContext *wbcGetGlobalCtx(void)
  4234. +{
  4235. + return &wbcGlobalCtx;
  4236. +}
  4237. diff --git a/nsswitch/libwbclient/wbclient_internal.h b/nsswitch/libwbclient/wbclient_internal.h
  4238. index becddac..6d815c0 100644
  4239. --- a/nsswitch/libwbclient/wbclient_internal.h
  4240. +++ b/nsswitch/libwbclient/wbclient_internal.h
  4241. @@ -24,6 +24,10 @@
  4242.  
  4243. struct wbcContext {
  4244. struct winbindd_context *winbindd_ctx;
  4245. + uint32_t pw_cache_size; /* Number of cached passwd structs */
  4246. + uint32_t pw_cache_idx; /* Position of the pwent context */
  4247. + uint32_t gr_cache_size; /* Number of cached group structs */
  4248. + uint32_t gr_cache_idx; /* Position of the grent context */
  4249. };
  4250.  
  4251. /* Private functions */
  4252. @@ -41,5 +45,6 @@ void *wbcAllocateMemory(size_t nelem, size_t elsize,
  4253.  
  4254. char *wbcStrDup(const char *str);
  4255. const char **wbcAllocateStringArray(int num_strings);
  4256. +struct wbcContext *wbcGetGlobalCtx(void);
  4257.  
  4258. #endif /* _WBCLIENT_INTERNAL_H */
  4259. --
  4260. 2.1.4
  4261.  
  4262. From cd6f731b479b728f568acc76c593c247c0d60e09 Mon Sep 17 00:00:00 2001
  4263. From: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  4264. Date: Sun, 1 Mar 2015 23:14:07 +0000
  4265. Subject: [PATCH 8/9] Update libwbclient version to 0.12
  4266.  
  4267. Increment the minor version of the libwbclient library after new
  4268. context functions added. (Major version increase not required as
  4269. the only two functions with changed parameters are private to the
  4270. library.)
  4271.  
  4272. Signed-off-by: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  4273. Reviewed-by: Volker Lendecke <vl@samba.org>
  4274. Reviewed-by: Jeremy Allison <jra@samba.org>
  4275.  
  4276. Autobuild-User(master): Jeremy Allison <jra@samba.org>
  4277. Autobuild-Date(master): Tue Mar 10 03:24:45 CET 2015 on sn-devel-104
  4278. ---
  4279. nsswitch/libwbclient/ABI/wbclient-0.12.sigs | 130 ++++++++++++++++++++++++++++
  4280. nsswitch/libwbclient/wbclient.h | 3 +-
  4281. nsswitch/libwbclient/wscript | 2 +-
  4282. 3 files changed, 133 insertions(+), 2 deletions(-)
  4283. create mode 100644 nsswitch/libwbclient/ABI/wbclient-0.12.sigs
  4284.  
  4285. diff --git a/nsswitch/libwbclient/ABI/wbclient-0.12.sigs b/nsswitch/libwbclient/ABI/wbclient-0.12.sigs
  4286. new file mode 100644
  4287. index 0000000..3b71917
  4288. --- /dev/null
  4289. +++ b/nsswitch/libwbclient/ABI/wbclient-0.12.sigs
  4290. @@ -0,0 +1,130 @@
  4291. +wbcAddNamedBlob: wbcErr (size_t *, struct wbcNamedBlob **, const char *, uint32_t, uint8_t *, size_t)
  4292. +wbcAllocateGid: wbcErr (gid_t *)
  4293. +wbcAllocateMemory: void *(size_t, size_t, void (*)(void *))
  4294. +wbcAllocateStringArray: const char **(int)
  4295. +wbcAllocateUid: wbcErr (uid_t *)
  4296. +wbcAuthenticateUser: wbcErr (const char *, const char *)
  4297. +wbcAuthenticateUserEx: wbcErr (const struct wbcAuthUserParams *, struct wbcAuthUserInfo **, struct wbcAuthErrorInfo **)
  4298. +wbcChangeTrustCredentials: wbcErr (const char *, struct wbcAuthErrorInfo **)
  4299. +wbcChangeUserPassword: wbcErr (const char *, const char *, const char *)
  4300. +wbcChangeUserPasswordEx: wbcErr (const struct wbcChangePasswordParams *, struct wbcAuthErrorInfo **, enum wbcPasswordChangeRejectReason *, struct wbcUserPasswordPolicyInfo **)
  4301. +wbcCheckTrustCredentials: wbcErr (const char *, struct wbcAuthErrorInfo **)
  4302. +wbcCredentialCache: wbcErr (struct wbcCredentialCacheParams *, struct wbcCredentialCacheInfo **, struct wbcAuthErrorInfo **)
  4303. +wbcCredentialSave: wbcErr (const char *, const char *)
  4304. +wbcCtxAllocateGid: wbcErr (struct wbcContext *, gid_t *)
  4305. +wbcCtxAllocateUid: wbcErr (struct wbcContext *, uid_t *)
  4306. +wbcCtxAuthenticateUser: wbcErr (struct wbcContext *, const char *, const char *)
  4307. +wbcCtxAuthenticateUserEx: wbcErr (struct wbcContext *, const struct wbcAuthUserParams *, struct wbcAuthUserInfo **, struct wbcAuthErrorInfo **)
  4308. +wbcCtxChangeTrustCredentials: wbcErr (struct wbcContext *, const char *, struct wbcAuthErrorInfo **)
  4309. +wbcCtxChangeUserPassword: wbcErr (struct wbcContext *, const char *, const char *, const char *)
  4310. +wbcCtxChangeUserPasswordEx: wbcErr (struct wbcContext *, const struct wbcChangePasswordParams *, struct wbcAuthErrorInfo **, enum wbcPasswordChangeRejectReason *, struct wbcUserPasswordPolicyInfo **)
  4311. +wbcCtxCheckTrustCredentials: wbcErr (struct wbcContext *, const char *, struct wbcAuthErrorInfo **)
  4312. +wbcCtxCreate: struct wbcContext *(void)
  4313. +wbcCtxCredentialCache: wbcErr (struct wbcContext *, struct wbcCredentialCacheParams *, struct wbcCredentialCacheInfo **, struct wbcAuthErrorInfo **)
  4314. +wbcCtxCredentialSave: wbcErr (struct wbcContext *, const char *, const char *)
  4315. +wbcCtxDcInfo: wbcErr (struct wbcContext *, const char *, size_t *, const char ***, const char ***)
  4316. +wbcCtxDomainInfo: wbcErr (struct wbcContext *, const char *, struct wbcDomainInfo **)
  4317. +wbcCtxEndgrent: wbcErr (struct wbcContext *)
  4318. +wbcCtxEndpwent: wbcErr (struct wbcContext *)
  4319. +wbcCtxFree: void (struct wbcContext *)
  4320. +wbcCtxGetDisplayName: wbcErr (struct wbcContext *, const struct wbcDomainSid *, char **, char **, enum wbcSidType *)
  4321. +wbcCtxGetGroups: wbcErr (struct wbcContext *, const char *, uint32_t *, gid_t **)
  4322. +wbcCtxGetSidAliases: wbcErr (struct wbcContext *, const struct wbcDomainSid *, struct wbcDomainSid *, uint32_t, uint32_t **, uint32_t *)
  4323. +wbcCtxGetgrent: wbcErr (struct wbcContext *, struct group **)
  4324. +wbcCtxGetgrgid: wbcErr (struct wbcContext *, gid_t, struct group **)
  4325. +wbcCtxGetgrlist: wbcErr (struct wbcContext *, struct group **)
  4326. +wbcCtxGetgrnam: wbcErr (struct wbcContext *, const char *, struct group **)
  4327. +wbcCtxGetpwent: wbcErr (struct wbcContext *, struct passwd **)
  4328. +wbcCtxGetpwnam: wbcErr (struct wbcContext *, const char *, struct passwd **)
  4329. +wbcCtxGetpwsid: wbcErr (struct wbcContext *, struct wbcDomainSid *, struct passwd **)
  4330. +wbcCtxGetpwuid: wbcErr (struct wbcContext *, uid_t, struct passwd **)
  4331. +wbcCtxGidToSid: wbcErr (struct wbcContext *, gid_t, struct wbcDomainSid *)
  4332. +wbcCtxInterfaceDetails: wbcErr (struct wbcContext *, struct wbcInterfaceDetails **)
  4333. +wbcCtxListGroups: wbcErr (struct wbcContext *, const char *, uint32_t *, const char ***)
  4334. +wbcCtxListTrusts: wbcErr (struct wbcContext *, struct wbcDomainInfo **, size_t *)
  4335. +wbcCtxListUsers: wbcErr (struct wbcContext *, const char *, uint32_t *, const char ***)
  4336. +wbcCtxLogoffUser: wbcErr (struct wbcContext *, const char *, uid_t, const char *)
  4337. +wbcCtxLogoffUserEx: wbcErr (struct wbcContext *, const struct wbcLogoffUserParams *, struct wbcAuthErrorInfo **)
  4338. +wbcCtxLogonUser: wbcErr (struct wbcContext *, const struct wbcLogonUserParams *, struct wbcLogonUserInfo **, struct wbcAuthErrorInfo **, struct wbcUserPasswordPolicyInfo **)
  4339. +wbcCtxLookupDomainController: wbcErr (struct wbcContext *, const char *, uint32_t, struct wbcDomainControllerInfo **)
  4340. +wbcCtxLookupDomainControllerEx: wbcErr (struct wbcContext *, const char *, struct wbcGuid *, const char *, uint32_t, struct wbcDomainControllerInfoEx **)
  4341. +wbcCtxLookupName: wbcErr (struct wbcContext *, const char *, const char *, struct wbcDomainSid *, enum wbcSidType *)
  4342. +wbcCtxLookupRids: wbcErr (struct wbcContext *, struct wbcDomainSid *, int, uint32_t *, const char **, const char ***, enum wbcSidType **)
  4343. +wbcCtxLookupSid: wbcErr (struct wbcContext *, const struct wbcDomainSid *, char **, char **, enum wbcSidType *)
  4344. +wbcCtxLookupSids: wbcErr (struct wbcContext *, const struct wbcDomainSid *, int, struct wbcDomainInfo **, int *, struct wbcTranslatedName **)
  4345. +wbcCtxLookupUserSids: wbcErr (struct wbcContext *, const struct wbcDomainSid *, bool, uint32_t *, struct wbcDomainSid **)
  4346. +wbcCtxPing: wbcErr (struct wbcContext *)
  4347. +wbcCtxPingDc: wbcErr (struct wbcContext *, const char *, struct wbcAuthErrorInfo **)
  4348. +wbcCtxPingDc2: wbcErr (struct wbcContext *, const char *, struct wbcAuthErrorInfo **, char **)
  4349. +wbcCtxResolveWinsByIP: wbcErr (struct wbcContext *, const char *, char **)
  4350. +wbcCtxResolveWinsByName: wbcErr (struct wbcContext *, const char *, char **)
  4351. +wbcCtxSetgrent: wbcErr (struct wbcContext *)
  4352. +wbcCtxSetpwent: wbcErr (struct wbcContext *)
  4353. +wbcCtxSidToGid: wbcErr (struct wbcContext *, const struct wbcDomainSid *, gid_t *)
  4354. +wbcCtxSidToUid: wbcErr (struct wbcContext *, const struct wbcDomainSid *, uid_t *)
  4355. +wbcCtxSidsToUnixIds: wbcErr (struct wbcContext *, const struct wbcDomainSid *, uint32_t, struct wbcUnixId *)
  4356. +wbcCtxUidToSid: wbcErr (struct wbcContext *, uid_t, struct wbcDomainSid *)
  4357. +wbcDcInfo: wbcErr (const char *, size_t *, const char ***, const char ***)
  4358. +wbcDomainInfo: wbcErr (const char *, struct wbcDomainInfo **)
  4359. +wbcEndgrent: wbcErr (void)
  4360. +wbcEndpwent: wbcErr (void)
  4361. +wbcErrorString: const char *(wbcErr)
  4362. +wbcFreeMemory: void (void *)
  4363. +wbcGetDisplayName: wbcErr (const struct wbcDomainSid *, char **, char **, enum wbcSidType *)
  4364. +wbcGetGlobalCtx: struct wbcContext *(void)
  4365. +wbcGetGroups: wbcErr (const char *, uint32_t *, gid_t **)
  4366. +wbcGetSidAliases: wbcErr (const struct wbcDomainSid *, struct wbcDomainSid *, uint32_t, uint32_t **, uint32_t *)
  4367. +wbcGetgrent: wbcErr (struct group **)
  4368. +wbcGetgrgid: wbcErr (gid_t, struct group **)
  4369. +wbcGetgrlist: wbcErr (struct group **)
  4370. +wbcGetgrnam: wbcErr (const char *, struct group **)
  4371. +wbcGetpwent: wbcErr (struct passwd **)
  4372. +wbcGetpwnam: wbcErr (const char *, struct passwd **)
  4373. +wbcGetpwsid: wbcErr (struct wbcDomainSid *, struct passwd **)
  4374. +wbcGetpwuid: wbcErr (uid_t, struct passwd **)
  4375. +wbcGidToSid: wbcErr (gid_t, struct wbcDomainSid *)
  4376. +wbcGuidToString: wbcErr (const struct wbcGuid *, char **)
  4377. +wbcInterfaceDetails: wbcErr (struct wbcInterfaceDetails **)
  4378. +wbcLibraryDetails: wbcErr (struct wbcLibraryDetails **)
  4379. +wbcListGroups: wbcErr (const char *, uint32_t *, const char ***)
  4380. +wbcListTrusts: wbcErr (struct wbcDomainInfo **, size_t *)
  4381. +wbcListUsers: wbcErr (const char *, uint32_t *, const char ***)
  4382. +wbcLogoffUser: wbcErr (const char *, uid_t, const char *)
  4383. +wbcLogoffUserEx: wbcErr (const struct wbcLogoffUserParams *, struct wbcAuthErrorInfo **)
  4384. +wbcLogonUser: wbcErr (const struct wbcLogonUserParams *, struct wbcLogonUserInfo **, struct wbcAuthErrorInfo **, struct wbcUserPasswordPolicyInfo **)
  4385. +wbcLookupDomainController: wbcErr (const char *, uint32_t, struct wbcDomainControllerInfo **)
  4386. +wbcLookupDomainControllerEx: wbcErr (const char *, struct wbcGuid *, const char *, uint32_t, struct wbcDomainControllerInfoEx **)
  4387. +wbcLookupName: wbcErr (const char *, const char *, struct wbcDomainSid *, enum wbcSidType *)
  4388. +wbcLookupRids: wbcErr (struct wbcDomainSid *, int, uint32_t *, const char **, const char ***, enum wbcSidType **)
  4389. +wbcLookupSid: wbcErr (const struct wbcDomainSid *, char **, char **, enum wbcSidType *)
  4390. +wbcLookupSids: wbcErr (const struct wbcDomainSid *, int, struct wbcDomainInfo **, int *, struct wbcTranslatedName **)
  4391. +wbcLookupUserSids: wbcErr (const struct wbcDomainSid *, bool, uint32_t *, struct wbcDomainSid **)
  4392. +wbcPing: wbcErr (void)
  4393. +wbcPingDc: wbcErr (const char *, struct wbcAuthErrorInfo **)
  4394. +wbcPingDc2: wbcErr (const char *, struct wbcAuthErrorInfo **, char **)
  4395. +wbcQueryGidToSid: wbcErr (gid_t, struct wbcDomainSid *)
  4396. +wbcQuerySidToGid: wbcErr (const struct wbcDomainSid *, gid_t *)
  4397. +wbcQuerySidToUid: wbcErr (const struct wbcDomainSid *, uid_t *)
  4398. +wbcQueryUidToSid: wbcErr (uid_t, struct wbcDomainSid *)
  4399. +wbcRemoveGidMapping: wbcErr (gid_t, const struct wbcDomainSid *)
  4400. +wbcRemoveUidMapping: wbcErr (uid_t, const struct wbcDomainSid *)
  4401. +wbcRequestResponse: wbcErr (struct wbcContext *, int, struct winbindd_request *, struct winbindd_response *)
  4402. +wbcRequestResponsePriv: wbcErr (struct wbcContext *, int, struct winbindd_request *, struct winbindd_response *)
  4403. +wbcResolveWinsByIP: wbcErr (const char *, char **)
  4404. +wbcResolveWinsByName: wbcErr (const char *, char **)
  4405. +wbcSetGidHwm: wbcErr (gid_t)
  4406. +wbcSetGidMapping: wbcErr (gid_t, const struct wbcDomainSid *)
  4407. +wbcSetUidHwm: wbcErr (uid_t)
  4408. +wbcSetUidMapping: wbcErr (uid_t, const struct wbcDomainSid *)
  4409. +wbcSetgrent: wbcErr (void)
  4410. +wbcSetpwent: wbcErr (void)
  4411. +wbcSidToGid: wbcErr (const struct wbcDomainSid *, gid_t *)
  4412. +wbcSidToString: wbcErr (const struct wbcDomainSid *, char **)
  4413. +wbcSidToStringBuf: int (const struct wbcDomainSid *, char *, int)
  4414. +wbcSidToUid: wbcErr (const struct wbcDomainSid *, uid_t *)
  4415. +wbcSidTypeString: const char *(enum wbcSidType)
  4416. +wbcSidsToUnixIds: wbcErr (const struct wbcDomainSid *, uint32_t, struct wbcUnixId *)
  4417. +wbcStrDup: char *(const char *)
  4418. +wbcStringToGuid: wbcErr (const char *, struct wbcGuid *)
  4419. +wbcStringToSid: wbcErr (const char *, struct wbcDomainSid *)
  4420. +wbcUidToSid: wbcErr (uid_t, struct wbcDomainSid *)
  4421. diff --git a/nsswitch/libwbclient/wbclient.h b/nsswitch/libwbclient/wbclient.h
  4422. index 6aa4e12..adf8fe3 100644
  4423. --- a/nsswitch/libwbclient/wbclient.h
  4424. +++ b/nsswitch/libwbclient/wbclient.h
  4425. @@ -72,9 +72,10 @@ const char *wbcErrorString(wbcErr error);
  4426. * 0.9: Added support for WBC_ID_TYPE_BOTH
  4427. * 0.10: Added wbcPingDc2()
  4428. * 0.11: Extended wbcAuthenticateUserEx to provide PAC parsing
  4429. + * 0.12: Added wbcCtxCreate and friends
  4430. **/
  4431. #define WBCLIENT_MAJOR_VERSION 0
  4432. -#define WBCLIENT_MINOR_VERSION 11
  4433. +#define WBCLIENT_MINOR_VERSION 12
  4434. #define WBCLIENT_VENDOR_VERSION "Samba libwbclient"
  4435. struct wbcLibraryDetails {
  4436. uint16_t major_version;
  4437. diff --git a/nsswitch/libwbclient/wscript b/nsswitch/libwbclient/wscript
  4438. index 9c4da16..8602c1c 100644
  4439. --- a/nsswitch/libwbclient/wscript
  4440. +++ b/nsswitch/libwbclient/wscript
  4441. @@ -3,7 +3,7 @@
  4442. import Options, Logs
  4443.  
  4444. # Remember to also update wbclient.h
  4445. -VERSION="0.11"
  4446. +VERSION="0.12"
  4447.  
  4448. # It may be useful at some point to allow Samba to build against a
  4449. # system libwbclient, such as the one provided by Likewise. To to
  4450. --
  4451. 2.1.4
  4452.  
  4453. From a805a2ef79da440f2866d25e4af7d5fd6c3e6577 Mon Sep 17 00:00:00 2001
  4454. From: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  4455. Date: Tue, 17 Mar 2015 00:56:12 +0000
  4456. Subject: [PATCH 9/9] Ensure we always initialise the winbind context
  4457.  
  4458. Stops segfault when a context is passed. Internal Samba code will
  4459. currently always call this with NULL so won't trigger the bug.
  4460.  
  4461. Signed-off-by: Matthew Newton <matthew-git@newtoncomputing.co.uk>
  4462. Reviewed-by: Volker Lendecke <vl@samba.org>
  4463. Reviewed-by: Jeremy Allison <jra@samba.org>
  4464.  
  4465. Autobuild-User(master): Jeremy Allison <jra@samba.org>
  4466. Autobuild-Date(master): Wed Mar 18 01:41:32 CET 2015 on sn-devel-104
  4467. ---
  4468. nsswitch/wb_common.c | 2 +-
  4469. 1 file changed, 1 insertion(+), 1 deletion(-)
  4470.  
  4471. diff --git a/nsswitch/wb_common.c b/nsswitch/wb_common.c
  4472. index 1149d08..4f1ec7c 100644
  4473. --- a/nsswitch/wb_common.c
  4474. +++ b/nsswitch/wb_common.c
  4475. @@ -708,7 +708,7 @@ NSS_STATUS winbindd_priv_request_response(struct winbindd_context *ctx,
  4476. {
  4477. NSS_STATUS status = NSS_STATUS_UNAVAIL;
  4478. int count = 0;
  4479. - struct winbindd_context *wb_ctx;
  4480. + struct winbindd_context *wb_ctx = ctx;
  4481.  
  4482. if (ctx == NULL) {
  4483. wb_ctx = &wb_global_ctx;
  4484. --
  4485. 2.1.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement