r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[vlendec/samba-autobuild/.git] / source3 / utils / net_rpc.c
index c1d812a8f0bdab6e8d5f9a3b603b0fa14232765d..273a4c7dbd77e1f950456f544073f53791280e26 100644 (file)
@@ -9,7 +9,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -18,8 +18,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
  
 #include "includes.h"
 #include "utils/net.h"
@@ -2030,7 +2029,7 @@ static NTSTATUS get_sid_from_name(struct cli_state *cli,
        }
 
        result = rpccli_lsa_lookup_names(pipe_hnd, mem_ctx, &lsa_pol, 1,
-                                     &name, NULL, &sids, &types);
+                                     &name, NULL, 1, &sids, &types);
 
        if (NT_STATUS_IS_OK(result)) {
                sid_copy(sid, &sids[0]);
@@ -3118,7 +3117,7 @@ static void display_share_info_1(struct srvsvc_NetShareInfo1 *info1)
 {
        if (opt_long_list_entries) {
                d_printf("%-12s %-8.8s %-50s\n",
-                        info1->name, share_type[info1->type],
+                        info1->name, share_type[info1->type & ~(STYPE_TEMPORARY|STYPE_HIDDEN)],
                         info1->comment ? info1->comment : "");
        } else {
                d_printf("%s\n", info1->name);
@@ -3507,15 +3506,23 @@ static void copy_fn(const char *mnt, file_info *f, const char *mask, void *state
  **/
 BOOL sync_files(struct copy_clistate *cp_clistate, pstring mask)
 {
+       struct cli_state *targetcli;
+       pstring targetpath;
 
        DEBUG(3,("calling cli_list with mask: %s\n", mask));
 
-       if (cli_list(cp_clistate->cli_share_src, mask, cp_clistate->attribute, copy_fn, cp_clistate) == -1) {
-               d_fprintf(stderr, "listing %s failed with error: %s\n", 
+       if ( !cli_resolve_path( "", cp_clistate->cli_share_src, mask, &targetcli, targetpath ) ) {
+               d_fprintf(stderr, "cli_resolve_path %s failed with error: %s\n", 
                        mask, cli_errstr(cp_clistate->cli_share_src));
                return False;
        }
 
+       if (cli_list(targetcli, targetpath, cp_clistate->attribute, copy_fn, cp_clistate) == -1) {
+               d_fprintf(stderr, "listing %s failed with error: %s\n", 
+                       mask, cli_errstr(targetcli));
+               return False;
+       }
+
        return True;
 }
 
@@ -4066,7 +4073,11 @@ static void init_user_token(NT_USER_TOKEN *token, DOM_SID *user_sid)
 {
        token->num_sids = 4;
 
-       token->user_sids = SMB_MALLOC_ARRAY(DOM_SID, 4);
+       if (!(token->user_sids = SMB_MALLOC_ARRAY(DOM_SID, 4))) {
+               d_fprintf(stderr, "malloc failed\n");
+               token->num_sids = 0;
+               return;
+       }
 
        token->user_sids[0] = *user_sid;
        sid_copy(&token->user_sids[1], &global_sid_World);
@@ -5963,6 +5974,7 @@ static int rpc_trustdom_list(int argc, const char **argv)
        if (!pipe_hnd) {
                DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
                        nt_errstr(nt_status) ));
+               cli_shutdown(cli);
                talloc_destroy(mem_ctx);
                return -1;
        };
@@ -5972,6 +5984,7 @@ static int rpc_trustdom_list(int argc, const char **argv)
        if (NT_STATUS_IS_ERR(nt_status)) {
                DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
                        nt_errstr(nt_status)));
+               cli_shutdown(cli);
                talloc_destroy(mem_ctx);
                return -1;
        };
@@ -5984,6 +5997,7 @@ static int rpc_trustdom_list(int argc, const char **argv)
        if (NT_STATUS_IS_ERR(nt_status)) {
                DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
                        nt_errstr(nt_status)));
+               cli_shutdown(cli);
                talloc_destroy(mem_ctx);
                return -1;
        }
@@ -6003,6 +6017,7 @@ static int rpc_trustdom_list(int argc, const char **argv)
                if (NT_STATUS_IS_ERR(nt_status)) {
                        DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
                                nt_errstr(nt_status)));
+                       cli_shutdown(cli);
                        talloc_destroy(mem_ctx);
                        return -1;
                };
@@ -6024,6 +6039,7 @@ static int rpc_trustdom_list(int argc, const char **argv)
        if (NT_STATUS_IS_ERR(nt_status)) {
                DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
                        nt_errstr(nt_status)));
+               cli_shutdown(cli);
                talloc_destroy(mem_ctx);
                return -1;
        };
@@ -6042,6 +6058,7 @@ static int rpc_trustdom_list(int argc, const char **argv)
        pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SAMR, &nt_status);
        if (!pipe_hnd) {
                DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status)));
+               cli_shutdown(cli);
                talloc_destroy(mem_ctx);
                return -1;
        };
@@ -6052,6 +6069,7 @@ static int rpc_trustdom_list(int argc, const char **argv)
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
                        nt_errstr(nt_status)));
+               cli_shutdown(cli);
                talloc_destroy(mem_ctx);
                return -1;
        };
@@ -6064,6 +6082,7 @@ static int rpc_trustdom_list(int argc, const char **argv)
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(0, ("Couldn't open domain object. Error was %s\n",
                        nt_errstr(nt_status)));
+               cli_shutdown(cli);
                talloc_destroy(mem_ctx);
                return -1;
        };
@@ -6082,6 +6101,7 @@ static int rpc_trustdom_list(int argc, const char **argv)
                if (NT_STATUS_IS_ERR(nt_status)) {
                        DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
                                nt_errstr(nt_status)));
+                       cli_shutdown(cli);
                        talloc_destroy(mem_ctx);
                        return -1;
                };
@@ -6189,6 +6209,7 @@ BOOL net_rpc_check(unsigned flags)
        BOOL ret = False;
        struct in_addr server_ip;
        char *server_name = NULL;
+       NTSTATUS status;
 
        /* flags (i.e. server type) may depend on command */
        if (!net_find_server(NULL, flags, &server_ip, &server_name))
@@ -6198,7 +6219,8 @@ BOOL net_rpc_check(unsigned flags)
                return False;
        }
 
-       if (!cli_connect(cli, server_name, &server_ip))
+       status = cli_connect(cli, server_name, &server_ip);
+       if (!NT_STATUS_IS_OK(status))
                goto done;
        if (!attempt_netbios_session_request(&cli, global_myname(), 
                                             server_name, &server_ip))