/apps/net/samba-current/samba-sambagroups.patch
https://github.com/tenchman/TTLinux · Patch · 168 lines · 166 code · 2 blank · 0 comment · 0 complexity · 91d7aad98633a60a87ab6c9b6ac9d92c MD5 · raw file
- --- source/Makefile.in.sambagroups 2007-03-08 09:57:26.000000000 +0100
- +++ source/Makefile.in 2007-03-08 09:52:34.000000000 +0100
- @@ -735,7 +735,7 @@
- $(AFS_OBJ) $(AFS_SETTOKEN_OBJ) \
- $(LIBADS_SERVER_OBJ) $(SERVER_MUTEX_OBJ)
-
- -WBINFO_OBJ = nsswitch/wbinfo.o $(LIBSAMBA_OBJ) $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) \
- +WBINFO_OBJ = nsswitch/wbinfo.o nsswitch/sambagroups.o $(LIBSAMBA_OBJ) $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) \
- $(SECRETS_OBJ) $(POPT_LIB_OBJ) $(AFS_SETTOKEN_OBJ) $(RPC_PARSE_OBJ1) $(DOSERR_OBJ)
-
- WINBIND_NSS_OBJ = $(WBCOMMON_OBJ) lib/replace1.o @WINBIND_NSS_EXTRA_OBJS@
- --- source/nsswitch/wbinfo.c.sambagroups 2007-03-08 09:57:08.000000000 +0100
- +++ source/nsswitch/wbinfo.c 2007-03-08 09:23:24.000000000 +0100
- @@ -1149,6 +1149,7 @@ int main(int argc, char **argv)
- /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
- #endif
- { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL },
- + { "sambagroups", 'L', POPT_ARG_NONE, 0, 'L', "Listener for squid's group requests", NULL },
- POPT_COMMON_VERSION
- POPT_TABLEEND
- };
- @@ -1375,6 +1376,9 @@ int main(int argc, char **argv)
- goto done;
- }
- break;
- + case 'L':
- + sambagroups_listener();
- + break;
- case 'p':
- if (!wbinfo_ping()) {
- d_fprintf(stderr, "could not ping winbindd!\n");
- --- source/nsswitch/sambagroups.c.sambagroups 2007-03-08 09:51:44.000000000 +0100
- +++ source/nsswitch/sambagroups.c 2007-03-08 16:35:59.000000000 +0100
- @@ -0,0 +1,134 @@
- +#include <stdlib.h>
- +#include <fcntl.h>
- +#include <unistd.h>
- +#include <stdio.h>
- +#include <errno.h>
- +#include <ctype.h>
- +#include <string.h>
- +
- +#include <sys/file.h>
- +#include <sys/stat.h>
- +
- +#include "includes.h"
- +#include "winbindd.h"
- +
- +#define READSIZ 1024
- +
- +#define writec(__fd, __chr) write(__fd, __chr, strlen(__chr))
- +static int inputfd = 0;
- +static int outputfd = 1;
- +
- +char domainsep = '+';
- +
- +int sambagroups_lookup(char * user, char *group)
- +{
- + struct winbindd_request request;
- + struct winbindd_response response;
- + char *domain, *t;
- + int gid, i;
- +
- + /* Send off request */
- +
- + ZERO_STRUCT(request);
- + ZERO_STRUCT(response);
- +
- + if (!user) {
- + writec(outputfd, "ERROR: user missing\n");
- + return -1;
- + }
- + if (!group) {
- + writec(outputfd, "ERROR: group missing\n");
- + return -1;
- + }
- +
- + /* lookup group sid */
- + if ((t = strchr(user, domainsep))) {
- + domain = user;
- + *t = '\0';
- + fstrcpy(request.data.name.dom_name, domain);
- + *t = '+';
- + }
- +
- + fstrcpy(request.data.name.name, group);
- +
- +
- + if (winbindd_request_response(WINBINDD_LOOKUPNAME, &request, &response) !=
- + NSS_STATUS_SUCCESS) {
- + writec(outputfd, "ERROR: cannot lookup group sid\n");
- + return -1;
- + }
- +
- + ZERO_STRUCT(request);
- + fstrcpy(request.data.sid, response.data.sid.sid);
- + ZERO_STRUCT(response);
- +
- + if (winbindd_request_response(WINBINDD_SID_TO_GID, &request, &response) !=
- + NSS_STATUS_SUCCESS) {
- + writec(outputfd, "ERROR: cannot convert sid to gid\n");
- + return -1;
- + }
- +
- + gid = (int)response.data.gid;
- +
- +
- +
- + ZERO_STRUCT(request);
- + ZERO_STRUCT(response);
- +
- + /* do we need domain+user? */
- + fstrcpy(request.data.username, user);
- +
- + if (NSS_STATUS_SUCCESS != winbindd_request_response(WINBINDD_GETGROUPS, &request, &response)) {
- + writec(outputfd, "ERROR: cannot lookup user groups\n");
- + return -1;
- + }
- +
- + for (i = 0; i < response.data.num_entries; i++)
- + if (gid == (int)((gid_t *)response.extra_data.data)[i]) {
- + SAFE_FREE(response.extra_data.data);
- + return 0;
- + }
- +
- +
- + SAFE_FREE(response.extra_data.data);
- + return -1;
- +}
- +
- +int sambagroups_listener() {
- + char buf[READSIZ];
- + int rlen;
- + fd_set rfds;
- +
- +
- + while (1) {
- + FD_ZERO(&rfds);
- + FD_SET(inputfd, &rfds);
- +
- + if (-1 == select(inputfd + 1, &rfds, NULL, NULL, NULL))
- + continue;
- +
- + if (0 < (rlen = read(inputfd, buf, READSIZ-1))) {
- + char *user = NULL;
- + char *group = NULL;
- +
- + buf[rlen - 1] = '\0';
- +
- + user = buf;
- + if ((group = strchr(user, ' '))) {
- + *group = '\0';
- + group++;
- + }
- +
- + if (-1 == sambagroups_lookup(user, group))
- + writec(outputfd, "ERR\n");
- + else
- + writec(outputfd, "OK\n");
- + } else {
- + /* read error or emtpy read */
- + exit(23);
- + }
- +
- + }
- +
- +}
- +