s3/service: use lp_const_servicename() where possible
authorDavid Disseldorp <ddiss@samba.org>
Sun, 24 Jun 2018 23:59:33 +0000 (01:59 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 6 Jul 2018 18:37:20 +0000 (20:37 +0200)
The majority of these lp_servicename(talloc_tos(), ...) callers leak
onto the talloc stackframe. Drop the unnecessary heap allocations.

Signed-off-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/service.c

index a928de6c78f02474fd7d8a61d85cdc6763a305c0..2e4a1136254b56941dd1dfd1374560ec94f21181 100644 (file)
@@ -65,8 +65,8 @@ bool set_conn_connectpath(connection_struct *conn, const char *connectpath)
                return false;
        }
 
-       DEBUG(10,("set_conn_connectpath: service %s, connectpath = %s\n",
-               lp_servicename(talloc_tos(), SNUM(conn)), destname ));
+       DBG_DEBUG("service %s, connectpath = %s\n",
+                 lp_const_servicename(SNUM(conn)), destname);
 
        talloc_free(conn->connectpath);
        conn->connectpath = destname;
@@ -260,7 +260,7 @@ static NTSTATUS find_forced_group(bool force_user,
        }
 
        groupname = talloc_string_sub(talloc_tos(), groupname,
-                                     "%S", lp_servicename(talloc_tos(), snum));
+                                     "%S", lp_const_servicename(snum));
        if (groupname == NULL) {
                DEBUG(1, ("talloc_string_sub failed\n"));
                result = NT_STATUS_NO_MEMORY;
@@ -341,20 +341,20 @@ static NTSTATUS create_connection_session_info(struct smbd_server_connection *sc
 
        if (security_session_user_level(session_info, NULL) < SECURITY_USER) {
                if (!lp_guest_ok(snum)) {
-                       DEBUG(2, ("guest user (from session setup) "
+                       DBG_WARNING("guest user (from session setup) "
                                  "not permitted to access this share "
-                                 "(%s)\n", lp_servicename(talloc_tos(), snum)));
+                                 "(%s)\n", lp_const_servicename(snum));
                        return NT_STATUS_ACCESS_DENIED;
                }
        } else {
                if (!user_ok_token(session_info->unix_info->unix_name,
                                   session_info->info->domain_name,
                                   session_info->security_token, snum)) {
-                       DEBUG(2, ("user '%s' (from session setup) not "
+                       DBG_WARNING("user '%s' (from session setup) not "
                                  "permitted to access this share "
                                  "(%s)\n",
                                  session_info->unix_info->unix_name,
-                                 lp_servicename(talloc_tos(), snum)));
+                                 lp_const_servicename(snum));
                        return NT_STATUS_ACCESS_DENIED;
                }
        }
@@ -558,7 +558,7 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
                        if (conn->encrypt_level == SMB_SIGNING_REQUIRED) {
                                DBG_ERR("Service [%s] requires encryption, but "
                                        "it is disabled globally!\n",
-                                       lp_servicename(talloc_tos(), snum));
+                                       lp_const_servicename(snum));
                                status = NT_STATUS_ACCESS_DENIED;
                                goto err_root_exit;
                        }
@@ -582,7 +582,7 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
 
        {
                char *s = talloc_sub_advanced(talloc_tos(),
-                                       lp_servicename(talloc_tos(), SNUM(conn)),
+                                       lp_const_servicename(SNUM(conn)),
                                        conn->session_info->unix_info->unix_name,
                                        conn->connectpath,
                                        conn->session_info->unix_token->gid,
@@ -599,8 +599,8 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
                        status = NT_STATUS_NO_MEMORY;
                        goto err_root_exit;
                }
-               DEBUG(3,("Connect path is '%s' for service [%s]\n",s,
-                        lp_servicename(talloc_tos(), snum)));
+               DBG_NOTICE("Connect path is '%s' for service [%s]\n", s,
+                          lp_const_servicename(snum));
                TALLOC_FREE(s);
        }
 
@@ -627,8 +627,8 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
        /* Initialise VFS function pointers */
 
        if (!smbd_vfs_init(conn)) {
-               DEBUG(0, ("vfs_init failed for service %s\n",
-                         lp_servicename(talloc_tos(), snum)));
+               DBG_ERR("vfs_init failed for service %s\n",
+                       lp_const_servicename(snum));
                status = NT_STATUS_BAD_NETWORK_NAME;
                goto err_root_exit;
        }
@@ -643,12 +643,12 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
         */
 
        if ((lp_max_connections(snum) > 0)
-           && (count_current_connections(lp_servicename(talloc_tos(), SNUM(conn)), True) >=
+           && (count_current_connections(lp_const_servicename(SNUM(conn)), true) >=
                lp_max_connections(snum))) {
 
-               DEBUG(1, ("Max connections (%d) exceeded for %s\n",
+               DBG_WARNING("Max connections (%d) exceeded for %s\n",
                          lp_max_connections(snum),
-                         lp_servicename(talloc_tos(), snum)));
+                         lp_const_servicename(snum));
                status = NT_STATUS_INSUFFICIENT_RESOURCES;
                goto err_root_exit;
        }
@@ -656,10 +656,10 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
        /* Invoke VFS make connection hook - this must be the first
           filesystem operation that we do. */
 
-       if (SMB_VFS_CONNECT(conn, lp_servicename(talloc_tos(), snum),
+       if (SMB_VFS_CONNECT(conn, lp_const_servicename(snum),
                            conn->session_info->unix_info->unix_name) < 0) {
                DBG_WARNING("SMB_VFS_CONNECT for service '%s' at '%s' failed: %s\n",
-                           lp_servicename(talloc_tos(), snum), conn->connectpath,
+                           lp_const_servicename(snum), conn->connectpath,
                            strerror(errno));
                status = NT_STATUS_UNSUCCESSFUL;
                goto err_root_exit;
@@ -698,7 +698,7 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
        /* execute any "root preexec = " line */
        if (*lp_root_preexec(talloc_tos(), snum)) {
                char *cmd = talloc_sub_advanced(talloc_tos(),
-                                       lp_servicename(talloc_tos(), SNUM(conn)),
+                                       lp_const_servicename(SNUM(conn)),
                                        conn->session_info->unix_info->unix_name,
                                        conn->connectpath,
                                        conn->session_info->unix_token->gid,
@@ -736,7 +736,7 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
        /* execute any "preexec = " line */
        if (*lp_preexec(talloc_tos(), snum)) {
                char *cmd = talloc_sub_advanced(talloc_tos(),
-                                       lp_servicename(talloc_tos(), SNUM(conn)),
+                                       lp_const_servicename(SNUM(conn)),
                                        conn->session_info->unix_info->unix_name,
                                        conn->connectpath,
                                        conn->session_info->unix_token->gid,
@@ -776,10 +776,10 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
         */
        if (!lp_widelinks(snum)) {
                if (!canonicalize_connect_path(conn)) {
-                       DEBUG(0, ("canonicalize_connect_path failed "
+                       DBG_ERR("canonicalize_connect_path failed "
                        "for service %s, path %s\n",
-                               lp_servicename(talloc_tos(), snum),
-                               conn->connectpath));
+                               lp_const_servicename(snum),
+                               conn->connectpath);
                        status = NT_STATUS_BAD_NETWORK_NAME;
                        goto err_root_exit;
                }
@@ -815,15 +815,15 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
        if ((ret = SMB_VFS_STAT(conn, smb_fname_cpath)) != 0 ||
            !S_ISDIR(smb_fname_cpath->st.st_ex_mode)) {
                if (ret == 0 && !S_ISDIR(smb_fname_cpath->st.st_ex_mode)) {
-                       DEBUG(0,("'%s' is not a directory, when connecting to "
+                       DBG_ERR("'%s' is not a directory, when connecting to "
                                 "[%s]\n", conn->connectpath,
-                                lp_servicename(talloc_tos(), snum)));
+                                lp_const_servicename(snum));
                } else {
-                       DEBUG(0,("'%s' does not exist or permission denied "
+                       DBG_ERR("'%s' does not exist or permission denied "
                                 "when connecting to [%s] Error was %s\n",
                                 conn->connectpath,
-                                lp_servicename(talloc_tos(), snum),
-                                strerror(errno) ));
+                                lp_const_servicename(snum),
+                                strerror(errno));
                }
                status = NT_STATUS_BAD_NETWORK_NAME;
                goto err_root_exit;
@@ -852,7 +852,7 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
                                                talloc_tos()) );
                dbgtext( "%s", srv_is_signing_active(xconn) ? "signed " : "");
                dbgtext( "connect to service %s ",
-                        lp_servicename(talloc_tos(), snum) );
+                        lp_const_servicename(snum) );
                dbgtext( "initially as user %s ",
                         conn->session_info->unix_info->unix_name );
                dbgtext( "(uid=%d, gid=%d) ", (int)effuid, (int)effgid );
@@ -1046,7 +1046,7 @@ connection_struct *make_connection(struct smb_request *req,
                                            dev, status);
        } else if ((vuser->homes_snum != -1)
                   && strequal(service_in,
-                              lp_servicename(talloc_tos(), vuser->homes_snum))) {
+                              lp_const_servicename(vuser->homes_snum))) {
                DEBUG(5, ("making a connection to 'homes' service [%s] "
                          "created at session setup time\n", service_in));
                return make_connection_smb1(req, now,
@@ -1126,7 +1126,7 @@ void close_cnum(connection_struct *conn, uint64_t vuid)
                                 get_remote_machine_name(),
                                 tsocket_address_string(conn->sconn->remote_address,
                                                        talloc_tos()),
-                                lp_servicename(talloc_tos(), SNUM(conn))));
+                                lp_const_servicename(SNUM(conn))));
 
        /* make sure we leave the directory available for unmount */
        vfs_ChDir(conn, &root_fname);
@@ -1138,7 +1138,7 @@ void close_cnum(connection_struct *conn, uint64_t vuid)
        if (*lp_postexec(talloc_tos(), SNUM(conn)) &&
            change_to_user(conn, vuid))  {
                char *cmd = talloc_sub_advanced(talloc_tos(),
-                                       lp_servicename(talloc_tos(), SNUM(conn)),
+                                       lp_const_servicename(SNUM(conn)),
                                        conn->session_info->unix_info->unix_name,
                                        conn->connectpath,
                                        conn->session_info->unix_token->gid,
@@ -1154,7 +1154,7 @@ void close_cnum(connection_struct *conn, uint64_t vuid)
        /* execute any "root postexec = " line */
        if (*lp_root_postexec(talloc_tos(), SNUM(conn)))  {
                char *cmd = talloc_sub_advanced(talloc_tos(),
-                                       lp_servicename(talloc_tos(), SNUM(conn)),
+                                       lp_const_servicename(SNUM(conn)),
                                        conn->session_info->unix_info->unix_name,
                                        conn->connectpath,
                                        conn->session_info->unix_token->gid,