fix a bunch of places where we can double-free a cli structure
authorAndrew Tridgell <tridge@samba.org>
Wed, 28 Nov 2001 03:56:30 +0000 (03:56 +0000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 28 Nov 2001 03:56:30 +0000 (03:56 +0000)
(This used to be commit e2ba2383c9f679c076749a8f4fccefc3559e37ec)

source3/auth/auth_server.c
source3/client/client.c
source3/client/smbmount.c
source3/libads/ldap.c
source3/libsmb/cliconnect.c
source3/torture/locktest.c
source3/torture/locktest2.c
source3/utils/net.c
source3/utils/smbcacls.c
source3/utils/smbtree.c

index 628e672608c91e44f69988ae3c724ecdd16dc4e9..4608c639ebc8ef70fccd82029f91e9c992b7895d 100644 (file)
@@ -110,8 +110,6 @@ static void free_server_private_data(void **private_data_pointer)
        struct cli_state **cli = (struct cli_state **)private_data_pointer;
        if (*cli && (*cli)->initialised) {
                cli_shutdown(*cli);
-               
-               SAFE_FREE(*cli);
        }
 }
 
@@ -129,7 +127,6 @@ static void send_server_keepalive(void **private_data_pointer)
                if (!send_keepalive((*cli)->fd)) {
                        DEBUG( 2, ( "password server keepalive failed.\n"));
                        cli_shutdown(*cli);
-                       SAFE_FREE(*cli);
                }
        }
 }
@@ -346,7 +343,6 @@ use this machine as the password server.\n"));
 
        if (locally_made_cli) {
                cli_shutdown(cli);
-               SAFE_FREE(cli);
        }
 
        return(nt_status);
index 2b0867cf7b40e0d006a40a13f1d59065ae251f7e..c3d1fbc7ecca5d4040e0169fb7122ccb607f3aa3 100644 (file)
@@ -2124,7 +2124,6 @@ struct cli_state *do_connect(const char *server, const char *share)
                d_printf("session request to %s failed (%s)\n", 
                         called.name, cli_errstr(c));
                cli_shutdown(c);
-               SAFE_FREE(c);
                if ((p=strchr_m(called.name, '.'))) {
                        *p = 0;
                        goto again;
@@ -2141,7 +2140,6 @@ struct cli_state *do_connect(const char *server, const char *share)
        if (!cli_negprot(c)) {
                d_printf("protocol negotiation failed\n");
                cli_shutdown(c);
-               SAFE_FREE(c);
                return NULL;
        }
 
@@ -2161,7 +2159,6 @@ struct cli_state *do_connect(const char *server, const char *share)
                    !cli_session_setup(c, "", "", 0, "", 0, workgroup)) { 
                        d_printf("session setup failed: %s\n", cli_errstr(c));
                        cli_shutdown(c);
-                       SAFE_FREE(c);
                        return NULL;
                }
                d_printf("Anonymous login successful\n");
@@ -2186,7 +2183,6 @@ struct cli_state *do_connect(const char *server, const char *share)
                            password, strlen(password)+1)) {
                d_printf("tree connect failed: %s\n", cli_errstr(c));
                cli_shutdown(c);
-               SAFE_FREE(c);
                return NULL;
        }
 
index 3aeddfabca159091d796417dcc31809d76f14ce1..02db69dfd5a2ca635de2e048fa621f677ca90ce6 100644 (file)
@@ -149,7 +149,6 @@ static struct cli_state *do_connection(char *the_service)
                DEBUG(0,("%d: Connection to %s failed\n", getpid(), server_n));
                if (c) {
                        cli_shutdown(c);
-                       SAFE_FREE(c);
                }
                return NULL;
        }
@@ -159,7 +158,6 @@ static struct cli_state *do_connection(char *the_service)
                DEBUG(0,("%d: session request to %s failed (%s)\n", 
                         getpid(), called.name, cli_errstr(c)));
                cli_shutdown(c);
-               SAFE_FREE(c);
                if ((p=strchr_m(called.name, '.'))) {
                        *p = 0;
                        goto again;
@@ -176,7 +174,6 @@ static struct cli_state *do_connection(char *the_service)
        if (!cli_negprot(c)) {
                DEBUG(0,("%d: protocol negotiation failed\n", getpid()));
                cli_shutdown(c);
-               SAFE_FREE(c);
                return NULL;
        }
 
@@ -198,7 +195,6 @@ static struct cli_state *do_connection(char *the_service)
                        DEBUG(0,("%d: session setup failed: %s\n",
                                getpid(), cli_errstr(c)));
                        cli_shutdown(c);
-                       SAFE_FREE(c);
                        return NULL;
                }
                DEBUG(0,("Anonymous login successful\n"));
@@ -211,7 +207,6 @@ static struct cli_state *do_connection(char *the_service)
                DEBUG(0,("%d: tree connect failed: %s\n",
                         getpid(), cli_errstr(c)));
                cli_shutdown(c);
-               SAFE_FREE(c);
                return NULL;
        }
 
@@ -360,7 +355,6 @@ static void send_fs_socket(char *the_service, char *mount_point, struct cli_stat
                   If we don't do this we will "leak" sockets and memory on
                   each reconnection we have to make. */
                cli_shutdown(c);
-               SAFE_FREE(c);
 
                if (!closed) {
                        /* redirect stdout & stderr since we can't know that
index 604a11aa5bef593bb4e551c470a9c39701600dce..49e803a49d6e4a6792050f33516a673e3f116fd2 100644 (file)
@@ -270,7 +270,7 @@ static int ads_add_machine_acct(ADS_STRUCT *ads, const char *hostname)
        asprintf(&new_dn, "cn=%s,cn=Computers,%s", hostname, ads->bind_path);
        asprintf(&samAccountName, "%s$", hostname);
        asprintf(&controlstr, "%u", 
-               UF_DONT_EXPIRE_PASSWD | UF_WORKSTATION_TRUST_ACCOUNT |
+               UF_DONT_EXPIRE_PASSWD | UF_WORKSTATION_TRUST_ACCOUNT | 
                UF_TRUSTED_FOR_DELEGATION | UF_USE_DES_KEY_ONLY);
     
        ret = ads_gen_add(ads, new_dn,
@@ -466,4 +466,17 @@ NTSTATUS ads_set_machine_password(ADS_STRUCT *ads,
        return ret;
 }
 
+/* find the update serial number - this is the core of the ldap cache */
+BOOL ads_USN(ADS_STRUCT *ads, unsigned *usn)
+{
+       const char *attrs[] = {"highestCommittedUSN", NULL};
+       int rc;
+       void *res;
+
+       rc = ldap_search_s(ads->ld, ads->bind_path, 
+                          LDAP_SCOPE_BASE, "(objectclass=*)", (char **)attrs, 0, (LDAPMessage *)&res);
+       if (rc || ads_count_replies(ads, res) != 1) return False;
+       return False;
+}
+
 #endif
index 314ac6638ae55038191b01ab208a4d589ca85fe9..ba4bedf8ab11c4d57beab07235c4e75fb49c2255 100644 (file)
@@ -1144,7 +1144,7 @@ BOOL cli_establish_connection(struct cli_state *cli,
                        {
                                DEBUG(1,("failed tcon_X\n"));
                                if (do_shutdown)
-                  cli_shutdown(cli);
+                                       cli_shutdown(cli);
                                return False;
                        }
                }
@@ -1196,9 +1196,9 @@ BOOL attempt_netbios_session_request(struct cli_state *cli, char *srchost, char
 
         DEBUG(0,("attempt_netbios_session_request: %s rejected the session for name *SMBSERVER \
 with error %s.\n", desthost, cli_errstr(cli) ));
-           cli_shutdown(cli);
-               return False;
-       }
+       cli_shutdown(cli);
+       return False;
+    }
 
     cli_shutdown(cli);
 
index 8606c9e38a91636cc127d1542e93f1a60a6c8a83..4e5d630f302ed9b15f70a80ab62a6c59ce2e4d7a 100644 (file)
@@ -249,7 +249,6 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NS
                        }
                        cli_ulogoff(cli[server][conn]);
                        cli_shutdown(cli[server][conn]);
-                       SAFE_FREE(cli[server][conn]);
                }
                cli[server][conn] = connect_one(share[server]);
                if (!cli[server][conn]) {
index 49c8b2a8a9cb09e919d6b145af5bfdda91eef690..175039bd14caea4ac6b9b50c2c744a4b2b2a75a2 100644 (file)
@@ -266,7 +266,6 @@ static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS],
                        }
                        cli_ulogoff(cli[server][conn]);
                        cli_shutdown(cli[server][conn]);
-                       SAFE_FREE(cli[server][conn]);
                }
                cli[server][conn] = connect_one(share[server]);
                if (!cli[server][conn]) {
index 02373c70510b12cb03c3ecbf9b5c64b5e2abf1c6..5a92766fa519f698803be722b58dbb8db71babd0 100644 (file)
@@ -381,7 +381,6 @@ again:
                DEBUG(1,("session request to %s failed (%s)\n", 
                         called.name, cli_errstr(c)));
                cli_shutdown(c);
-               SAFE_FREE(c);
                if ((p=strchr(called.name, '.'))) {
                        *p = 0;
                        goto again;
@@ -398,7 +397,6 @@ again:
        if (!cli_negprot(c)) {
                DEBUG(1,("protocol negotiation failed\n"));
                cli_shutdown(c);
-               SAFE_FREE(c);
                return NULL;
        }
        
@@ -417,7 +415,6 @@ again:
                if (!cli_session_setup(c, "", "", 0, "", 0, opt_workgroup)) { 
                        DEBUG(1,("session setup failed: %s\n", cli_errstr(c)));
                        cli_shutdown(c);
-                       SAFE_FREE(c);
                        return NULL;
                }
                DEBUG(3,("Anonymous login successful\n"));
@@ -428,7 +425,6 @@ again:
                            opt_password, strlen(opt_password)+1)) {
                DEBUG(1,("tree connect failed: %s\n", cli_errstr(c)));
                cli_shutdown(c);
-               SAFE_FREE(c);
                return NULL;
        }
        
index 2605442e8a592aef58f82fa9c50b83398c5f9adc..670e1f6efef6466f3076b63af6868b5ceade2f8e 100644 (file)
@@ -710,14 +710,12 @@ struct cli_state *connect_one(char *share)
        if (!(c=cli_initialise(NULL)) || !cli_connect(c, server, &ip)) {
                DEBUG(0,("Connection to %s failed\n", server));
                cli_shutdown(c);
-               SAFE_FREE(c);
                return NULL;
        }
 
        if (!cli_session_request(c, &calling, &called)) {
                DEBUG(0,("session request to %s failed\n", called.name));
                cli_shutdown(c);
-               SAFE_FREE(c);
                if (strcmp(called.name, "*SMBSERVER")) {
                        make_nmb_name(&called , "*SMBSERVER", 0x20);
                        goto again;
@@ -730,7 +728,6 @@ struct cli_state *connect_one(char *share)
        if (!cli_negprot(c)) {
                DEBUG(0,("protocol negotiation failed\n"));
                cli_shutdown(c);
-               SAFE_FREE(c);
                return NULL;
        }
 
@@ -747,7 +744,6 @@ struct cli_state *connect_one(char *share)
                               lp_workgroup())) {
                DEBUG(0,("session setup failed: %s\n", cli_errstr(c)));
                cli_shutdown(c);
-               SAFE_FREE(c);
                return NULL;
        }
 
@@ -757,7 +753,6 @@ struct cli_state *connect_one(char *share)
                            password, strlen(password)+1)) {
                DEBUG(0,("tree connect failed: %s\n", cli_errstr(c)));
                cli_shutdown(c);
-               SAFE_FREE(c);
                return NULL;
        }
 
index 5b7e8a73c1d05196b0df4bcb62bb429031b7906c..b06920418d6c32ad8dc30edd6fb428be0f44e31e 100644 (file)
@@ -162,7 +162,6 @@ static struct cli_state *get_ipc_connect(char *server,
         if (cli && cli->initialised)
                 cli_shutdown(cli);
 
-        SAFE_FREE(cli);
         return NULL;
 }