Update cli_full_connection() to take a 'flags' paramater, and try to get a
authorAndrew Bartlett <abartlet@samba.org>
Tue, 25 Jun 2002 08:57:24 +0000 (08:57 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 25 Jun 2002 08:57:24 +0000 (08:57 +0000)
few more places to use it.

Andrew Bartlett

12 files changed:
source/auth/auth_domain.c
source/client/smbspool.c
source/include/client.h
source/libsmb/cliconnect.c
source/libsmb/trust_passwd.c
source/nsswitch/winbindd_cm.c
source/rpcclient/rpcclient.c
source/rpcclient/samsync.c
source/smbd/change_trust_pw.c
source/utils/net.c
source/utils/smbcacls.c
source/utils/smbtree.c

index ee486d3f307314ff97961ee029fd87ff0079d88b..9997507757106ab1396c6d2606292e51f44ee450 100644 (file)
@@ -102,7 +102,7 @@ static NTSTATUS connect_to_domain_password_server(struct cli_state **cli,
        
        /* Attempt connection */
        result = cli_full_connection(cli, global_myname, server,
-                                    &dest_ip, 0, "IPC$", "IPC", "", "", "");
+                                    &dest_ip, 0, "IPC$", "IPC", "", "", "", 0);
 
        if (!NT_STATUS_IS_OK(result)) {
                release_server_mutex();
index 2a2d5cbaf59d181f4e609bbbb974a4d20d22fddf..b78d9d22a80212cafcc4140044e6ae82e6bcc322 100644 (file)
@@ -3,6 +3,7 @@
    SMB backend for the Common UNIX Printing System ("CUPS")
    Copyright 1999 by Easy Software Products
    Copyright Andrew Tridgell 1994-1998
+   Copyright Andrew Bartlett 2002
    
    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
@@ -271,72 +272,25 @@ smb_connect(char *workgroup,              /* I - Workgroup */
             char *password)            /* I - Password */
 {
   struct cli_state     *c;             /* New connection */
-  struct nmb_name      called,         /* NMB name of server */
-                       calling;        /* NMB name of client */
-  struct in_addr       ip;             /* IP address of server */
   pstring              myname;         /* Client name */
-
+  NTSTATUS nt_status;
 
  /*
   * Get the names and addresses of the client and server...
   */
 
   get_myname(myname);  
-
-  zero_ip(&ip);
-
-  make_nmb_name(&calling, myname, 0x0);
-  make_nmb_name(&called, server, 0x20);
-
- /*
-  * Open a new connection to the SMB server...
-  */
-
-  if ((c = cli_initialise(NULL)) == NULL)
-  {
-    fputs("ERROR: cli_initialize() failed...\n", stderr);
-    return (NULL);
-  }
-
-  if (!cli_connect(c, server, &ip))
-  {
-    fputs("ERROR: cli_connect() failed...\n", stderr);
-    return (NULL);
+       
+  nt_status = cli_full_connection(&c, myname, server, NULL, 0, share, "?????", 
+                                 username, lp_workgroup(), password, 0);
+  
+  if (NT_STATUS_IS_OK(nt_status)) {
+         return c;
+  } else {
+         fprintf(stderr, "ERROR:  Connection failed with error %s\n", nt_errstr(nt_status));
+         return NULL;
   }
 
-  if (!cli_session_request(c, &calling, &called))
-  {
-    fputs("ERROR: cli_session_request() failed...\n", stderr);
-    return (NULL);
-  }
-
-  if (!cli_negprot(c))
-  {
-    fputs("ERROR: SMB protocol negotiation failed\n", stderr);
-    cli_shutdown(c);
-    return (NULL);
-  }
-
- /*
-  * Do password stuff...
-  */
-
-  if (!cli_session_setup(c, username, 
-                        password, strlen(password),
-                        password, strlen(password),
-                        workgroup))
-  {
-    fprintf(stderr, "ERROR: SMB session setup failed: %s\n", cli_errstr(c));
-    return (NULL);
-  }
-
-  if (!cli_send_tconX(c, share, "?????",
-                     password, strlen(password)+1))
-  {
-    fprintf(stderr, "ERROR: SMB tree connect failed: %s\n", cli_errstr(c));
-    cli_shutdown(c);
-    return (NULL);
-  }
 
  /*
   * Return the new connection...
index 69c74200c103a40d3afa8d63d77fdd546e9a790b..711ae1fd196d1d52f2bad78a020dda8946de48ed 100644 (file)
@@ -155,4 +155,8 @@ struct cli_state {
        fstring pipe_name;
 };
 
+#define CLI_FULL_CONNECTION_DONT_SPNEGO 0x0001
+#define CLI_FULL_CONNECTION_USE_KERBEROS 0x0002
+#define CLI_FULL_CONNECTION_ANNONYMOUS_FALLBACK 0x0004
+
 #endif /* _CLIENT_H */
index cc9821dc29a618be9e97201de18898ec1d24e1a6..c621d9a34e2635007b1d188d80d7a83ad54c078e 100644 (file)
@@ -2,6 +2,7 @@
    Unix SMB/CIFS implementation.
    client connect/disconnect routines
    Copyright (C) Andrew Tridgell 1994-1998
+   Copyright (C) Andrew Barteltt 2001-2002
    
    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
@@ -1096,7 +1097,7 @@ static void init_creds(struct ntuser_creds *creds, char* username,
    @param dest_host The netbios name of the remote host
    @param dest_ip (optional) The the destination IP, NULL for name based lookup
    @param port (optional) The destination port (0 for default)
-   @param service The share to make the connection to.  Should be 'unqualified' in any way.
+   @param service (optional) The share to make the connection to.  Should be 'unqualified' in any way.
    @param service_type The 'type' of serivice. 
    @param user Username, unix string
    @param domain User's domain
@@ -1104,11 +1105,12 @@ static void init_creds(struct ntuser_creds *creds, char* username,
 */
 
 NTSTATUS cli_full_connection(struct cli_state **output_cli, 
-                            const char *my_name, const char *dest_host, 
+                            const char *my_name, 
+                            const char *dest_host, 
                             struct in_addr *dest_ip, int port,
                             char *service, char *service_type,
                             char *user, char *domain, 
-                            char *password) 
+                            char *password, int flags
 {
        struct ntuser_creds creds;
        NTSTATUS nt_status;
@@ -1123,17 +1125,15 @@ NTSTATUS cli_full_connection(struct cli_state **output_cli,
                SMB_ASSERT("output_cli for cli_full_connection was NULL.\n");
        }
 
-       *output_cli = NULL;
-
        if (!my_name) 
                my_name = global_myname;
        
-       make_nmb_name(&calling, my_name, 0x0);
-       make_nmb_name(&called , dest_host, 0x20);
-
        if (!(cli = cli_initialise(NULL)))
                return NT_STATUS_NO_MEMORY;
        
+       make_nmb_name(&calling, my_name, 0x0);
+       make_nmb_name(&called , dest_host, 0x20);
+
        if (cli_set_port(cli, port) != port) {
                cli_shutdown(cli);
                return NT_STATUS_UNSUCCESSFUL;
@@ -1172,6 +1172,12 @@ again:
                return NT_STATUS_UNSUCCESSFUL;
        }
 
+       if (flags & CLI_FULL_CONNECTION_DONT_SPNEGO) {
+               cli->use_spnego = False;
+       } else if (flags & CLI_FULL_CONNECTION_USE_KERBEROS) {
+               cli->use_kerberos = True;
+       }
+
        if (!cli_negprot(cli)) {
                DEBUG(1,("failed negprot\n"));
                nt_status = NT_STATUS_UNSUCCESSFUL;
@@ -1182,18 +1188,23 @@ again:
        if (!cli_session_setup(cli, user, password, strlen(password)+1, 
                               password, strlen(password)+1, 
                               domain)) {
-               DEBUG(1,("failed session setup\n"));
-               nt_status = cli_nt_error(cli);
-               cli_shutdown(cli);
-               if (NT_STATUS_IS_OK(nt_status)) 
-                       nt_status = NT_STATUS_UNSUCCESSFUL;
-               return nt_status;
+               if (!(flags & CLI_FULL_CONNECTION_ANNONYMOUS_FALLBACK) 
+                   || cli_session_setup(cli, "", "", 0, 
+                                        "", 0, domain)) {
+               } else {
+                       nt_status = cli_nt_error(cli);
+                       DEBUG(1,("failed session setup with %s\n", nt_errstr(nt_status)));
+                       cli_shutdown(cli);
+                       if (NT_STATUS_IS_OK(nt_status)) 
+                               nt_status = NT_STATUS_UNSUCCESSFUL;
+                       return nt_status;
+               }
        } 
 
        if (service) {
                if (!cli_send_tconX(cli, service, service_type,
                                    (char*)password, strlen(password)+1)) {
-                       DEBUG(1,("failed tcon_X\n"));
+                       DEBUG(1,("failed tcon_X with %s\n", nt_errstr(nt_status)));
                        nt_status = cli_nt_error(cli);
                        cli_shutdown(cli);
                        if (NT_STATUS_IS_OK(nt_status)) {
index fd98e8dca9a2cf4c5042bfad02712b205c99388e..7491f15f5234400914e5ff0c9ba5236f80c93ab6 100644 (file)
@@ -77,7 +77,8 @@ NTSTATUS trust_pw_change_and_store_it(struct cli_state *cli, TALLOC_CTX *mem_ctx
                                             new_trust_passwd_hash);
        
        if (NT_STATUS_IS_OK(nt_status)) {
-               DEBUG(3,("%s : change_trust_account_password: Changed password.\n", timestring(False)));
+               DEBUG(3,("%s : trust_pw_change_and_store_it: Changed password.\n", 
+                        timestring(False)));
                /*
                 * Return the result of trying to write the new password
                 * back into the trust account file.
index bffa169ab1700aaa8d2822118c282686bc9bb770..0f36d3613ce8aa7facb90622b08fa96893b65643 100644 (file)
@@ -351,7 +351,7 @@ static NTSTATUS cm_open_connection(const char *domain,const char *pipe_name,
        result = cli_full_connection(&(new_conn->cli), global_myname, new_conn->controller, 
                                     &dc_ip, 0, "IPC$", 
                                     "IPC", ipc_username, ipc_domain, 
-                                    ipc_password);
+                                    ipc_password, 0);
 
        SAFE_FREE(ipc_username);
        SAFE_FREE(ipc_domain);
index 1e2b42233f424122c8d079afeccc6d888010aa10..42fb71abee17191adf3b0dd13c90810b3a67b05f 100644 (file)
@@ -757,7 +757,7 @@ static void usage(void)
                                        &server_ip, 0,
                                        "IPC$", "IPC",  
                                        username, domain,
-                                       password);
+                                       password, 0);
        
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(1,("Cannot connect to server.  Error was %s\n", nt_errstr(nt_status)));
index be5bc874be9d4ded1f2c95490fe490222823059e..5b64cbc47d0304821ab4975c541bdcc09dd9dee9 100644 (file)
@@ -428,7 +428,7 @@ static struct cli_state *init_connection(struct cli_state **cli,
                                                dest_ip, 0,
                                                "IPC$", "IPC",  
                                                username, domain,
-                                               password))) {
+                                               password, 0))) {
                return *cli;
        } else {
                return NULL;
index 182995d7f4e8c09c80baf76fa7cea19d2ce9018e..0c468699b4cc640db49ff7cf10ea930bb8075475 100644 (file)
@@ -35,7 +35,6 @@ static NTSTATUS modify_trust_password( char *domain, char *remote_machine,
 {
   struct cli_state *cli;
   DOM_SID domain_sid;
-  struct in_addr dest_ip;
   NTSTATUS nt_status;
 
   /*
@@ -47,16 +46,11 @@ static NTSTATUS modify_trust_password( char *domain, char *remote_machine,
     return NT_STATUS_UNSUCCESSFUL;
   }
 
-  if(!resolve_name( remote_machine, &dest_ip, 0x20)) {
-         DEBUG(0,("modify_trust_password: Can't resolve address for %s\n", remote_machine));
-         return NT_STATUS_UNSUCCESSFUL;
-  }
-  
   if (!NT_STATUS_IS_OK(cli_full_connection(&cli, global_myname, remote_machine, 
-                                          &dest_ip, 0,
+                                          NULL, 0,
                                           "IPC$", "IPC",  
                                           "", "",
-                                          ""))) {
+                                          "", 0))) {
          DEBUG(0,("modify_trust_password: Connection to %s failed!\n", remote_machine));
          return NT_STATUS_UNSUCCESSFUL;
   }
index 6e5202a40054fc7b9b526b0e29948b3bf866e6d8..a3610d090745abe903532ba328e58c5d1e7b6511 100644 (file)
@@ -120,7 +120,7 @@ NTSTATUS connect_to_ipc(struct cli_state **c, struct in_addr *server_ip,
                                        server_ip, opt_port,
                                        "IPC$", "IPC",  
                                        opt_user_name, opt_workgroup,
-                                       opt_password);
+                                       opt_password, 0);
        
        if (NT_STATUS_IS_OK(nt_status)) {
                return nt_status;
@@ -150,7 +150,7 @@ NTSTATUS connect_to_ipc_anonymous(struct cli_state **c,
                                        server_ip, opt_port,
                                        "IPC$", "IPC",  
                                        "", "",
-                                       "");
+                                       "", 0);
        
        if (NT_STATUS_IS_OK(nt_status)) {
                return nt_status;
index 7d0dd579fb16326abf721cbaab1f74e61d7f4753..aa00eab42c9f9ff0a079d2aacc0ab0cc373b8e14 100644 (file)
@@ -722,7 +722,7 @@ static struct cli_state *connect_one(char *share)
                                                &ip, 0,
                                                share, "?????",  
                                                username, global_myworkgroup,
-                                               password))) {
+                                               password, 0))) {
                return c;
        } else {
                return NULL;
index b80a27eb37bedb2ad900ef1fe5e30585a76054be..bcb460ee0bf1bfad17cdb192118f634e3425501c 100644 (file)
@@ -87,81 +87,26 @@ static void add_name(const char *machine_name, uint32 server_type,
         DLIST_ADD(*name_list, new_name);
 }
 
-/* Return a cli_state pointing at the IPC$ share for the given workgroup */
+/* Return a cli_state pointing at the IPC$ share for the given server */
 
-static struct cli_state *get_ipc_connect(char *server,
+static struct cli_state *get_ipc_connect(char *server, struct in_addr *server_ip,
                                          struct user_auth_info *user_info)
 {
-        struct nmb_name calling, called;
-        struct in_addr server_ip;
         struct cli_state *cli;
         pstring myname;
-
-        zero_ip(&server_ip);
+       NTSTATUS nt_status;
 
         get_myname(myname);
-
-        make_nmb_name(&called, myname, 0x0);
-        make_nmb_name(&calling, server, 0x20);
-
-        if (is_ipaddress(server))
-                if (!resolve_name(server, &server_ip, 0x20))
-                        return False;
-                
- again:
-       if (!(cli = cli_initialise(NULL))) {
-                DEBUG(4, ("Unable to initialise cli structure\n"));
-                goto error;
-        }
-
-        if (!cli_connect(cli, server, &server_ip)) {
-                DEBUG(4, ("Unable to connect to %s\n", server));
-                goto error;
-        }
-
-        if (!cli_session_request(cli, &calling, &called)) {
-                cli_shutdown(cli);
-                if (!strequal(called.name, "*SMBSERVER")) {
-                        make_nmb_name(&called , "*SMBSERVER", 0x20);
-                        goto again;
-                }
-                DEBUG(4, ("Session request failed to %s\n", called.name));
-                goto error;
-       }
-
-        if (!cli_negprot(cli)) {
-                DEBUG(4, ("Negprot failed\n"));
-                goto error;
-       }
-
-       if (!cli_session_setup(cli, user_info->username, user_info->password, 
-                               strlen(user_info->password),
-                              user_info->password, 
-                               strlen(user_info->password), server) &&
-           /* try an anonymous login if it failed */
-           !cli_session_setup(cli, "", "", 1,"", 0, server)) {
-                DEBUG(4, ("Session setup failed\n"));
-                goto error;
-       }
-
-       DEBUG(4,(" session setup ok\n"));
-
-       if (!cli_send_tconX(cli, "IPC$", "?????",
-                           user_info->password, 
-                            strlen(user_info->password)+1)) {
-                DEBUG(4, ("Tconx failed\n"));
-                goto error;
+       
+       nt_status = cli_full_connection(&cli, myname, server, server_ip, 0, "IPC$", "IPC", 
+                                       user_info->username, lp_workgroup(), user_info->password, 
+                                       CLI_FULL_CONNECTION_ANNONYMOUS_FALLBACK);
+
+       if (NT_STATUS_IS_OK(nt_status)) {
+               return cli;
+       } else {
+               return NULL;
        }
-
-        return cli;
-
-        /* Clean up after error */
-
- error:
-        if (cli && cli->initialised)
-                cli_shutdown(cli);
-
-        return NULL;
 }
 
 /* Return the IP address and workgroup of a master browser on the 
@@ -223,7 +168,7 @@ static BOOL get_workgroups(struct user_auth_info *user_info)
                }
         }
 
-        if (!(cli = get_ipc_connect(inet_ntoa(server_ip), user_info)))
+        if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info)))
                 return False;
 
         if (!cli_NetServerEnum(cli, master_workgroup, 
@@ -248,7 +193,7 @@ static BOOL get_servers(char *workgroup, struct user_auth_info *user_info)
                 return False;
         }
 
-        if (!(cli = get_ipc_connect(inet_ntoa(server_ip), user_info)))
+        if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info)))
                 return False;
 
         if (!cli_NetServerEnum(cli, workgroup, SV_TYPE_ALL, add_name, 
@@ -262,7 +207,7 @@ static BOOL get_shares(char *server_name, struct user_auth_info *user_info)
 {
         struct cli_state *cli;
 
-        if (!(cli = get_ipc_connect(server_name, user_info)))
+        if (!(cli = get_ipc_connect(server_name, NULL, user_info)))
                 return False;
 
         if (!cli_RNetShareEnum(cli, add_name, &shares))