From 87280e9a798895de827e5d1526fbac28a548f710 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 26 Mar 2004 22:26:33 +0000 Subject: Move the Client-IP based msdfs target expansion to a VFS module. Volker (This used to be commit 9cb6a4d76f87b28077861d3f4220541fbf704ddf) --- source3/modules/vfs_expand_msdfs.c | 184 +++++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 source3/modules/vfs_expand_msdfs.c (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c new file mode 100644 index 0000000000..954f28a411 --- /dev/null +++ b/source3/modules/vfs_expand_msdfs.c @@ -0,0 +1,184 @@ +/* + * Expand msdfs targets based on client IP + * + * Copyright (C) Volker Lendecke, 2004 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_VFS + +/********************************************************** + Under mapfile we expect a table of the following format: + + IP-Prefix whitespace expansion + + For example: + 192.168.234 local.samba.org + 192.168 remote.samba.org + default.samba.org + + This is to redirect a DFS client to a host close to it. +***********************************************************/ + +static BOOL read_target_host(const char *mapfile, pstring targethost) +{ + XFILE *f; + pstring buf; + char *s, *space = buf; + BOOL found = False; + + f = x_fopen(mapfile, O_RDONLY, 0); + + if (f == NULL) { + DEBUG(0,("can't open IP map %s. Error %s\n", + mapfile, strerror(errno) )); + return False; + } + + DEBUG(10, ("Scanning mapfile [%s]\n", mapfile)); + + while ((s=fgets_slash(buf, sizeof(buf), f)) != NULL) { + space = strchr_m(buf, ' '); + + if (space == NULL) { + DEBUG(0, ("Ignoring invalid line %s\n", buf)); + continue; + } + + *space = '\0'; + + if (strncmp(client_addr(), buf, strlen(buf)) == 0) { + found = True; + break; + } + } + + x_fclose(f); + + if (!found) + return False; + + space += 1; + + while (isspace(*space)) + space += 1; + + pstrcpy(targethost, space); + return True; +} + +/********************************************************** + + Expand the msdfs target host using read_target_host + explained above. The syntax used in the msdfs link is + + msdfs:@table-filename@/share + + Everything between and including the two @-signs is + replaced by the substitution string found in the table + described above. + +***********************************************************/ + +static BOOL expand_msdfs_target(connection_struct* conn, pstring target) +{ + pstring mapfilename; + char *filename_start = strchr_m(target, '@'); + char *filename_end; + int filename_len; + pstring targethost; + pstring new_target; + + if (filename_start == NULL) { + DEBUG(10, ("No filename start in %s\n", target)); + return False; + } + + filename_end = strchr_m(filename_start+1, '@'); + + if (filename_end == NULL) { + DEBUG(10, ("No filename end in %s\n", target)); + return False; + } + + filename_len = PTR_DIFF(filename_end, filename_start+1); + pstrcpy(mapfilename, filename_start+1); + mapfilename[filename_len] = '\0'; + + DEBUG(10, ("Expanding from table [%s]\n", mapfilename)); + + if (!read_target_host(mapfilename, targethost)) { + DEBUG(1, ("Could not expand target host from file %s\n", + mapfilename)); + return False; + } + + standard_sub_conn(conn, mapfilename, sizeof(mapfilename)); + + DEBUG(10, ("Expanded targethost to %s\n", targethost)); + + *filename_start = '\0'; + pstrcpy(new_target, target); + pstrcat(new_target, targethost); + pstrcat(new_target, filename_end+1); + + DEBUG(10, ("New DFS target: %s\n", new_target)); + pstrcpy(target, new_target); + return True; +} + +static int expand_msdfs_readlink(struct vfs_handle_struct *handle, + struct connection_struct *conn, + const char *path, char *buf, size_t bufsiz) +{ + pstring target; + int result; + + result = SMB_VFS_NEXT_READLINK(handle, conn, path, target, + sizeof(target)); + + if (result < 0) + return result; + + target[result] = '\0'; + + if (strchr_m(target, '@') != NULL) { + if (!expand_msdfs_target(conn, target)) { + errno = ENOENT; + return -1; + } + } + + safe_strcpy(buf, target, bufsiz-1); + return strlen(buf); +} + +/* VFS operations structure */ + +static vfs_op_tuple expand_msdfs_ops[] = { + {SMB_VFS_OP(expand_msdfs_readlink), SMB_VFS_OP_READLINK, + SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} +}; + +NTSTATUS vfs_expand_msdfs_init(void) +{ + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "expand_msdfs", + expand_msdfs_ops); +} -- cgit From f6d86af4a2488aee1b8fdacc7228c18e12edde37 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 29 Mar 2004 11:40:43 +0000 Subject: Some fixes to expand_msdfs module. Volker (This used to be commit 558b5bc1d81d8ccd2048b37357e4b3e5b9b4e011) --- source3/modules/vfs_expand_msdfs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 954f28a411..46a6616db9 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -53,7 +53,13 @@ static BOOL read_target_host(const char *mapfile, pstring targethost) DEBUG(10, ("Scanning mapfile [%s]\n", mapfile)); - while ((s=fgets_slash(buf, sizeof(buf), f)) != NULL) { + while ((s=x_fgets(buf, sizeof(buf), f)) != NULL) { + + if (buf[strlen(buf)-1] == '\n') + buf[strlen(buf)-1] = '\0'; + + DEBUG(10, ("Scanning line [%s]\n", buf)); + space = strchr_m(buf, ' '); if (space == NULL) { @@ -158,7 +164,8 @@ static int expand_msdfs_readlink(struct vfs_handle_struct *handle, target[result] = '\0'; - if (strchr_m(target, '@') != NULL) { + if ((strncmp(target, "msdfs:", strlen("msdfs:")) == 0) && + (strchr_m(target, '@') != NULL)) { if (!expand_msdfs_target(conn, target)) { errno = ENOENT; return -1; -- cgit From 4ee66eb4c3ffc575dde7aa7156a0dca1b23825e1 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 29 Mar 2004 11:54:34 +0000 Subject: Without words... (This used to be commit 9cb6b10efa3c7d50d3e686bda122121c61633419) --- source3/modules/vfs_expand_msdfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 46a6616db9..07fbe59825 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -55,7 +55,7 @@ static BOOL read_target_host(const char *mapfile, pstring targethost) while ((s=x_fgets(buf, sizeof(buf), f)) != NULL) { - if (buf[strlen(buf)-1] == '\n') + if ((strlen(buf) > 0) && (buf[strlen(buf)-1] == '\n')) buf[strlen(buf)-1] = '\0'; DEBUG(10, ("Scanning line [%s]\n", buf)); -- cgit From 74dd9f1186b388f884c0c6c56e3fabf618520f67 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 20 Jan 2005 01:19:57 +0000 Subject: r4864: Remove unused var. Jeremy. (This used to be commit 9fd5d633e65e00a44ba0136ee91170edcecfae24) --- source3/modules/vfs_expand_msdfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 07fbe59825..d22f6a7f98 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -40,7 +40,7 @@ static BOOL read_target_host(const char *mapfile, pstring targethost) { XFILE *f; pstring buf; - char *s, *space = buf; + char *space = buf; BOOL found = False; f = x_fopen(mapfile, O_RDONLY, 0); @@ -53,7 +53,7 @@ static BOOL read_target_host(const char *mapfile, pstring targethost) DEBUG(10, ("Scanning mapfile [%s]\n", mapfile)); - while ((s=x_fgets(buf, sizeof(buf), f)) != NULL) { + while (x_fgets(buf, sizeof(buf), f) != NULL) { if ((strlen(buf) > 0) && (buf[strlen(buf)-1] == '\n')) buf[strlen(buf)-1] = '\0'; -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/modules/vfs_expand_msdfs.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index d22f6a7f98..fdd9ac6fbd 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -110,6 +110,7 @@ static BOOL expand_msdfs_target(connection_struct* conn, pstring target) int filename_len; pstring targethost; pstring new_target; + extern userdom_struct current_user_info; if (filename_start == NULL) { DEBUG(10, ("No filename start in %s\n", target)); @@ -135,7 +136,11 @@ static BOOL expand_msdfs_target(connection_struct* conn, pstring target) return False; } - standard_sub_conn(conn, mapfilename, sizeof(mapfilename)); + standard_sub_advanced(lp_servicename(SNUM(conn)), conn->user, + conn->connectpath, conn->gid, + get_current_username(), + current_user_info.domain, + mapfilename, sizeof(mapfilename)); DEBUG(10, ("Expanded targethost to %s\n", targethost)); @@ -150,13 +155,12 @@ static BOOL expand_msdfs_target(connection_struct* conn, pstring target) } static int expand_msdfs_readlink(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, char *buf, size_t bufsiz) { pstring target; int result; - result = SMB_VFS_NEXT_READLINK(handle, conn, path, target, + result = SMB_VFS_NEXT_READLINK(handle, path, target, sizeof(target)); if (result < 0) @@ -166,7 +170,7 @@ static int expand_msdfs_readlink(struct vfs_handle_struct *handle, if ((strncmp(target, "msdfs:", strlen("msdfs:")) == 0) && (strchr_m(target, '@') != NULL)) { - if (!expand_msdfs_target(conn, target)) { + if (!expand_msdfs_target(handle->conn, target)) { errno = ENOENT; return -1; } -- cgit From 791f48f167de339c8ae371e5c80706511fd10018 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Tue, 12 Dec 2006 17:38:42 +0000 Subject: r20124: clean up nested extern declaration warnings (This used to be commit ac3eb7813e33b9a2e78c9158433f7ed62c3b62bb) --- source3/modules/vfs_expand_msdfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index fdd9ac6fbd..2abab4dd2f 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -23,6 +23,8 @@ #undef DBGC_CLASS #define DBGC_CLASS DBGC_VFS +extern userdom_struct current_user_info; + /********************************************************** Under mapfile we expect a table of the following format: @@ -110,7 +112,6 @@ static BOOL expand_msdfs_target(connection_struct* conn, pstring target) int filename_len; pstring targethost; pstring new_target; - extern userdom_struct current_user_info; if (filename_start == NULL) { DEBUG(10, ("No filename start in %s\n", target)); -- cgit From 55ed1d59455566d90a03e7123fbf7a05a4bd4539 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Tue, 19 Dec 2006 20:16:52 +0000 Subject: r20261: merge 20260 from samba_3_0_24 clean up a bunch of no previous prototype warnings (This used to be commit c60687db112405262adf26dbf267804b04074e67) --- source3/modules/vfs_expand_msdfs.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 2abab4dd2f..7176c11e4a 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -189,6 +189,7 @@ static vfs_op_tuple expand_msdfs_ops[] = { {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} }; +NTSTATUS vfs_expand_msdfs_init(void); NTSTATUS vfs_expand_msdfs_init(void) { return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "expand_msdfs", -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/modules/vfs_expand_msdfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 7176c11e4a..bfcb188760 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -5,7 +5,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, -- cgit From 153cfb9c83534b09f15cc16205d7adb19b394928 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 87c91e4362c51819032bfbebbb273c52e203b227) --- source3/modules/vfs_expand_msdfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index bfcb188760..10194f17d3 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ #include "includes.h" -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/modules/vfs_expand_msdfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 10194f17d3..e2a4a18bf0 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -37,12 +37,12 @@ extern userdom_struct current_user_info; This is to redirect a DFS client to a host close to it. ***********************************************************/ -static BOOL read_target_host(const char *mapfile, pstring targethost) +static bool read_target_host(const char *mapfile, pstring targethost) { XFILE *f; pstring buf; char *space = buf; - BOOL found = False; + bool found = False; f = x_fopen(mapfile, O_RDONLY, 0); @@ -103,7 +103,7 @@ static BOOL read_target_host(const char *mapfile, pstring targethost) ***********************************************************/ -static BOOL expand_msdfs_target(connection_struct* conn, pstring target) +static bool expand_msdfs_target(connection_struct* conn, pstring target) { pstring mapfilename; char *filename_start = strchr_m(target, '@'); -- cgit From 6658165d5e9cd186fea74e1581091233e8990e9b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Nov 2007 18:15:45 -0700 Subject: Stop get_peer_addr() and client_addr() from using global statics. Part of my library cleanups. Jeremy. (This used to be commit e848506c858bd16706c1d7f6b4b032005512b8ac) --- source3/modules/vfs_expand_msdfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index e2a4a18bf0..12f2c8e72b 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -55,6 +55,7 @@ static bool read_target_host(const char *mapfile, pstring targethost) DEBUG(10, ("Scanning mapfile [%s]\n", mapfile)); while (x_fgets(buf, sizeof(buf), f) != NULL) { + char addr[INET6_ADDRSTRLEN]; if ((strlen(buf) > 0) && (buf[strlen(buf)-1] == '\n')) buf[strlen(buf)-1] = '\0'; @@ -70,7 +71,7 @@ static bool read_target_host(const char *mapfile, pstring targethost) *space = '\0'; - if (strncmp(client_addr(), buf, strlen(buf)) == 0) { + if (strncmp(client_addr(addr), buf, strlen(buf)) == 0) { found = True; break; } -- cgit From 25074433f412c4dd2531fd268d51be8753ddc11b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Nov 2007 18:41:26 -0700 Subject: I can't get away without a 'length' arg. :-). Jeremy. (This used to be commit 95d01279a5def709d0a5d5ae7224d6286006d120) --- source3/modules/vfs_expand_msdfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 12f2c8e72b..4b670d5172 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -71,7 +71,8 @@ static bool read_target_host(const char *mapfile, pstring targethost) *space = '\0'; - if (strncmp(client_addr(addr), buf, strlen(buf)) == 0) { + if (strncmp(client_addr(addr,sizeof(addr)), + buf, strlen(buf)) == 0) { found = True; break; } -- cgit From 5b0b4f23ef5fec3d1ad518237f973d4e014b5766 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Nov 2007 23:20:10 -0700 Subject: Remove most of the remaining globals out of lib/util_sock.c. I have a plan for dealing with the remaining..... Watch this space. Jeremy. (This used to be commit 963fc7685212689f02b3adcc05b4273ee5c382d4) --- source3/modules/vfs_expand_msdfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 4b670d5172..2a16b5a731 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -71,7 +71,7 @@ static bool read_target_host(const char *mapfile, pstring targethost) *space = '\0'; - if (strncmp(client_addr(addr,sizeof(addr)), + if (strncmp(client_addr(get_client_fd(),addr,sizeof(addr)), buf, strlen(buf)) == 0) { found = True; break; -- cgit From 882987594455c6676d0b01618d91bdbfc5e3b267 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 16 Nov 2007 17:07:11 -0800 Subject: Remove pstring from modules directory. Jeremy. (This used to be commit 977dc3accb3d440e5fd19591c425da7dc3718d94) --- source3/modules/vfs_expand_msdfs.c | 89 +++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 35 deletions(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 2a16b5a731..9d4883c085 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -37,19 +37,19 @@ extern userdom_struct current_user_info; This is to redirect a DFS client to a host close to it. ***********************************************************/ -static bool read_target_host(const char *mapfile, pstring targethost) +static char *read_target_host(TALLOC_CTX *ctx, const char *mapfile) { XFILE *f; - pstring buf; + char buf[1024]; char *space = buf; - bool found = False; - + bool found = false; + f = x_fopen(mapfile, O_RDONLY, 0); if (f == NULL) { DEBUG(0,("can't open IP map %s. Error %s\n", mapfile, strerror(errno) )); - return False; + return NULL; } DEBUG(10, ("Scanning mapfile [%s]\n", mapfile)); @@ -73,23 +73,23 @@ static bool read_target_host(const char *mapfile, pstring targethost) if (strncmp(client_addr(get_client_fd(),addr,sizeof(addr)), buf, strlen(buf)) == 0) { - found = True; + found = true; break; } } x_fclose(f); - if (!found) - return False; + if (!found) { + return NULL; + } space += 1; while (isspace(*space)) space += 1; - pstrcpy(targethost, space); - return True; + return talloc_strdup(ctx, space); } /********************************************************** @@ -105,65 +105,83 @@ static bool read_target_host(const char *mapfile, pstring targethost) ***********************************************************/ -static bool expand_msdfs_target(connection_struct* conn, pstring target) +static char *expand_msdfs_target(TALLOC_CTX *ctx, + connection_struct *conn, + char *target) { - pstring mapfilename; + char *mapfilename = NULL; char *filename_start = strchr_m(target, '@'); - char *filename_end; - int filename_len; - pstring targethost; - pstring new_target; + char *filename_end = NULL; + int filename_len = 0; + char *targethost = NULL; + char *new_target = NULL; if (filename_start == NULL) { DEBUG(10, ("No filename start in %s\n", target)); - return False; + return NULL; } filename_end = strchr_m(filename_start+1, '@'); if (filename_end == NULL) { DEBUG(10, ("No filename end in %s\n", target)); - return False; + return NULL; } filename_len = PTR_DIFF(filename_end, filename_start+1); - pstrcpy(mapfilename, filename_start+1); + mapfilename = talloc_strdup(ctx, filename_start+1); + if (!mapfilename) { + return NULL; + } mapfilename[filename_len] = '\0'; DEBUG(10, ("Expanding from table [%s]\n", mapfilename)); - if (!read_target_host(mapfilename, targethost)) { + if ((targethost = read_target_host(ctx, mapfilename)) == NULL) { DEBUG(1, ("Could not expand target host from file %s\n", mapfilename)); - return False; + return NULL; } - standard_sub_advanced(lp_servicename(SNUM(conn)), conn->user, - conn->connectpath, conn->gid, - get_current_username(), - current_user_info.domain, - mapfilename, sizeof(mapfilename)); + targethost = talloc_sub_advanced(ctx, + lp_servicename(SNUM(conn)), + conn->user, + conn->connectpath, + conn->gid, + get_current_username(), + current_user_info.domain, + targethost); DEBUG(10, ("Expanded targethost to %s\n", targethost)); + /* Replace the part between '@...@' */ *filename_start = '\0'; - pstrcpy(new_target, target); - pstrcat(new_target, targethost); - pstrcat(new_target, filename_end+1); + new_target = talloc_asprintf(ctx, + "%s%s%s", + target, + targethost, + filename_end+1); + if (!new_target) { + return NULL; + } DEBUG(10, ("New DFS target: %s\n", new_target)); - pstrcpy(target, new_target); - return True; + return new_target; } static int expand_msdfs_readlink(struct vfs_handle_struct *handle, const char *path, char *buf, size_t bufsiz) { - pstring target; + TALLOC_CTX *ctx = talloc_tos(); int result; + char *target = TALLOC_ARRAY(ctx, char, PATH_MAX+1); + if (!target) { + errno = ENOMEM; + return -1; + } result = SMB_VFS_NEXT_READLINK(handle, path, target, - sizeof(target)); + PATH_MAX); if (result < 0) return result; @@ -172,7 +190,8 @@ static int expand_msdfs_readlink(struct vfs_handle_struct *handle, if ((strncmp(target, "msdfs:", strlen("msdfs:")) == 0) && (strchr_m(target, '@') != NULL)) { - if (!expand_msdfs_target(handle->conn, target)) { + target = expand_msdfs_target(ctx, handle->conn, target); + if (!target) { errno = ENOENT; return -1; } @@ -184,7 +203,7 @@ static int expand_msdfs_readlink(struct vfs_handle_struct *handle, /* VFS operations structure */ -static vfs_op_tuple expand_msdfs_ops[] = { +static vfs_op_tuple expand_msdfs_ops[] = { {SMB_VFS_OP(expand_msdfs_readlink), SMB_VFS_OP_READLINK, SMB_VFS_LAYER_TRANSPARENT}, {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} -- cgit From 53a623d8a69b5dd7fbd964013032878e09032375 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 8 May 2008 15:53:55 +0200 Subject: Remove the unix token info from connection_struct (This used to be commit 2834dacc8d49f77fe55fb5d7e3eb2dda431d1d3d) --- source3/modules/vfs_expand_msdfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 9d4883c085..62222c48ff 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -147,7 +147,7 @@ static char *expand_msdfs_target(TALLOC_CTX *ctx, lp_servicename(SNUM(conn)), conn->user, conn->connectpath, - conn->gid, + conn->server_info->gid, get_current_username(), current_user_info.domain, targethost); -- cgit From 5bda9a8af02c7889e15e580a5620689aa312a16a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 8 May 2008 16:06:42 +0200 Subject: Remove "user" from connection_struct (This used to be commit 368454a27cb53a408ec416cbf37235b304592fb5) --- source3/modules/vfs_expand_msdfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 62222c48ff..133c5eb28b 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -145,7 +145,7 @@ static char *expand_msdfs_target(TALLOC_CTX *ctx, targethost = talloc_sub_advanced(ctx, lp_servicename(SNUM(conn)), - conn->user, + conn->server_info->unix_name, conn->connectpath, conn->server_info->gid, get_current_username(), -- cgit From 50ab871813d8281760e0c70d454cba996e0b67d8 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 11 May 2008 11:26:33 +0200 Subject: Remove some references to get_current_username() and current_user_info (This used to be commit 344d69f95e217d16213eaa6b53141af6ab459708) --- source3/modules/vfs_expand_msdfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 133c5eb28b..9b85ad2dda 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -148,7 +148,7 @@ static char *expand_msdfs_target(TALLOC_CTX *ctx, conn->server_info->unix_name, conn->connectpath, conn->server_info->gid, - get_current_username(), + conn->server_info->sanitized_username, current_user_info.domain, targethost); -- cgit From ff215c4f81abb70a76fd6517c61ba2954c5e3312 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 19 Jun 2008 15:44:15 +0200 Subject: Remove current_user_info reference from vfs_expand_msdfs.c (This used to be commit 05a66980a9b5a7c6222ceb038d819d23fd172186) --- source3/modules/vfs_expand_msdfs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 9b85ad2dda..3654ae4351 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -22,8 +22,6 @@ #undef DBGC_CLASS #define DBGC_CLASS DBGC_VFS -extern userdom_struct current_user_info; - /********************************************************** Under mapfile we expect a table of the following format: @@ -149,7 +147,7 @@ static char *expand_msdfs_target(TALLOC_CTX *ctx, conn->connectpath, conn->server_info->gid, conn->server_info->sanitized_username, - current_user_info.domain, + pdb_get_domain(conn->server_info->sam_account), targethost); DEBUG(10, ("Expanded targethost to %s\n", targethost)); -- cgit From 40f5eab5eb515937e1b23cf6762b77c194d29b9d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 19 Jun 2008 16:54:12 +0200 Subject: Wrap the unix token info in a unix_user_token in auth_serversupplied_info No functional change, this is a preparation for more current_user ref removal (This used to be commit dcaedf345e62ab74ea87f0a3fa1e3199c75c5445) --- source3/modules/vfs_expand_msdfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/modules/vfs_expand_msdfs.c') diff --git a/source3/modules/vfs_expand_msdfs.c b/source3/modules/vfs_expand_msdfs.c index 3654ae4351..0d09d213e1 100644 --- a/source3/modules/vfs_expand_msdfs.c +++ b/source3/modules/vfs_expand_msdfs.c @@ -145,7 +145,7 @@ static char *expand_msdfs_target(TALLOC_CTX *ctx, lp_servicename(SNUM(conn)), conn->server_info->unix_name, conn->connectpath, - conn->server_info->gid, + conn->server_info->utok.gid, conn->server_info->sanitized_username, pdb_get_domain(conn->server_info->sam_account), targethost); -- cgit