r25170: Remove pstring limits from ms_fnmatch and module load.
authorJeremy Allison <jra@samba.org>
Fri, 14 Sep 2007 22:03:41 +0000 (22:03 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:30:48 +0000 (12:30 -0500)
Jeremy.

source/lib/module.c
source/lib/ms_fnmatch.c
source/nmbd/nmbd_processlogon.c

index 1bf305ea3f70ebbe4cb8e434215a6946e4842d5e..beb9bc9b925a84a049b6530da112ee576fad1dc4 100644 (file)
@@ -76,7 +76,7 @@ NTSTATUS smb_load_module(const char *module_name)
        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 @@ int smb_load_modules(const char **modules)
 
 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 */
index bdfaca143cfd3a6e293b3142d479f0d04a93a020..9dc942c5f2ed3db3fe32ade3920b4d8c267b8088 100644 (file)
@@ -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 @@ struct max_n {
   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 @@ static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n,
                        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 @@ int ms_fnmatch(const char *pattern, const char *string, BOOL translate_pattern,
                }
        }
 
-       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 @@ int ms_fnmatch(const char *pattern, const char *string, BOOL translate_pattern,
                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 @@ int ms_fnmatch(const char *pattern, const char *string, BOOL translate_pattern,
        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;
 }
 
index 1ba45ce8df3e7872b2fd32dd0d2f75cb5f29b8ec..8a183c4d24a1b72c61c848fdda6cd96562db2f33 100644 (file)
@@ -220,7 +220,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) ));
                                                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 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
                                        q += 4; /* unknown */
                                        SIVAL(q, 0, 0x00000000);
                                        q += 4; /* unknown */
-                               }       
+                               }
 #endif
 
                                if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) {
@@ -535,7 +535,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
                                /* 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 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
                                        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;
                        }