Author: jra Date: 2007-09-14 22:03:41 +0000 (Fri, 14 Sep 2007) New Revision: 25170
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=25170 Log: Remove pstring limits from ms_fnmatch and module load. Jeremy. Modified: branches/SAMBA_3_2/source/lib/module.c branches/SAMBA_3_2/source/lib/ms_fnmatch.c branches/SAMBA_3_2/source/nmbd/nmbd_processlogon.c branches/SAMBA_3_2_0/source/lib/module.c branches/SAMBA_3_2_0/source/lib/ms_fnmatch.c branches/SAMBA_3_2_0/source/nmbd/nmbd_processlogon.c Changeset: Modified: branches/SAMBA_3_2/source/lib/module.c =================================================================== --- branches/SAMBA_3_2/source/lib/module.c 2007-09-14 18:31:33 UTC (rev 25169) +++ branches/SAMBA_3_2/source/lib/module.c 2007-09-14 22:03:41 UTC (rev 25170) @@ -76,7 +76,7 @@ return do_smb_load_module(module_name, False); } -/* Load all modules in list and return number of +/* Load all modules in list and return number of * modules that has been successfully loaded */ int smb_load_modules(const char **modules) { @@ -96,28 +96,38 @@ NTSTATUS smb_probe_module(const char *subsystem, const char *module) { - pstring full_path; - + char *full_path = NULL; + TALLOC_CTX *ctx = talloc_stackframe(); + NTSTATUS status; + /* Check for absolute path */ - /* if we make any 'samba multibyte string' - calls here, we break + /* if we make any 'samba multibyte string' + calls here, we break for loading string modules */ DEBUG(5, ("Probing module '%s'\n", module)); if (module[0] == '/') return do_smb_load_module(module, True); - - pstrcpy(full_path, lib_path(subsystem)); - pstrcat(full_path, "/"); - pstrcat(full_path, module); - pstrcat(full_path, "."); - pstrcat(full_path, shlib_ext()); - DEBUG(5, ("Probing module '%s': Trying to load from %s\n", module, full_path)); - - return do_smb_load_module(full_path, True); + full_path = talloc_asprintf(ctx, + "%s/%s.%s", + lib_path(subsystem), + module, + shlib_ext()); + if (!full_path) { + TALLOC_FREE(ctx); + return NT_STATUS_NO_MEMORY; + } + + DEBUG(5, ("Probing module '%s': Trying to load from %s\n", + module, full_path)); + + status = do_smb_load_module(full_path, True); + + TALLOC_FREE(ctx); + return status; } #else /* HAVE_DLOPEN */ Modified: branches/SAMBA_3_2/source/lib/ms_fnmatch.c =================================================================== --- branches/SAMBA_3_2/source/lib/ms_fnmatch.c 2007-09-14 18:31:33 UTC (rev 25169) +++ branches/SAMBA_3_2/source/lib/ms_fnmatch.c 2007-09-14 22:03:41 UTC (rev 25170) @@ -1,4 +1,4 @@ -/* +/* Unix SMB/CIFS implementation. filename matching routine Copyright (C) Andrew Tridgell 1992-2004 @@ -7,21 +7,21 @@ it under the terms of the GNU General Public License as published by 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, 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, see <http://www.gnu.org/licenses/>. + along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* This module was originally based on fnmatch.c copyright by the Free Software Foundation. It bears little (if any) resemblence to that code now -*/ +*/ #include "includes.h" @@ -53,7 +53,7 @@ an optimisation only. The ldot pointer is NULL if the string does not contain a '.', otherwise it points at the last dot in 'n'. */ -static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n, +static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n, struct max_n *max_n, const smb_ucs2_t *ldot, BOOL is_case_sensitive) { @@ -137,22 +137,23 @@ break; } } - + if (! *n) { return 0; } - + return -1; } int ms_fnmatch(const char *pattern, const char *string, BOOL translate_pattern, BOOL is_case_sensitive) { - wpstring p, s; + smb_ucs2_t *p = NULL; + smb_ucs2_t *s = NULL; int ret, count, i; struct max_n *max_n = NULL; - if (strcmp(string, "..") == 0) { + if (ISDOTDOT(string)) { string = "."; } @@ -166,15 +167,12 @@ } } - if (push_ucs2(NULL, p, pattern, sizeof(p), STR_TERMINATE) == (size_t)-1) { - /* Not quite the right answer, but finding the right one - under this failure case is expensive, and it's pretty close */ + if (push_ucs2_allocate(&p, pattern) == (size_t)-1) { return -1; } - if (push_ucs2(NULL, s, string, sizeof(s), STR_TERMINATE) == (size_t)-1) { - /* Not quite the right answer, but finding the right one - under this failure case is expensive, and it's pretty close */ + if (push_ucs2_allocate(&s, string) == (size_t)-1) { + SAFE_FREE(p); return -1; } @@ -187,8 +185,8 @@ for (i=0;p[i];i++) { if (p[i] == UCS2_CHAR('?')) { p[i] = UCS2_CHAR('>'); - } else if (p[i] == UCS2_CHAR('.') && - (p[i+1] == UCS2_CHAR('?') || + } else if (p[i] == UCS2_CHAR('.') && + (p[i+1] == UCS2_CHAR('?') || p[i+1] == UCS2_CHAR('*') || p[i+1] == 0)) { p[i] = UCS2_CHAR('"'); @@ -205,16 +203,17 @@ if (count != 0) { max_n = SMB_CALLOC_ARRAY(struct max_n, count); if (!max_n) { + SAFE_FREE(p); + SAFE_FREE(s); return -1; } } ret = ms_fnmatch_core(p, s, max_n, strrchr_w(s, UCS2_CHAR('.')), is_case_sensitive); - if (max_n) { - free(max_n); - } - + SAFE_FREE(max_n); + SAFE_FREE(p); + SAFE_FREE(s); return ret; } Modified: branches/SAMBA_3_2/source/nmbd/nmbd_processlogon.c =================================================================== --- branches/SAMBA_3_2/source/nmbd/nmbd_processlogon.c 2007-09-14 18:31:33 UTC (rev 25169) +++ branches/SAMBA_3_2/source/nmbd/nmbd_processlogon.c 2007-09-14 22:03:41 UTC (rev 25170) @@ -220,7 +220,7 @@ sizeof(pstring) - PTR_DIFF(q, outbuf), True); /* PDC name */ q += dos_PutUniCode(q, lp_workgroup(), - sizeof(pstring) - (q-outbuf), + sizeof(pstring) - PTR_DIFF(q, outbuf), True); /* Domain name*/ if (sizeof(pstring) - PTR_DIFF(q, outbuf) < 8) { return; @@ -525,7 +525,7 @@ q += 4; /* unknown */ SIVAL(q, 0, 0x00000000); q += 4; /* unknown */ - } + } #endif if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) { @@ -535,7 +535,7 @@ /* tell the client what version we are */ SIVAL(q, 0, ((ntversion < 11) || (SEC_ADS != lp_security())) ? 1 : 13); /* our ntversion */ - SSVAL(q, 4, 0xffff); /* our lmnttoken */ + SSVAL(q, 4, 0xffff); /* our lmnttoken */ SSVAL(q, 6, 0xffff); /* our lm20token */ q += 8; @@ -549,7 +549,7 @@ global_myname(), 0x0, source_name, dgram->source_name.name_type, - p->ip, *iface_ip(p->ip), p->port); + p->ip, *iface_ip(p->ip), p->port); break; } Modified: branches/SAMBA_3_2_0/source/lib/module.c =================================================================== --- branches/SAMBA_3_2_0/source/lib/module.c 2007-09-14 18:31:33 UTC (rev 25169) +++ branches/SAMBA_3_2_0/source/lib/module.c 2007-09-14 22:03:41 UTC (rev 25170) @@ -76,7 +76,7 @@ return do_smb_load_module(module_name, False); } -/* Load all modules in list and return number of +/* Load all modules in list and return number of * modules that has been successfully loaded */ int smb_load_modules(const char **modules) { @@ -96,28 +96,38 @@ NTSTATUS smb_probe_module(const char *subsystem, const char *module) { - pstring full_path; - + char *full_path = NULL; + TALLOC_CTX *ctx = talloc_stackframe(); + NTSTATUS status; + /* Check for absolute path */ - /* if we make any 'samba multibyte string' - calls here, we break + /* if we make any 'samba multibyte string' + calls here, we break for loading string modules */ DEBUG(5, ("Probing module '%s'\n", module)); if (module[0] == '/') return do_smb_load_module(module, True); - - pstrcpy(full_path, lib_path(subsystem)); - pstrcat(full_path, "/"); - pstrcat(full_path, module); - pstrcat(full_path, "."); - pstrcat(full_path, shlib_ext()); - DEBUG(5, ("Probing module '%s': Trying to load from %s\n", module, full_path)); - - return do_smb_load_module(full_path, True); + full_path = talloc_asprintf(ctx, + "%s/%s.%s", + lib_path(subsystem), + module, + shlib_ext()); + if (!full_path) { + TALLOC_FREE(ctx); + return NT_STATUS_NO_MEMORY; + } + + DEBUG(5, ("Probing module '%s': Trying to load from %s\n", + module, full_path)); + + status = do_smb_load_module(full_path, True); + + TALLOC_FREE(ctx); + return status; } #else /* HAVE_DLOPEN */ Modified: branches/SAMBA_3_2_0/source/lib/ms_fnmatch.c =================================================================== --- branches/SAMBA_3_2_0/source/lib/ms_fnmatch.c 2007-09-14 18:31:33 UTC (rev 25169) +++ branches/SAMBA_3_2_0/source/lib/ms_fnmatch.c 2007-09-14 22:03:41 UTC (rev 25170) @@ -1,4 +1,4 @@ -/* +/* Unix SMB/CIFS implementation. filename matching routine Copyright (C) Andrew Tridgell 1992-2004 @@ -7,21 +7,21 @@ it under the terms of the GNU General Public License as published by 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, 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, see <http://www.gnu.org/licenses/>. + along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* This module was originally based on fnmatch.c copyright by the Free Software Foundation. It bears little (if any) resemblence to that code now -*/ +*/ #include "includes.h" @@ -53,7 +53,7 @@ an optimisation only. The ldot pointer is NULL if the string does not contain a '.', otherwise it points at the last dot in 'n'. */ -static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n, +static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n, struct max_n *max_n, const smb_ucs2_t *ldot, BOOL is_case_sensitive) { @@ -137,22 +137,23 @@ break; } } - + if (! *n) { return 0; } - + return -1; } int ms_fnmatch(const char *pattern, const char *string, BOOL translate_pattern, BOOL is_case_sensitive) { - wpstring p, s; + smb_ucs2_t *p = NULL; + smb_ucs2_t *s = NULL; int ret, count, i; struct max_n *max_n = NULL; - if (strcmp(string, "..") == 0) { + if (ISDOTDOT(string)) { string = "."; } @@ -166,15 +167,12 @@ } } - if (push_ucs2(NULL, p, pattern, sizeof(p), STR_TERMINATE) == (size_t)-1) { - /* Not quite the right answer, but finding the right one - under this failure case is expensive, and it's pretty close */ + if (push_ucs2_allocate(&p, pattern) == (size_t)-1) { return -1; } - if (push_ucs2(NULL, s, string, sizeof(s), STR_TERMINATE) == (size_t)-1) { - /* Not quite the right answer, but finding the right one - under this failure case is expensive, and it's pretty close */ + if (push_ucs2_allocate(&s, string) == (size_t)-1) { + SAFE_FREE(p); return -1; } @@ -187,8 +185,8 @@ for (i=0;p[i];i++) { if (p[i] == UCS2_CHAR('?')) { p[i] = UCS2_CHAR('>'); - } else if (p[i] == UCS2_CHAR('.') && - (p[i+1] == UCS2_CHAR('?') || + } else if (p[i] == UCS2_CHAR('.') && + (p[i+1] == UCS2_CHAR('?') || p[i+1] == UCS2_CHAR('*') || p[i+1] == 0)) { p[i] = UCS2_CHAR('"'); @@ -205,16 +203,17 @@ if (count != 0) { max_n = SMB_CALLOC_ARRAY(struct max_n, count); if (!max_n) { + SAFE_FREE(p); + SAFE_FREE(s); return -1; } } ret = ms_fnmatch_core(p, s, max_n, strrchr_w(s, UCS2_CHAR('.')), is_case_sensitive); - if (max_n) { - free(max_n); - } - + SAFE_FREE(max_n); + SAFE_FREE(p); + SAFE_FREE(s); return ret; } Modified: branches/SAMBA_3_2_0/source/nmbd/nmbd_processlogon.c =================================================================== --- branches/SAMBA_3_2_0/source/nmbd/nmbd_processlogon.c 2007-09-14 18:31:33 UTC (rev 25169) +++ branches/SAMBA_3_2_0/source/nmbd/nmbd_processlogon.c 2007-09-14 22:03:41 UTC (rev 25170) @@ -220,7 +220,7 @@ sizeof(pstring) - PTR_DIFF(q, outbuf), True); /* PDC name */ q += dos_PutUniCode(q, lp_workgroup(), - sizeof(pstring) - (q-outbuf), + sizeof(pstring) - PTR_DIFF(q, outbuf), True); /* Domain name*/ if (sizeof(pstring) - PTR_DIFF(q, outbuf) < 8) { return; @@ -525,7 +525,7 @@ q += 4; /* unknown */ SIVAL(q, 0, 0x00000000); q += 4; /* unknown */ - } + } #endif if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) { @@ -535,7 +535,7 @@ /* tell the client what version we are */ SIVAL(q, 0, ((ntversion < 11) || (SEC_ADS != lp_security())) ? 1 : 13); /* our ntversion */ - SSVAL(q, 4, 0xffff); /* our lmnttoken */ + SSVAL(q, 4, 0xffff); /* our lmnttoken */ SSVAL(q, 6, 0xffff); /* our lm20token */ q += 8; @@ -549,7 +549,7 @@ global_myname(), 0x0, source_name, dgram->source_name.name_type, - p->ip, *iface_ip(p->ip), p->port); + p->ip, *iface_ip(p->ip), p->port); break; }