s3:smbd: make make_connection_snum() non static
[samba.git] / source3 / smbd / service.c
index 75c19ce131f35aa83503b78c06b1a33ffbddd66b..508f71b44eed77c6bec3ab1439b900c1f6361a8d 100644 (file)
@@ -301,6 +301,7 @@ int add_home_service(const char *service, const char *username, const char *home
 int find_service(fstring service)
 {
        int iService;
+       struct smbd_server_connection *sconn = smbd_server_conn;
 
        all_string_sub(service,"\\","/",0);
 
@@ -315,7 +316,7 @@ int find_service(fstring service)
                         * Try mapping the servicename, it may
                         * be a Windows to unix mapped user name.
                         */
-                       if(map_username(service))
+                       if(map_username(sconn, service))
                                phome_dir = get_user_home_dir(
                                        talloc_tos(), service);
                }
@@ -556,7 +557,8 @@ static NTSTATUS find_forced_group(bool force_user,
   Create an auth_serversupplied_info structure for a connection_struct
 ****************************************************************************/
 
-static NTSTATUS create_connection_server_info(TALLOC_CTX *mem_ctx, int snum,
+static NTSTATUS create_connection_server_info(struct smbd_server_connection *sconn,
+                                             TALLOC_CTX *mem_ctx, int snum,
                                               struct auth_serversupplied_info *vuid_serverinfo,
                                              DATA_BLOB password,
                                               struct auth_serversupplied_info **presult)
@@ -610,11 +612,11 @@ static NTSTATUS create_connection_server_info(TALLOC_CTX *mem_ctx, int snum,
                 /* add the sharename as a possible user name if we
                    are in share mode security */
 
-                add_session_user(lp_servicename(snum));
+                add_session_user(sconn, lp_servicename(snum));
 
                 /* shall we let them in? */
 
-                if (!authorise_login(snum,user,password,&guest)) {
+                if (!authorise_login(sconn, snum,user,password,&guest)) {
                         DEBUG( 2, ( "Invalid username/password for [%s]\n",
                                     lp_servicename(snum)) );
                        return NT_STATUS_WRONG_PASSWORD;
@@ -634,10 +636,11 @@ static NTSTATUS create_connection_server_info(TALLOC_CTX *mem_ctx, int snum,
   connecting user if appropriate.
 ****************************************************************************/
 
-static connection_struct *make_connection_snum(int snum, user_struct *vuser,
-                                              DATA_BLOB password, 
-                                              const char *pdev,
-                                              NTSTATUS *pstatus)
+connection_struct *make_connection_snum(struct smbd_server_connection *sconn,
+                                       int snum, user_struct *vuser,
+                                       DATA_BLOB password,
+                                       const char *pdev,
+                                       NTSTATUS *pstatus)
 {
        connection_struct *conn;
        SMB_STRUCT_STAT st;
@@ -654,7 +657,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                return NULL;
        }       
 
-       conn = conn_new();
+       conn = conn_new(sconn);
        if (!conn) {
                DEBUG(0,("Couldn't find free connection.\n"));
                *pstatus = NT_STATUS_INSUFFICIENT_RESOURCES;
@@ -663,7 +666,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
 
        conn->params->service = snum;
 
-       status = create_connection_server_info(
+       status = create_connection_server_info(sconn,
                conn, snum, vuser ? vuser->server_info : NULL, password,
                &conn->server_info);
 
@@ -671,7 +674,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                DEBUG(1, ("create_connection_server_info failed: %s\n",
                          nt_errstr(status)));
                *pstatus = status;
-               conn_free(conn);
+               conn_free(sconn, conn);
                return NULL;
        }
 
@@ -679,7 +682,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                conn->force_user = true;
        }
 
-       add_session_user(conn->server_info->unix_name);
+       add_session_user(sconn, conn->server_info->unix_name);
 
        safe_strcpy(conn->client_address,
                        client_addr(get_client_fd(),addr,sizeof(addr)), 
@@ -728,7 +731,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                fuser = talloc_string_sub(conn, lp_force_user(snum), "%S",
                                          lp_servicename(snum));
                if (fuser == NULL) {
-                       conn_free(conn);
+                       conn_free(sconn, conn);
                        *pstatus = NT_STATUS_NO_MEMORY;
                        return NULL;
                }
@@ -737,7 +740,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                        conn, fuser, conn->server_info->guest,
                        &forced_serverinfo);
                if (!NT_STATUS_IS_OK(status)) {
-                       conn_free(conn);
+                       conn_free(sconn, conn);
                        *pstatus = status;
                        return NULL;
                }
@@ -762,7 +765,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                        &conn->server_info->utok.gid);
 
                if (!NT_STATUS_IS_OK(status)) {
-                       conn_free(conn);
+                       conn_free(sconn, conn);
                        *pstatus = status;
                        return NULL;
                }
@@ -788,14 +791,14 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                                        pdb_get_domain(conn->server_info->sam_account),
                                        lp_pathname(snum));
                if (!s) {
-                       conn_free(conn);
+                       conn_free(sconn, conn);
                        *pstatus = NT_STATUS_NO_MEMORY;
                        return NULL;
                }
 
                if (!set_conn_connectpath(conn,s)) {
                        TALLOC_FREE(s);
-                       conn_free(conn);
+                       conn_free(sconn, conn);
                        *pstatus = NT_STATUS_NO_MEMORY;
                        return NULL;
                }
@@ -827,7 +830,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                                         "denied due to security "
                                         "descriptor.\n",
                                          lp_servicename(snum)));
-                               conn_free(conn);
+                               conn_free(sconn, conn);
                                *pstatus = NT_STATUS_ACCESS_DENIED;
                                return NULL;
                        } else {
@@ -840,7 +843,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
        if (!smbd_vfs_init(conn)) {
                DEBUG(0, ("vfs_init failed for service %s\n",
                          lp_servicename(snum)));
-               conn_free(conn);
+               conn_free(sconn, conn);
                *pstatus = NT_STATUS_BAD_NETWORK_NAME;
                return NULL;
        }
@@ -858,7 +861,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                        "for service %s, path %s\n",
                                lp_servicename(snum),
                                conn->connectpath));
-                       conn_free(conn);
+                       conn_free(sconn, conn);
                        *pstatus = NT_STATUS_BAD_NETWORK_NAME;
                        return NULL;
                }
@@ -882,7 +885,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
 
                DEBUG(1, ("Max connections (%d) exceeded for %s\n",
                          lp_max_connections(snum), lp_servicename(snum)));
-               conn_free(conn);
+               conn_free(sconn, conn);
                *pstatus = NT_STATUS_INSUFFICIENT_RESOURCES;
                return NULL;
        }  
@@ -892,7 +895,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
         */
        if (!claim_connection(conn, lp_servicename(snum), 0)) {
                DEBUG(1, ("Could not store connections entry\n"));
-               conn_free(conn);
+               conn_free(sconn, conn);
                *pstatus = NT_STATUS_INTERNAL_DB_ERROR;
                return NULL;
        }  
@@ -916,7 +919,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                        DEBUG(1,("root preexec gave %d - failing "
                                 "connection\n", ret));
                        yield_connection(conn, lp_servicename(snum));
-                       conn_free(conn);
+                       conn_free(sconn, conn);
                        *pstatus = NT_STATUS_ACCESS_DENIED;
                        return NULL;
                }
@@ -927,7 +930,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                /* No point continuing if they fail the basic checks */
                DEBUG(0,("Can't become connected user!\n"));
                yield_connection(conn, lp_servicename(snum));
-               conn_free(conn);
+               conn_free(sconn, conn);
                *pstatus = NT_STATUS_LOGON_FAILURE;
                return NULL;
        }
@@ -1063,7 +1066,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                SMB_VFS_DISCONNECT(conn);
        }
        yield_connection(conn, lp_servicename(snum));
-       conn_free(conn);
+       conn_free(sconn, conn);
        return NULL;
 }
 
@@ -1073,7 +1076,8 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
  * @param service 
 ****************************************************************************/
 
-connection_struct *make_connection(const char *service_in, DATA_BLOB password, 
+connection_struct *make_connection(struct smbd_server_connection *sconn,
+                                  const char *service_in, DATA_BLOB password,
                                   const char *pdev, uint16 vuid,
                                   NTSTATUS *status)
 {
@@ -1094,13 +1098,13 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password,
                smb_panic("make_connection: PANIC ERROR. Called as nonroot\n");
        }
 
-       if (conn_num_open() > 2047) {
+       if (conn_num_open(sconn) > 2047) {
                *status = NT_STATUS_INSUFF_SERVER_RESOURCES;
                return NULL;
        }
 
        if(lp_security() != SEC_SHARE) {
-               vuser = get_valid_user_struct(vuid);
+               vuser = get_valid_user_struct(sconn, vuid);
                if (!vuser) {
                        DEBUG(1,("make_connection: refusing to connect with "
                                 "no session setup\n"));
@@ -1131,7 +1135,8 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password,
                        }
                        DEBUG(5, ("making a connection to [homes] service "
                                  "created at session setup time\n"));
-                       return make_connection_snum(vuser->homes_snum,
+                       return make_connection_snum(sconn,
+                                                   vuser->homes_snum,
                                                    vuser, no_pw, 
                                                    dev, status);
                } else {
@@ -1141,14 +1146,15 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password,
                                fstring unix_username;
                                fstrcpy(unix_username,
                                        current_user_info.smb_name);
-                               map_username(unix_username);
+                               map_username(sconn, unix_username);
                                snum = find_service(unix_username);
                        } 
                        if (snum != -1) {
                                DEBUG(5, ("making a connection to 'homes' "
                                          "service %s based on "
                                          "security=share\n", service_in));
-                               return make_connection_snum(snum, NULL,
+                               return make_connection_snum(sconn,
+                                                           snum, NULL,
                                                            password,
                                                            dev, status);
                        }
@@ -1159,7 +1165,8 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password,
                DATA_BLOB no_pw = data_blob_null;
                DEBUG(5, ("making a connection to 'homes' service [%s] "
                          "created at session setup time\n", service_in));
-               return make_connection_snum(vuser->homes_snum,
+               return make_connection_snum(sconn,
+                                           vuser->homes_snum,
                                            vuser, no_pw, 
                                            dev, status);
        }
@@ -1197,7 +1204,7 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password,
 
        DEBUG(5, ("making a connection to 'normal' service %s\n", service));
 
-       return make_connection_snum(snum, vuser,
+       return make_connection_snum(sconn, snum, vuser,
                                    password,
                                    dev, status);
 }
@@ -1206,7 +1213,8 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password,
  Close a cnum.
 ****************************************************************************/
 
-void close_cnum(connection_struct *conn, uint16 vuid)
+void close_cnum(struct smbd_server_connection *sconn,
+               connection_struct *conn, uint16 vuid)
 {
        file_close_conn(conn);
 
@@ -1260,5 +1268,5 @@ void close_cnum(connection_struct *conn, uint16 vuid)
                TALLOC_FREE(cmd);
        }
 
-       conn_free(conn);
+       conn_free(sconn, conn);
 }