Fix bug 7781 - Samba transforms ShareName to lowercase (sharename) when adding new...
authorJeremy Allison <jra@samba.org>
Wed, 10 Nov 2010 00:39:24 +0000 (16:39 -0800)
committerJeremy Allison <jra@samba.org>
Wed, 10 Nov 2010 00:39:24 +0000 (16:39 -0800)
Change the find_service() interface to not depend on fstring, and
create a useable talloc-based interface.

Jeremy.

source3/include/proto.h
source3/lib/dummysmbd.c
source3/lib/util_str.c
source3/modules/vfs_xattr_tdb.c
source3/param/loadparm.c
source3/printing/nt_printing.c
source3/rpc_server/srv_srvsvc_nt.c
source3/smbd/lanman.c
source3/smbd/msdfs.c
source3/smbd/service.c
source3/smbd/smb2_tcon.c

index 16755e2c734119643b892fd2fc3dd906b427489a..5272e9645a120a0099c6ae48664e706872f70c42 100644 (file)
@@ -5387,7 +5387,7 @@ bool set_conn_connectpath(connection_struct *conn, const char *connectpath);
 bool set_current_service(connection_struct *conn, uint16 flags, bool do_chdir);
 void load_registry_shares(void);
 int add_home_service(const char *service, const char *username, const char *homedir);
-int find_service(fstring service);
+int find_service(TALLOC_CTX *ctx, const char *service, char **p_service_out);
 connection_struct *make_connection_snum(struct smbd_server_connection *sconn,
                                        int snum, user_struct *vuser,
                                        DATA_BLOB password,
index 01a55633068e66658c1bda670225c5f08639f430..0e52a2d8619379f9b8aa7f19699060fb04de522e 100644 (file)
@@ -28,7 +28,7 @@ int get_client_fd(void)
        return -1;
 }
 
-int find_service(fstring service)
+int find_service(TALLOC_CTX *ctx, const char *service_in, char **p_service_out)
 {
        return -1;
 }
index 508050d892d9f9c78532ccfa17cf746e9f87f1a3..61b46edc5daf522a98c2721501ad49e4f5612c69 100644 (file)
@@ -2307,6 +2307,10 @@ bool validate_net_name( const char *name,
 {
        int i;
 
+       if (!name) {
+               return false;
+       }
+
        for ( i=0; i<max_len && name[i]; i++ ) {
                /* fail if strchr_m() finds one of the invalid characters */
                if ( name[i] && strchr_m( invalid_chars, name[i] ) ) {
index 28b21b6bf6964071a4439208c17ee06bc86bc2ff..e565e54522b8095bbd0a3cc5d447d0e1df562b84 100644 (file)
@@ -723,7 +723,7 @@ static void close_xattr_db(void **data)
 static int xattr_tdb_connect(vfs_handle_struct *handle, const char *service,
                          const char *user)
 {
-       fstring sname;
+       char *sname = NULL;
        int res, snum;
        struct db_context *db;
 
@@ -732,9 +732,8 @@ static int xattr_tdb_connect(vfs_handle_struct *handle, const char *service,
                return res;
        }
 
-       fstrcpy(sname, service);
-       snum = find_service(sname);
-       if (snum == -1) {
+       snum = find_service(talloc_tos(), service, &sname);
+       if (snum == -1 || sname == NULL) {
                /*
                 * Should not happen, but we should not fail just *here*.
                 */
index 1552fae859b5393d16712471912e685c2b715a8a..8b533518af1d7681bd78a9e81673dc45cdddf4a6 100644 (file)
@@ -9454,17 +9454,11 @@ struct share_params *get_share_params(TALLOC_CTX *mem_ctx,
                                      const char *sharename)
 {
        struct share_params *result;
-       char *sname;
+       char *sname = NULL;
        int snum;
 
-       if (!(sname = SMB_STRDUP(sharename))) {
-               return NULL;
-       }
-
-       snum = find_service(sname);
-       SAFE_FREE(sname);
-
-       if (snum < 0) {
+       snum = find_service(mem_ctx, sharename, &sname);
+       if (snum < 0 || sname == NULL) {
                return NULL;
        }
 
index c1101cfd68ed19f8ab47a9c3eed6f8941c1ed5a0..ee1ac76d152f436b4f0c424018dd3b5aa901010e 100644 (file)
@@ -586,7 +586,7 @@ static uint32 get_correct_cversion(struct pipes_struct *p,
        connection_struct *conn = NULL;
        NTSTATUS status;
        char *oldcwd;
-       fstring printdollar;
+       char *printdollar = NULL;
        int printdollar_snum;
 
        *perr = WERR_INVALID_PARAM;
@@ -605,9 +605,11 @@ static uint32 get_correct_cversion(struct pipes_struct *p,
                return 3;
        }
 
-       fstrcpy(printdollar, "print$");
-
-       printdollar_snum = find_service(printdollar);
+       printdollar_snum = find_service(talloc_tos(), "print$", &printdollar);
+       if (!printdollar) {
+               *perr = WERR_NOMEM;
+               return -1;
+       }
        if (printdollar_snum == -1) {
                *perr = WERR_NO_SUCH_SHARE;
                return -1;
@@ -945,7 +947,7 @@ WERROR move_driver_to_download_area(struct pipes_struct *p,
        TALLOC_CTX *ctx = talloc_tos();
        int ver = 0;
        char *oldcwd;
-       fstring printdollar;
+       char *printdollar = NULL;
        int printdollar_snum;
 
        *perr = WERR_OK;
@@ -968,9 +970,11 @@ WERROR move_driver_to_download_area(struct pipes_struct *p,
                return WERR_UNKNOWN_PRINTER_DRIVER;
        }
 
-       fstrcpy(printdollar, "print$");
-
-       printdollar_snum = find_service(printdollar);
+       printdollar_snum = find_service(ctx, "print$", &printdollar);
+       if (!printdollar) {
+               *perr = WERR_NOMEM;
+               return WERR_NOMEM;
+       }
        if (printdollar_snum == -1) {
                *perr = WERR_NO_SUCH_SHARE;
                return WERR_NO_SUCH_SHARE;
@@ -1881,7 +1885,7 @@ bool delete_driver_files(struct auth_serversupplied_info *server_info,
        connection_struct *conn;
        NTSTATUS nt_status;
        char *oldcwd;
-       fstring printdollar;
+       char *printdollar = NULL;
        int printdollar_snum;
        bool ret = false;
 
@@ -1892,9 +1896,10 @@ bool delete_driver_files(struct auth_serversupplied_info *server_info,
        DEBUG(6,("delete_driver_files: deleting driver [%s] - version [%d]\n",
                r->driver_name, r->version));
 
-       fstrcpy(printdollar, "print$");
-
-       printdollar_snum = find_service(printdollar);
+       printdollar_snum = find_service(talloc_tos(), "print$", &printdollar);
+       if (!printdollar) {
+               return false;
+       }
        if (printdollar_snum == -1) {
                return false;
        }
index 35c030a9b3743a775c99b23c1b49a1d5ac4f66ee..3fe22b3f5a837a42470ab68c99b3fa9614bdf094 100644 (file)
@@ -1410,15 +1410,20 @@ WERROR _srvsvc_NetShareGetInfo(struct pipes_struct *p,
                               struct srvsvc_NetShareGetInfo *r)
 {
        WERROR status = WERR_OK;
-       fstring share_name;
+       char *share_name = NULL;
        int snum;
        union srvsvc_NetShareInfo *info = r->out.info;
 
        DEBUG(5,("_srvsvc_NetShareGetInfo: %d\n", __LINE__));
 
-       fstrcpy(share_name, r->in.share_name);
+       if (!r->in.share_name) {
+               return WERR_INVALID_NAME;
+       }
 
-       snum = find_service(share_name);
+       snum = find_service(talloc_tos(), r->in.share_name, &share_name);
+       if (!share_name) {
+               return WERR_NOMEM;
+       }
        if (snum < 0) {
                return WERR_INVALID_NAME;
        }
@@ -1542,26 +1547,28 @@ WERROR _srvsvc_NetShareSetInfo(struct pipes_struct *p,
 
        DEBUG(5,("_srvsvc_NetShareSetInfo: %d\n", __LINE__));
 
-       share_name = talloc_strdup(p->mem_ctx, r->in.share_name);
-       if (!share_name) {
-               return WERR_NOMEM;
+       if (!r->in.share_name) {
+               return WERR_INVALID_NAME;
        }
 
        if (r->out.parm_error) {
                *r->out.parm_error = 0;
        }
 
-       if ( strequal(share_name,"IPC$")
-               || ( lp_enable_asu_support() && strequal(share_name,"ADMIN$") )
-               || strequal(share_name,"global") )
+       if ( strequal(r->in.share_name,"IPC$")
+               || ( lp_enable_asu_support() && strequal(r->in.share_name,"ADMIN$") )
+               || strequal(r->in.share_name,"global") )
        {
                DEBUG(5,("_srvsvc_NetShareSetInfo: share %s cannot be "
                        "modified by a remote user.\n",
-                       share_name ));
+                       r->in.share_name ));
                return WERR_ACCESS_DENIED;
        }
 
-       snum = find_service(share_name);
+       snum = find_service(talloc_tos(), r->in.share_name, &share_name);
+       if (!share_name) {
+               return WERR_NOMEM;
+       }
 
        /* Does this share exist ? */
        if (snum < 0)
@@ -1756,6 +1763,7 @@ WERROR _srvsvc_NetShareAdd(struct pipes_struct *p,
                           struct srvsvc_NetShareAdd *r)
 {
        char *command = NULL;
+       char *share_name_in = NULL;
        char *share_name = NULL;
        char *comment = NULL;
        char *pathname = NULL;
@@ -1793,7 +1801,7 @@ WERROR _srvsvc_NetShareAdd(struct pipes_struct *p,
                /* Not enough info in a level 1 to do anything. */
                return WERR_ACCESS_DENIED;
        case 2:
-               share_name = talloc_strdup(ctx, r->in.info->info2->name);
+               share_name_in = talloc_strdup(ctx, r->in.info->info2->name);
                comment = talloc_strdup(ctx, r->in.info->info2->comment);
                pathname = talloc_strdup(ctx, r->in.info->info2->path);
                max_connections = (r->in.info->info2->max_users == (uint32_t)-1) ?
@@ -1804,7 +1812,7 @@ WERROR _srvsvc_NetShareAdd(struct pipes_struct *p,
                /* No path. Not enough info in a level 501 to do anything. */
                return WERR_ACCESS_DENIED;
        case 502:
-               share_name = talloc_strdup(ctx, r->in.info->info502->name);
+               share_name_in = talloc_strdup(ctx, r->in.info->info502->name);
                comment = talloc_strdup(ctx, r->in.info->info502->comment);
                pathname = talloc_strdup(ctx, r->in.info->info502->path);
                max_connections = (r->in.info->info502->max_users == (uint32_t)-1) ?
@@ -1832,21 +1840,24 @@ WERROR _srvsvc_NetShareAdd(struct pipes_struct *p,
 
        /* check for invalid share names */
 
-       if (!share_name || !validate_net_name(share_name,
+       if (!share_name_in || !validate_net_name(share_name_in,
                                INVALID_SHARENAME_CHARS,
-                               strlen(share_name))) {
+                               strlen(share_name_in))) {
                DEBUG(5,("_srvsvc_NetShareAdd: Bad sharename \"%s\"\n",
-                                       share_name ? share_name : ""));
+                                       share_name_in ? share_name_in : ""));
                return WERR_INVALID_NAME;
        }
 
-       if (strequal(share_name,"IPC$") || strequal(share_name,"global")
+       if (strequal(share_name_in,"IPC$") || strequal(share_name_in,"global")
                        || (lp_enable_asu_support() &&
-                                       strequal(share_name,"ADMIN$"))) {
+                                       strequal(share_name_in,"ADMIN$"))) {
                return WERR_ACCESS_DENIED;
        }
 
-       snum = find_service(share_name);
+       snum = find_service(ctx, share_name_in, &share_name);
+       if (!share_name) {
+               return WERR_NOMEM;
+       }
 
        /* Share already exists. */
        if (snum >= 0) {
@@ -1864,6 +1875,7 @@ WERROR _srvsvc_NetShareAdd(struct pipes_struct *p,
        }
 
        /* Ensure share name, pathname and comment don't contain '"' characters. */
+       string_replace(share_name_in, '"', ' ');
        string_replace(share_name, '"', ' ');
        string_replace(path, '"', ' ');
        if (comment) {
@@ -1874,7 +1886,7 @@ WERROR _srvsvc_NetShareAdd(struct pipes_struct *p,
                        "%s \"%s\" \"%s\" \"%s\" \"%s\" %d",
                        lp_add_share_cmd(),
                        get_dyn_CONFIGFILE(),
-                       share_name,
+                       share_name_in,
                        path,
                        comment ? comment : "",
                        max_connections);
@@ -1911,6 +1923,8 @@ WERROR _srvsvc_NetShareAdd(struct pipes_struct *p,
                return WERR_ACCESS_DENIED;
 
        if (psd) {
+               /* Note we use share_name here, not share_name_in as
+                  we need a canonicalized name for setting security. */
                if (!set_share_security(share_name, psd)) {
                        DEBUG(0,("_srvsvc_NetShareAdd: Failed to add security info to share %s.\n",
                                share_name ));
@@ -1948,22 +1962,29 @@ WERROR _srvsvc_NetShareDel(struct pipes_struct *p,
 
        DEBUG(5,("_srvsvc_NetShareDel: %d\n", __LINE__));
 
-       share_name = talloc_strdup(p->mem_ctx, r->in.share_name);
-       if (!share_name) {
+       if (!r->in.share_name) {
                return WERR_NET_NAME_NOT_FOUND;
        }
-       if ( strequal(share_name,"IPC$")
-               || ( lp_enable_asu_support() && strequal(share_name,"ADMIN$") )
-               || strequal(share_name,"global") )
+
+       if ( strequal(r->in.share_name,"IPC$")
+               || ( lp_enable_asu_support() && strequal(r->in.share_name,"ADMIN$") )
+               || strequal(r->in.share_name,"global") )
        {
                return WERR_ACCESS_DENIED;
        }
 
-       if (!(params = get_share_params(p->mem_ctx, share_name))) {
+       snum = find_service(talloc_tos(), r->in.share_name, &share_name);
+       if (!share_name) {
+               return WERR_NOMEM;
+       }
+
+       if (snum < 0) {
                return WERR_NO_SUCH_SHARE;
        }
 
-       snum = find_service(share_name);
+       if (!(params = get_share_params(p->mem_ctx, share_name))) {
+               return WERR_NO_SUCH_SHARE;
+       }
 
        /* No change to printer shares. */
        if (lp_print_ok(snum))
@@ -2094,7 +2115,7 @@ WERROR _srvsvc_NetGetFileSecurity(struct pipes_struct *p,
        struct smb_filename *smb_fname = NULL;
        struct security_descriptor *psd = NULL;
        size_t sd_size;
-       fstring servicename;
+       char *servicename = NULL;
        SMB_STRUCT_STAT st;
        NTSTATUS nt_status;
        WERROR werr;
@@ -2106,9 +2127,15 @@ WERROR _srvsvc_NetGetFileSecurity(struct pipes_struct *p,
 
        ZERO_STRUCT(st);
 
-       fstrcpy(servicename, r->in.share);
-
-       snum = find_service(servicename);
+       if (!r->in.share) {
+               werr = WERR_NET_NAME_NOT_FOUND;
+               goto error_exit;
+       }
+       snum = find_service(talloc_tos(), r->in.share, &servicename);
+       if (!servicename) {
+               werr = WERR_NOMEM;
+               goto error_exit;
+       }
        if (snum == -1) {
                DEBUG(10, ("Could not find service %s\n", servicename));
                werr = WERR_NET_NAME_NOT_FOUND;
@@ -2224,7 +2251,7 @@ WERROR _srvsvc_NetSetFileSecurity(struct pipes_struct *p,
                                  struct srvsvc_NetSetFileSecurity *r)
 {
        struct smb_filename *smb_fname = NULL;
-       fstring servicename;
+       char *servicename = NULL;
        files_struct *fsp = NULL;
        SMB_STRUCT_STAT st;
        NTSTATUS nt_status;
@@ -2237,9 +2264,17 @@ WERROR _srvsvc_NetSetFileSecurity(struct pipes_struct *p,
 
        ZERO_STRUCT(st);
 
-       fstrcpy(servicename, r->in.share);
+       if (!r->in.share) {
+               werr = WERR_NET_NAME_NOT_FOUND;
+               goto error_exit;
+       }
+
+       snum = find_service(talloc_tos(), r->in.share, &servicename);
+       if (!servicename) {
+               werr = WERR_NOMEM;
+               goto error_exit;
+       }
 
-       snum = find_service(servicename);
        if (snum == -1) {
                DEBUG(10, ("Could not find service %s\n", servicename));
                werr = WERR_NET_NAME_NOT_FOUND;
index e54aa5b5ff4e2446e258f0aa1211f6df65c67ca9..84f2fa3bda162d41bacd113b3d12fccee6f754ad 100644 (file)
@@ -1982,7 +1982,8 @@ static bool api_RNetShareGetInfo(struct smbd_server_connection *sconn,
 {
        char *str1 = get_safe_str_ptr(param,tpscnt,param,2);
        char *str2 = skip_string(param,tpscnt,str1);
-       char *netname = skip_string(param,tpscnt,str2);
+       char *netname_in = skip_string(param,tpscnt,str2);
+       char *netname = NULL;
        char *p = skip_string(param,tpscnt,netname);
        int uLevel = get_safe_SVAL(param,tpscnt,p,0,-1);
        int snum;
@@ -1991,8 +1992,8 @@ static bool api_RNetShareGetInfo(struct smbd_server_connection *sconn,
                return False;
        }
 
-       snum = find_service(netname);
-       if (snum < 0) {
+       snum = find_service(talloc_tos(), netname_in, &netname);
+       if (snum < 0 || !netname) {
                return False;
        }
 
index 320ffb529adb7ab542c6c7b6270ab8cc154c5c5c..45b7bac1645f62f8b4c5761e47086540056b20c1 100644 (file)
@@ -833,11 +833,13 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
        /* Verify the share is a dfs root */
        snum = lp_servicenumber(jucn->service_name);
        if(snum < 0) {
-               fstring service_name;
-               fstrcpy(service_name, jucn->service_name);
-               if ((snum = find_service(service_name)) < 0) {
+               char *service_name = NULL;
+               if ((snum = find_service(ctx, jucn->service_name, &service_name)) < 0) {
                        return NT_STATUS_NOT_FOUND;
                }
+               if (!service_name) {
+                       return NT_STATUS_NO_MEMORY;
+               }
                TALLOC_FREE(jucn->service_name);
                jucn->service_name = talloc_strdup(ctx, service_name);
                if (!jucn->service_name) {
index 8320d1b2bf8ec1de4ea73fee0f008e8aa2234b8a..affa8c5f5e668e97a709cf740d1fd09e4c4f2d11 100644 (file)
@@ -304,39 +304,47 @@ int add_home_service(const char *service, const char *username, const char *home
  * @param service is modified (to canonical form??)
  **/
 
-int find_service(fstring service)
+int find_service(TALLOC_CTX *ctx, const char *service_in, char **p_service_out)
 {
        int iService;
 
-       all_string_sub(service,"\\","/",0);
+       if (!service_in) {
+               return -1;
+       }
+
+       /* First make a copy. */
+       *p_service_out = talloc_strdup(ctx, service_in);
+       if (!*p_service_out) {
+               return -1;
+       }
 
-       iService = lp_servicenumber(service);
+       all_string_sub(*p_service_out,"\\","/",0);
+
+       iService = lp_servicenumber(*p_service_out);
 
        /* now handle the special case of a home directory */
        if (iService < 0) {
-               char *phome_dir = get_user_home_dir(talloc_tos(), service);
+               char *phome_dir = get_user_home_dir(ctx, *p_service_out);
 
                if(!phome_dir) {
-                       char *service_out = NULL;
                        /*
                         * Try mapping the servicename, it may
                         * be a Windows to unix mapped user name.
                         */
-                       if(map_username(talloc_tos(), service, &service_out)) {
-                               if (service_out == NULL) {
+                       if(map_username(ctx, *p_service_out, p_service_out)) {
+                               if (*p_service_out == NULL) {
                                        /* Out of memory. */
                                        return -1;
                                }
-                               fstrcpy(service, service_out);
                                phome_dir = get_user_home_dir(
-                                       talloc_tos(), service);
+                                               ctx, *p_service_out);
                        }
                }
 
-               DEBUG(3,("checking for home directory %s gave %s\n",service,
+               DEBUG(3,("checking for home directory %s gave %s\n",*p_service_out,
                        phome_dir?phome_dir:"(NULL)"));
 
-               iService = add_home_service(service,service /* 'username' */, phome_dir);
+               iService = add_home_service(*p_service_out,*p_service_out /* 'username' */, phome_dir);
        }
 
        /* If we still don't have a service, attempt to add it as a printer. */
@@ -347,17 +355,22 @@ int find_service(fstring service)
                        iPrinterService = load_registry_service(PRINTERS_NAME);
                }
                if (iPrinterService >= 0) {
-                       DEBUG(3,("checking whether %s is a valid printer name...\n", service));
-                       if (pcap_printername_ok(service)) {
-                               DEBUG(3,("%s is a valid printer name\n", service));
-                               DEBUG(3,("adding %s as a printer service\n", service));
-                               lp_add_printer(service, iPrinterService);
-                               iService = lp_servicenumber(service);
+                       DEBUG(3,("checking whether %s is a valid printer name...\n",
+                               *p_service_out));
+                       if (pcap_printername_ok(*p_service_out)) {
+                               DEBUG(3,("%s is a valid printer name\n",
+                                       *p_service_out));
+                               DEBUG(3,("adding %s as a printer service\n",
+                                       *p_service_out));
+                               lp_add_printer(*p_service_out, iPrinterService);
+                               iService = lp_servicenumber(*p_service_out);
                                if (iService < 0) {
-                                       DEBUG(0,("failed to add %s as a printer service!\n", service));
+                                       DEBUG(0,("failed to add %s as a printer service!\n",
+                                               *p_service_out));
                                }
                        } else {
-                               DEBUG(3,("%s is not a valid printer name\n", service));
+                               DEBUG(3,("%s is not a valid printer name\n",
+                                       *p_service_out));
                        }
                }
        }
@@ -367,27 +380,30 @@ int find_service(fstring service)
        }
 
        if (iService < 0) {
-               iService = load_registry_service(service);
+               iService = load_registry_service(*p_service_out);
        }
 
        /* Is it a usershare service ? */
        if (iService < 0 && *lp_usershare_path()) {
                /* Ensure the name is canonicalized. */
-               strlower_m(service);
-               iService = load_usershare_service(service);
+               strlower_m(*p_service_out);
+               iService = load_usershare_service(*p_service_out);
        }
 
        /* just possibly it's a default service? */
        if (iService < 0) {
                char *pdefservice = lp_defaultservice();
-               if (pdefservice && *pdefservice && !strequal(pdefservice,service) && !strstr_m(service,"..")) {
+               if (pdefservice &&
+                               *pdefservice &&
+                               !strequal(pdefservice, *p_service_out)
+                               && !strstr_m(*p_service_out,"..")) {
                        /*
                         * We need to do a local copy here as lp_defaultservice() 
                         * returns one of the rotating lp_string buffers that
                         * could get overwritten by the recursive find_service() call
                         * below. Fix from Josef Hinteregger <joehtg@joehtg.co.at>.
                         */
-                       char *defservice = SMB_STRDUP(pdefservice);
+                       char *defservice = talloc_strdup(ctx, pdefservice);
 
                        if (!defservice) {
                                goto fail;
@@ -397,30 +413,38 @@ int find_service(fstring service)
                        if (strequal(defservice,HOMES_NAME) ||
                                        strequal(defservice, PRINTERS_NAME) ||
                                        strequal(defservice, "IPC$")) {
-                               SAFE_FREE(defservice);
+                               TALLOC_FREE(defservice);
                                goto fail;
                        }
 
-                       iService = find_service(defservice);
+                       iService = find_service(ctx, defservice, p_service_out);
+                       if (!*p_service_out) {
+                               TALLOC_FREE(defservice);
+                               iService = -1;
+                               goto fail;
+                       }
                        if (iService >= 0) {
-                               all_string_sub(service, "_","/",0);
-                               iService = lp_add_service(service, iService);
+                               all_string_sub(*p_service_out, "_","/",0);
+                               iService = lp_add_service(*p_service_out, iService);
                        }
-                       SAFE_FREE(defservice);
+                       TALLOC_FREE(defservice);
                }
        }
 
        if (iService >= 0) {
                if (!VALID_SNUM(iService)) {
-                       DEBUG(0,("Invalid snum %d for %s\n",iService, service));
+                       DEBUG(0,("Invalid snum %d for %s\n",iService,
+                               *p_service_out));
                        iService = -1;
                }
        }
 
   fail:
 
-       if (iService < 0)
-               DEBUG(3,("find_service() failed to find service %s\n", service));
+       if (iService < 0) {
+               DEBUG(3,("find_service() failed to find service %s\n",
+                       *p_service_out));
+       }
 
        return (iService);
 }
@@ -1102,7 +1126,7 @@ connection_struct *make_connection(struct smbd_server_connection *sconn,
 {
        uid_t euid;
        user_struct *vuser = NULL;
-       fstring service;
+       char *service = NULL;
        fstring dev;
        int snum = -1;
        char addr[INET6_ADDRSTRLEN];
@@ -1166,7 +1190,13 @@ connection_struct *make_connection(struct smbd_server_connection *sconn,
                                (void)map_username(talloc_tos(),
                                                current_user_info.smb_name,
                                                &unix_username);
-                               snum = find_service(unix_username);
+                               snum = find_service(talloc_tos(),
+                                               unix_username,
+                                               &unix_username);
+                               if (!unix_username) {
+                                       *status = NT_STATUS_NO_MEMORY;
+                               }
+                               return NULL;
                        }
                        if (snum != -1) {
                                DEBUG(5, ("making a connection to 'homes' "
@@ -1190,11 +1220,19 @@ connection_struct *make_connection(struct smbd_server_connection *sconn,
                                            dev, status);
        }
 
-       fstrcpy(service, service_in);
+       service = talloc_strdup(talloc_tos(), service_in);
+       if (!service) {
+               *status = NT_STATUS_NO_MEMORY;
+               return NULL;
+       }
 
        strlower_m(service);
 
-       snum = find_service(service);
+       snum = find_service(talloc_tos(), service, &service);
+       if (!service) {
+               *status = NT_STATUS_NO_MEMORY;
+               return NULL;
+       }
 
        if (snum < 0) {
                if (strequal(service,"IPC$") ||
index 66b8dc5941c8782c7e78f479b3e09c711c0b2213..454174fc6b074c56f2af692a6b9a3a0c01505adc 100644 (file)
@@ -150,7 +150,7 @@ static NTSTATUS smbd_smb2_tree_connect(struct smbd_smb2_request *req,
                                       uint32_t *out_tree_id)
 {
        const char *share = in_path;
-       fstring service;
+       char *service = NULL;
        int snum = -1;
        struct smbd_smb2_tcon *tcon;
        connection_struct *compat_conn = NULL;
@@ -168,7 +168,10 @@ static NTSTATUS smbd_smb2_tree_connect(struct smbd_smb2_request *req,
        DEBUG(10,("smbd_smb2_tree_connect: path[%s] share[%s]\n",
                  in_path, share));
 
-       fstrcpy(service, share);
+       service = talloc_strdup(talloc_tos(), share);
+       if(!service) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
        strlower_m(service);
 
@@ -188,7 +191,10 @@ static NTSTATUS smbd_smb2_tree_connect(struct smbd_smb2_request *req,
                        lp_servicename(compat_vuser->homes_snum))) {
                snum = compat_vuser->homes_snum;
        } else {
-               snum = find_service(service);
+               snum = find_service(talloc_tos(), service, &service);
+               if (!service) {
+                       return NT_STATUS_NO_MEMORY;
+               }
        }
 
        if (snum < 0) {