basic client-side ntcreateX function (hard-wired values except filename)
authorLuke Leighton <lkcl@samba.org>
Fri, 9 Oct 1998 19:34:57 +0000 (19:34 +0000)
committerLuke Leighton <lkcl@samba.org>
Fri, 9 Oct 1998 19:34:57 +0000 (19:34 +0000)
source/include/proto.h
source/libsmb/clientgen.c
source/rpc_client/cli_pipe.c
source/rpcclient/rpcclient.c
source/smbd/nttrans.c

index b0c50cbca7492cd5c7c4eab3a0aec50de10e2d6a..dec428a1421b0165e98da1f293e030b815958bfa 100644 (file)
@@ -385,6 +385,7 @@ BOOL cli_rename(struct cli_state *cli, char *fname_src, char *fname_dst);
 BOOL cli_unlink(struct cli_state *cli, char *fname);
 BOOL cli_mkdir(struct cli_state *cli, char *dname);
 BOOL cli_rmdir(struct cli_state *cli, char *dname);
+int cli_nt_create(struct cli_state *cli, char *fname);
 int cli_open(struct cli_state *cli, char *fname, int flags, int share_mode);
 BOOL cli_close(struct cli_state *cli, int fnum);
 BOOL cli_lock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int timeout);
@@ -498,8 +499,8 @@ void E_old_pw_hash( unsigned char *p14, unsigned char *in, unsigned char *out);
 void cred_hash1(unsigned char *out,unsigned char *in,unsigned char *key);
 void cred_hash2(unsigned char *out,unsigned char *in,unsigned char *key);
 void cred_hash3(unsigned char *out,unsigned char *in,unsigned char *key, int forw);
-void NTLMSSPhash( unsigned char hash[256], unsigned char const key[5]);
-void NTLMSSPcalc( unsigned char hash[256], unsigned char *data, int len);
+void NTLMSSPhash( unsigned char hash[258], unsigned char key[5]);
+void NTLMSSPcalc( unsigned char hash[258], unsigned char *data, int len);
 void SamOEMhash( unsigned char *data, unsigned char *key, int val);
 
 /*The following definitions come from  libsmb/smbencrypt.c  */
index 5ae84f763b93e99aaef85850dfff414fdbd2de74..8eb832128cd5b85b19870b771774f24ad7b35fd8 100644 (file)
@@ -973,6 +973,50 @@ BOOL cli_rmdir(struct cli_state *cli, char *dname)
 
 
 
+/****************************************************************************
+open a file
+****************************************************************************/
+int cli_nt_create(struct cli_state *cli, char *fname)
+{
+       char *p;
+
+       bzero(cli->outbuf,smb_size);
+       bzero(cli->inbuf,smb_size);
+
+       set_message(cli->outbuf,24,1 + strlen(fname),True);
+
+       CVAL(cli->outbuf,smb_com) = SMBntcreateX;
+       SSVAL(cli->outbuf,smb_tid,cli->cnum);
+       cli_setup_packet(cli);
+
+       SSVAL(cli->outbuf,smb_vwv0,0xFF);
+       SIVAL(cli->outbuf,smb_ntcreate_Flags, 0x06);
+       SIVAL(cli->outbuf,smb_ntcreate_RootDirectoryFid, 0x0);
+       SIVAL(cli->outbuf,smb_ntcreate_DesiredAccess, 0x2019f);
+       SIVAL(cli->outbuf,smb_ntcreate_FileAttributes, 0x0);
+       SIVAL(cli->outbuf,smb_ntcreate_ShareAccess, 0x03);
+       SIVAL(cli->outbuf,smb_ntcreate_CreateDisposition, 0x01);
+       SIVAL(cli->outbuf,smb_ntcreate_CreateOptions, 0x0);
+       SIVAL(cli->outbuf,smb_ntcreate_ImpersonationLevel, 0x02);
+       SSVAL(cli->outbuf,smb_ntcreate_NameLength, strlen(fname));
+
+       p = smb_buf(cli->outbuf);
+       pstrcpy(p,fname);
+       p = skip_string(p,1);
+
+       send_smb(cli->fd,cli->outbuf);
+       if (!client_receive_smb(cli->fd,cli->inbuf,cli->timeout)) {
+               return -1;
+       }
+
+       if (CVAL(cli->inbuf,smb_rcls) != 0) {
+               return -1;
+       }
+
+       return SVAL(cli->inbuf,smb_vwv2 + 1);
+}
+
+
 /****************************************************************************
 open a file
 ****************************************************************************/
index 761f23f8851332b3bfb0390397937aa786056260..0b9a4e95e5c2bc32b103a8d378803a162a6a95d2 100644 (file)
@@ -863,22 +863,37 @@ BOOL cli_nt_session_open(struct cli_state *cli, char *pipe_name, BOOL encrypted)
        int fnum;
 
        /******************* open the pipe *****************/
-       if ((fnum = cli_open(cli, pipe_name, O_CREAT|O_RDWR, DENY_NONE)) == -1)
+       if (IS_BITS_SET_ALL(cli->capabilities, CAP_NT_SMBS))
        {
-               DEBUG(0,("cli_nt_session_open: cli_open failed on pipe %s to machine %s.  Error was %s\n",
-                        pipe_name, cli->desthost, cli_errstr(cli)));
-               return False;
+               if ((fnum = cli_nt_create(cli, &(pipe_name[5]))) == -1)
+               {
+                       DEBUG(0,("cli_nt_session_open: cli_nt_create failed on pipe %s to machine %s.  Error was %s\n",
+                                &(pipe_name[5]), cli->desthost, cli_errstr(cli)));
+                       return False;
+               }
+
+               cli->nt_pipe_fnum = (uint16)fnum;
        }
+       else
+       {
+               if ((fnum = cli_open(cli, pipe_name, O_CREAT|O_RDWR, DENY_NONE)) == -1)
+               {
+                       DEBUG(0,("cli_nt_session_open: cli_open failed on pipe %s to machine %s.  Error was %s\n",
+                                pipe_name, cli->desthost, cli_errstr(cli)));
+                       return False;
+               }
 
-       cli->nt_pipe_fnum = (uint16)fnum;
+               cli->nt_pipe_fnum = (uint16)fnum;
+
+               /**************** Set Named Pipe State ***************/
+               if (!rpc_pipe_set_hnd_state(cli, pipe_name, 0x4300))
+               {
+                       DEBUG(0,("cli_nt_session_open: pipe hnd state failed.  Error was %s\n",
+                                 cli_errstr(cli)));
+                       cli_close(cli, cli->nt_pipe_fnum);
+                       return False;
+               }
 
-       /**************** Set Named Pipe State ***************/
-       if (!rpc_pipe_set_hnd_state(cli, pipe_name, 0x4300))
-       {
-               DEBUG(0,("cli_nt_session_open: pipe hnd state failed.  Error was %s\n",
-                         cli_errstr(cli)));
-               cli_close(cli, cli->nt_pipe_fnum);
-               return False;
        }
 
        /******************* bind request on pipe *****************/
index 2183f504c243d9aae7673e35b4e8a05ff59d0011..55bc0e15cc15e48fccbb32483a79388020dc8c0d 100644 (file)
@@ -60,6 +60,7 @@ void rpcclient_init(void)
 {
        bzero(smb_cli, sizeof(smb_cli));
        cli_initialise(smb_cli);
+       smb_cli->capabilities |= CAP_NT_SMBS;
 }
 
 /****************************************************************************
index b439ba9560260dd0748dc1ac7bddfe807ff5807f..758c46a6cd0234dd1027562f6c51166df25284cb 100644 (file)
@@ -412,7 +412,7 @@ int reply_ntcreate_and_X(connection_struct *conn,
        uint32 create_options = IVAL(inbuf,smb_ntcreate_CreateOptions);
        uint32 fname_len = MIN(((uint32)SVAL(inbuf,smb_ntcreate_NameLength)),
                               ((uint32)sizeof(fname)-1));
-    uint16 root_dir_fid = (uint16)IVAL(inbuf,smb_ntcreate_RootDirectoryFid);
+       uint16 root_dir_fid = (uint16)IVAL(inbuf,smb_ntcreate_RootDirectoryFid);
        int smb_ofun;
        int smb_open_mode;
        int smb_attr = (file_attributes & SAMBA_ATTRIBUTES_MASK);