]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
starting "connection reuse" system in smb-agent. added version number
authorLuke Leighton <lkcl@samba.org>
Fri, 3 Dec 1999 22:02:03 +0000 (22:02 +0000)
committerLuke Leighton <lkcl@samba.org>
Fri, 3 Dec 1999 22:02:03 +0000 (22:02 +0000)
which isn't actually used right now :-)
(This used to be commit d54a64ae3ab7cdc1ac67fb49f7255e6a106d624e)

source3/include/client.h
source3/include/smb.h
source3/libsmb/clientgen.c
source3/rpc_client/cli_use.c
source3/rpcclient/rpcclient.c
source3/utils/smb-agent.c

index 821a333e546eaf317b5d5ac17dc12a6f4a8272e5..477ceb116008d121d9fdb0d2b7dc79617b4a0c3d 100644 (file)
@@ -85,6 +85,7 @@ struct user_credentials
        struct pwd_info pwd;
 
        uint32 ntlmssp_flags;
+       BOOL reuse;
 };
 
 struct cli_state
index ebc0e7ad9e94cdbdb5e1fd9de69813c42963a0e7..17da44e75bb10c63a47136c6470b3b2783abe2d4 100644 (file)
@@ -1740,6 +1740,9 @@ struct field_info
        char *str;
 };
 
+#define AGENT_CMD_CON       0
+#define AGENT_CMD_CON_REUSE 1
+
 #endif /* _SMB_H */
 
 /* _SMB_H */
index 176be9948be12faeb79d9a9a54297f8d3701d077..369568030141cafd0cfca64238ad56e724f63a0a 100644 (file)
@@ -40,6 +40,7 @@ void copy_user_creds(struct user_credentials *to,
                to->user_name[0] = 0;
                pwd_set_nullpwd(&to->pwd);
                to->ntlmssp_flags = 0;
+               to->reuse = False;
 
                return;
        }
@@ -47,6 +48,7 @@ void copy_user_creds(struct user_credentials *to,
        safe_strcpy(to->user_name, from->user_name, sizeof(from->user_name)-1);
        memcpy(&to->pwd, &from->pwd, sizeof(from->pwd));
        to->ntlmssp_flags = from->ntlmssp_flags;
+       to->reuse = from->reuse;
 };
        
 int cli_set_port(struct cli_state *cli, int port)
@@ -785,6 +787,12 @@ BOOL cli_session_setup_x(struct cli_state *cli,
        char *p;
        BOOL esec = cli->capabilities & CAP_EXTENDED_SECURITY;
 
+       if (cli->usr.reuse)
+       {
+               DEBUG(3,("cli_session_setup_x: reuse enabled, skipping SMBsesssetupX\n"));
+               return True;
+       }
+
        DEBUG(100,("cli_session_setup.  extended security: %s\n",
                    BOOLSTR(esec)));
 
@@ -1063,6 +1071,12 @@ BOOL cli_session_setup(struct cli_state *cli,
 
 BOOL cli_ulogoff(struct cli_state *cli)
 {
+       if (cli->usr.reuse)
+       {
+               DEBUG(3,("cli_ulogoff: reuse enabled, skipping SMBulogoff\n"));
+               return True;
+       }
+
         bzero(cli->outbuf,smb_size);
         set_message(cli->outbuf,2,0,True);
         CVAL(cli->outbuf,smb_com) = SMBulogoffX;
@@ -2981,6 +2995,12 @@ static int cli_init_redirect(struct cli_state *cli,
        ZERO_STRUCT(data);
 
        p = &data[4];
+       SSVAL(p, 0, 0);
+       p += 2;
+
+       SSVAL(p, 0, usr->reuse ? AGENT_CMD_CON_REUSE : AGENT_CMD_CON);
+       p += 2;
+
        safe_strcpy(p, srv_name, 16);
        p = skip_string(p, 1);
        safe_strcpy(p, usr != NULL ? usr->user_name : "", 16);
index 31e3b69b2efb624d3ebfda0584df0d00f931e7de..131edfeb5bc04e7db3494ff60ad2c81a6c3cc8f2 100644 (file)
@@ -156,7 +156,8 @@ static struct cli_use *cli_find(const char* srv_name,
                {
                        continue;
                }
-               if (!pwd_compare(&usr_creds->pwd, &c->cli->usr.pwd))
+               if (!usr_creds->reuse &&
+                   !pwd_compare(&usr_creds->pwd, &c->cli->usr.pwd))
                {
                        continue;
                }
@@ -221,6 +222,12 @@ struct cli_state *cli_net_use_add(const char* srv_name,
                return cli->cli;
        }
 
+       /* reuse an existing connection requested, and one was not found */
+       if (usr_creds != NULL && usr_creds->reuse)
+       {
+               return False;
+       }
+
        /*
         * allocate
         */
index 19698a0f8338aeff913b5f12be28d948bd0eafe3..30fbd4ee9d27f97428aebd7298afb678f8d07e2d 100644 (file)
@@ -1362,6 +1362,7 @@ static void cmd_net(struct client_info *info, int argc, char *argv[])
 
        pstrcpy(dest_host, cli_info.dest_host);
        pstrcpy(u.user_name,optarg);
+       u.reuse = False;
 
        if (argc <= 1)
        {
@@ -1567,6 +1568,8 @@ static void cmd_set(struct client_info *info, int argc, char *argv[])
        *term_code = 0;
 #endif /* KANJI */
 
+       usr.reuse = False;
+
        if (argc > 1 && *argv[1] != '-')
        {
                if (argc > 1 && (*argv[1] != '-'))
@@ -1579,10 +1582,16 @@ static void cmd_set(struct client_info *info, int argc, char *argv[])
                }
        }
 
-       while ((opt = getopt(argc, argv, "s:B:O:M:S:i:N:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF)
+       while ((opt = getopt(argc, argv, "Rs:B:O:M:S:i:N:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF)
        {
                switch (opt)
                {
+                       case 'R':
+                       {
+                               usr.reuse = True;
+                               break;
+                       }
+
                        case 'm':
                        {
                                /* FIXME ... max_protocol seems to be funny here */
index 8c039dfc86d1d346becb24810a98acdb8d9e1d9e..bcc5eebd7571de512a14c3b676fce26d04a934f1 100644 (file)
@@ -99,6 +99,127 @@ static void agent_request(char *buf)
 
 }
 
+#define AGENT_CMD_CON       0
+#define AGENT_CMD_CON_REUSE 1
+
+static struct cli_state *init_client_connection(int c)
+{
+       pstring buf;
+       uchar ntpw[16];
+       uchar lmpw[16];
+       fstring srv_name;
+       struct user_credentials usr;
+       char *p = buf;
+       int rl;
+       uint32 len;
+       uint16 version;
+       uint16 command;
+       BOOL new_con = False;
+
+       ZERO_STRUCT(usr);
+
+       DEBUG(10,("first request\n"));
+
+       rl = read(c, &buf, sizeof(len));
+
+       if (rl != sizeof(len))
+       {
+               DEBUG(0,("Unable to read length\n"));
+               dump_data(0, buf, sizeof(len));
+               return NULL;
+       }
+
+       len = IVAL(buf, 0);
+
+       if (len > sizeof(buf))
+       {
+               DEBUG(0,("length %d too long\n", len));
+               return NULL;
+       }
+
+       rl = read(c, buf, len);
+
+       if (rl < 0)
+       {
+               DEBUG(0,("Unable to read from connection\n"));
+               exit(1);
+       }
+       
+#ifdef DEBUG_PASSWORD
+       dump_data(100, buf, rl);
+#endif
+       version = SVAL(p, 0);
+       p += 2;
+       command = SVAL(p, 0);
+       p += 2;
+
+       fstrcpy(srv_name, p);
+       p = skip_string(p, 1);
+       fstrcpy(usr.user_name, p);
+       p = skip_string(p, 1);
+       fstrcpy(usr.domain, p);
+       p = skip_string(p, 1);
+
+       if (PTR_DIFF(p, buf) < rl)
+       {
+               memcpy(ntpw, p, 16);
+               p += 16;
+               memcpy(lmpw, p, 16);
+               p += 16;
+               pwd_set_lm_nt_16(&usr.pwd, lmpw, ntpw);
+       }
+       else
+       {
+               pwd_set_nullpwd(&usr.pwd);
+       }
+
+       if (PTR_DIFF(p, buf) != rl)
+       {
+               DEBUG(0,("Buffer size %d %d!\n",
+                       PTR_DIFF(p, buf), rl));
+               exit(1);
+       }
+
+       switch (command)
+       {
+               case AGENT_CMD_CON:
+               {
+                       new_con = True;
+                       break;
+               }
+               case AGENT_CMD_CON_REUSE:
+               {
+                       new_con = True;
+                       usr.reuse = True;
+                       break;
+               }
+               default:
+               {
+                       DEBUG(0,("unknown command %d\n", command));
+                       return NULL;
+               }
+       }
+
+       if (new_con)
+       {
+               struct cli_state *s;
+               s = cli_net_use_add(srv_name, &usr, False);
+
+               if (s == NULL)
+               {
+                       DEBUG(0,("Unable to connect to %s\n", srv_name));
+                       return NULL;
+               }
+               if (write(c, s, sizeof(*s)) < 0)
+               {
+                       DEBUG(0,("Could not write connection down pipe.\n"));
+                       cli_net_use_del(srv_name, &usr, False, NULL);
+                       return NULL;
+               }
+               return s;
+       }
+       return NULL;
+}
 
 static void agent_child(int c)
 {
@@ -132,82 +253,9 @@ static void agent_child(int c)
                {
                        if (s == NULL)
                        {
-                               pstring buf;
-                               uchar ntpw[16];
-                               uchar lmpw[16];
-                               fstring srv_name;
-                               struct user_credentials usr;
-                               char *p = buf;
-                               int rl;
-                               uint32 len;
-
-                               DEBUG(10,("first request\n"));
-
-                               rl = read(c, &buf, sizeof(len));
-
-                               if (rl != sizeof(len))
-                               {
-                                       DEBUG(0,("Unable to read length\n"));
-                                       dump_data(0, buf, sizeof(len));
-                                       exit(1);
-                               }
-
-                               len = IVAL(buf, 0);
-
-                               if (len > sizeof(buf))
-                               {
-                                       DEBUG(0,("length %d too long\n", len));
-                                       exit(1);
-                               }
-
-                               rl = read(c, buf, len);
-
-                               if (rl < 0)
-                               {
-                                       DEBUG(0,("Unable to read from connection\n"));
-                                       exit(1);
-                               }
-                               
-#ifdef DEBUG_PASSWORD
-                               dump_data(100, buf, rl);
-#endif
-                               fstrcpy(srv_name, p);
-                               p = skip_string(p, 1);
-                               fstrcpy(usr.user_name, p);
-                               p = skip_string(p, 1);
-                               fstrcpy(usr.domain, p);
-                               p = skip_string(p, 1);
-
-                               if (PTR_DIFF(p, buf) < rl)
-                               {
-                                       memcpy(ntpw, p, 16);
-                                       p += 16;
-                                       memcpy(lmpw, p, 16);
-                                       p += 16;
-                                       pwd_set_lm_nt_16(&usr.pwd, lmpw, ntpw);
-                               }
-                               else
-                               {
-                                       pwd_set_nullpwd(&usr.pwd);
-                               }
-
-                               if (PTR_DIFF(p, buf) != rl)
-                               {
-                                       DEBUG(0,("Buffer size %d %d!\n",
-                                               PTR_DIFF(p, buf), rl));
-                                       exit(1);
-                               }
-
-                               s = cli_net_use_add(srv_name, &usr, False);
-
+                               s = init_client_connection(c);
                                if (s == NULL)
                                {
-                                       DEBUG(0,("Unable to connect to %s\n", srv_name));
-                                       exit(1);
-                               }
-                               if (write(c, s, sizeof(*s)) < 0)
-                               {
-                                       DEBUG(0,("Could not write ack\n"));
                                        exit(1);
                                }
                        }