Use sockaddr_storage only where we rely on the size, use sockaddr
[kamenim/samba.git] / source3 / auth / auth_server.c
index 9f90ef8ccd21e5e47414c288420a19db9ad130ef..e74e3f5b3bf89810a0279b8fb337ad06017ca712 100644 (file)
@@ -37,6 +37,7 @@ static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
        const char *p;
        char *pserver = NULL;
        bool connected_ok = False;
+       struct named_mutex *mutex = NULL;
 
        if (!(cli = cli_initialise()))
                return NULL;
@@ -64,7 +65,7 @@ static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
                        continue;
                }
 
-               if (ismyaddr(&dest_ss)) {
+               if (ismyaddr((struct sockaddr *)&dest_ss)) {
                        DEBUG(1,("Password server loop - disabling password server %s\n",desthost));
                        continue;
                }
@@ -74,7 +75,9 @@ static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
                   session setup yet it will send a TCP reset to the first
                   connection (tridge) */
 
-               if (!grab_server_mutex(desthost)) {
+               mutex = grab_named_mutex(talloc_tos(), desthost, 10);
+               if (mutex == NULL) {
+                       cli_shutdown(cli);
                        return NULL;
                }
 
@@ -86,7 +89,7 @@ static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
                }
                DEBUG(10,("server_cryptkey: failed to connect to server %s. Error %s\n",
                        desthost, nt_errstr(status) ));
-               release_server_mutex();
+               TALLOC_FREE(mutex);
        }
 
        if (!connected_ok) {
@@ -97,7 +100,7 @@ static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
 
        if (!attempt_netbios_session_request(&cli, global_myname(),
                                             desthost, &dest_ss)) {
-               release_server_mutex();
+               TALLOC_FREE(mutex);
                DEBUG(1,("password server fails session request\n"));
                cli_shutdown(cli);
                return NULL;
@@ -110,16 +113,16 @@ static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
        DEBUG(3,("got session\n"));
 
        if (!cli_negprot(cli)) {
+               TALLOC_FREE(mutex);
                DEBUG(1,("%s rejected the negprot\n",desthost));
-               release_server_mutex();
                cli_shutdown(cli);
                return NULL;
        }
 
        if (cli->protocol < PROTOCOL_LANMAN2 ||
            !(cli->sec_mode & NEGOTIATE_SECURITY_USER_LEVEL)) {
+               TALLOC_FREE(mutex);
                DEBUG(1,("%s isn't in user level security mode\n",desthost));
-               release_server_mutex();
                cli_shutdown(cli);
                return NULL;
        }
@@ -131,14 +134,14 @@ static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
 
        if (!NT_STATUS_IS_OK(cli_session_setup(cli, "", "", 0, "", 0,
                                               ""))) {
+               TALLOC_FREE(mutex);
                DEBUG(0,("%s rejected the initial session setup (%s)\n",
                         desthost, cli_errstr(cli)));
-               release_server_mutex();
                cli_shutdown(cli);
                return NULL;
        }
 
-       release_server_mutex();
+       TALLOC_FREE(mutex);
 
        DEBUG(3,("password server OK\n"));
 
@@ -267,13 +270,15 @@ static NTSTATUS check_smbserver_security(const struct auth_context *auth_context
                                         const auth_usersupplied_info *user_info, 
                                         auth_serversupplied_info **server_info)
 {
+       struct server_security_state *state = talloc_get_type_abort(
+               my_private_data, struct server_security_state);
        struct cli_state *cli;
        static bool tested_password_server = False;
        static bool bad_password_server = False;
        NTSTATUS nt_status = NT_STATUS_NOT_IMPLEMENTED;
        bool locally_made_cli = False;
 
-       cli = (struct cli_state *)my_private_data;
+       cli = state->cli;
        
        if (cli) {
        } else {
@@ -282,7 +287,7 @@ static NTSTATUS check_smbserver_security(const struct auth_context *auth_context
        }
 
        if (!cli || !cli->initialised) {
-               DEBUG(1,("password server is not connected (cli not initilised)\n"));
+               DEBUG(1,("password server is not connected (cli not initialised)\n"));
                return NT_STATUS_LOGON_FAILURE;
        }