/**************************************************************************** Old style search next. ****************************************************************************/ static NTSTATUS smb_raw_search_close_old(struct smbcli_tree *tree, union smb_search_close *io) { struct smbcli_request *req; uint8_t var_block[21]; req = smbcli_request_setup(tree, SMBfclose, 2, 0); if (!req) { return NT_STATUS_NO_MEMORY; } SSVAL(req->out.vwv, VWV(0), io->fclose.in.max_count); SSVAL(req->out.vwv, VWV(1), io->fclose.in.search_attrib); smbcli_req_append_ascii4(req, "", STR_TERMINATE); SCVAL(var_block, 0, io->fclose.in.id.reserved); memcpy(&var_block[1], io->fclose.in.id.name, 11); SCVAL(var_block, 12, io->fclose.in.id.handle); SIVAL(var_block, 13, io->fclose.in.id.server_cookie); SIVAL(var_block, 17, io->fclose.in.id.client_cookie); smbcli_req_append_var_block(req, var_block, 21); if (!smbcli_request_send(req) || !smbcli_request_receive(req)) { return smbcli_request_destroy(req); } return smbcli_request_destroy(req); }
/* send a find request */ struct smb2_request *smb2_find_send(struct smb2_tree *tree, struct smb2_find *io) { struct smb2_request *req; NTSTATUS status; req = smb2_request_init_tree(tree, SMB2_OP_QUERY_DIRECTORY, 0x20, true, 0); if (req == NULL) return NULL; SCVAL(req->out.body, 0x02, io->in.level); SCVAL(req->out.body, 0x03, io->in.continue_flags); SIVAL(req->out.body, 0x04, io->in.file_index); smb2_push_handle(req->out.body+0x08, &io->in.file.handle); status = smb2_push_o16s16_string(&req->out, 0x18, io->in.pattern); if (!NT_STATUS_IS_OK(status)) { talloc_free(req); return NULL; } SIVAL(req->out.body, 0x1C, io->in.max_response_size); smb2_transport_send(req); return req; }
/* send an oplock break request to a client */ NTSTATUS smbsrv_send_oplock_break(void *p, struct ntvfs_handle *ntvfs, uint8_t level) { struct smbsrv_tcon *tcon = talloc_get_type(p, struct smbsrv_tcon); struct smbsrv_request *req; req = smbsrv_init_request(tcon->smb_conn); NT_STATUS_HAVE_NO_MEMORY(req); smbsrv_setup_reply(req, 8, 0); SCVAL(req->out.hdr,HDR_COM,SMBlockingX); SSVAL(req->out.hdr,HDR_TID,tcon->tid); SSVAL(req->out.hdr,HDR_PID,0xFFFF); SSVAL(req->out.hdr,HDR_UID,0); SSVAL(req->out.hdr,HDR_MID,0xFFFF); SCVAL(req->out.hdr,HDR_FLG,0); SSVAL(req->out.hdr,HDR_FLG2,0); SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); SSVAL(req->out.vwv, VWV(1), 0); smbsrv_push_fnum(req->out.vwv, VWV(2), ntvfs); SCVAL(req->out.vwv, VWV(3), LOCKING_ANDX_OPLOCK_RELEASE); SCVAL(req->out.vwv, VWV(3)+1, level); SIVAL(req->out.vwv, VWV(4), 0); SSVAL(req->out.vwv, VWV(6), 0); SSVAL(req->out.vwv, VWV(7), 0); smbsrv_send_reply(req); return NT_STATUS_OK; }
void cli_setup_packet_buf(struct cli_state *cli, char *buf) { uint16 flags2; cli->rap_error = 0; SIVAL(buf,smb_rcls,0); SSVAL(buf,smb_pid,cli->pid); memset(buf+smb_pidhigh, 0, 12); SSVAL(buf,smb_uid,cli->vuid); SSVAL(buf,smb_mid,cli->mid); if (cli->protocol <= PROTOCOL_CORE) { return; } if (cli->case_sensitive) { SCVAL(buf,smb_flg,0x0); } else { /* Default setting, case insensitive. */ SCVAL(buf,smb_flg,0x8); } flags2 = FLAGS2_LONG_PATH_COMPONENTS; if (cli->capabilities & CAP_UNICODE) flags2 |= FLAGS2_UNICODE_STRINGS; if ((cli->capabilities & CAP_DFS) && cli->dfsroot) flags2 |= FLAGS2_DFS_PATHNAMES; if (cli->capabilities & CAP_STATUS32) flags2 |= FLAGS2_32_BIT_ERROR_CODES; if (cli->use_spnego) flags2 |= FLAGS2_EXTENDED_SECURITY; SSVAL(buf,smb_flg2, flags2); }
void cli_negprot_send(struct cli_state *cli) { char *p; int numprots; memset(cli->outbuf,'\0',smb_size); /* setup the protocol strings */ set_message(cli->outbuf,0,0,True); p = smb_buf(cli->outbuf); for (numprots=0; prots[numprots].name && prots[numprots].prot<=cli->protocol; numprots++) { *p++ = 2; p += clistr_push(cli, p, prots[numprots].name, -1, STR_CONVERT|STR_TERMINATE); } SCVAL(cli->outbuf,smb_com,SMBnegprot); cli_setup_bcc(cli, p); cli_setup_packet(cli); SCVAL(smb_buf(cli->outbuf),0,2); cli_send_smb(cli); }
static void send_election_dgram(struct subnet_record *subrec, const char *workgroup_name, uint32 criterion, int timeup,const char *server_name) { pstring outbuf; unstring srv_name; char *p; DEBUG(2,("send_election_dgram: Sending election packet for workgroup %s on subnet %s\n", workgroup_name, subrec->subnet_name )); memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; SCVAL(p,0,ANN_Election); /* Election opcode. */ p++; SCVAL(p,0,((criterion == 0 && timeup == 0) ? 0 : ELECTION_VERSION)); SIVAL(p,1,criterion); SIVAL(p,5,timeup*1000); /* ms - Despite what the spec says. */ p += 13; unstrcpy(srv_name, server_name); strupper_m(srv_name); /* The following call does UNIX -> DOS charset conversion. */ pstrcpy_base(p, srv_name, outbuf); p = skip_string(p,1); send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), global_myname(), 0, workgroup_name, 0x1e, subrec->bcast_ip, subrec->myip, DGRAM_PORT); }
static void send_announcement(struct subnet_record *subrec, int announce_type, const char *from_name, const char *to_name, int to_type, struct in_addr to_ip, time_t announce_interval, const char *server_name, int server_type, const char *server_comment) { pstring outbuf; char *p; memset(outbuf,'\0',sizeof(outbuf)); p = outbuf+1; SCVAL(outbuf,0,announce_type); /* Announcement parameters. */ SCVAL(p,0,updatecount); SIVAL(p,1,announce_interval*1000); /* Milliseconds - despite the spec. */ push_string(NULL, p+5, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE); SCVAL(p,21,lp_major_announce_version()); /* Major version. */ SCVAL(p,22,lp_minor_announce_version()); /* Minor version. */ SIVAL(p,23,server_type & ~SV_TYPE_LOCAL_LIST_ONLY); /* Browse version: got from NT/AS 4.00 - Value defined in smb.h (JHT). */ SSVAL(p,27,BROWSER_ELECTION_VERSION); SSVAL(p,29,BROWSER_CONSTANT); /* Browse signature. */ p += 31 + push_string(NULL, p+31, server_comment, -1, STR_ASCII|STR_TERMINATE); send_mailslot(False,BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), from_name, 0x0, to_name, to_type, to_ip, subrec->myip, DGRAM_PORT); }
static void send_election_dgram(struct subnet_record *subrec, const char *workgroup_name, uint32_t criterion, int timeup,const char *server_name) { char outbuf[1024]; unstring srv_name; char *p; DEBUG(2,("send_election_dgram: Sending election packet for workgroup %s on subnet %s\n", workgroup_name, subrec->subnet_name )); memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; SCVAL(p,0,ANN_Election); /* Election opcode. */ p++; SCVAL(p,0,((criterion == 0 && timeup == 0) ? 0 : ELECTION_VERSION)); SIVAL(p,1,criterion); SIVAL(p,5,timeup*1000); /* ms - Despite what the spec says. */ p += 13; unstrcpy(srv_name, server_name); if (!strupper_m(srv_name)) { DEBUG(2,("strupper_m failed for %s\n", srv_name)); return; } /* The following call does UNIX -> DOS charset conversion. */ push_ascii(p, srv_name, sizeof(outbuf)-PTR_DIFF(p,outbuf)-1, STR_TERMINATE); p = skip_string(outbuf,sizeof(outbuf),p); send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), lp_netbios_name(), 0, workgroup_name, 0x1e, subrec->bcast_ip, subrec->myip, DGRAM_PORT); }
/** send a session setup request */ struct smb2_request *smb2_session_setup_send(struct smb2_session *session, struct smb2_session_setup *io) { struct smb2_request *req; NTSTATUS status; req = smb2_request_init(session->transport, SMB2_OP_SESSSETUP, 0x18, true, io->in.secblob.length); if (req == NULL) return NULL; SBVAL(req->out.hdr, SMB2_HDR_SESSION_ID, session->uid); SCVAL(req->out.body, 0x02, io->in.vc_number); SCVAL(req->out.body, 0x03, io->in.security_mode); SIVAL(req->out.body, 0x04, io->in.capabilities); SIVAL(req->out.body, 0x08, io->in.channel); SBVAL(req->out.body, 0x10, io->in.previous_sessionid); req->session = session; status = smb2_push_o16s16_blob(&req->out, 0x0C, io->in.secblob); if (!NT_STATUS_IS_OK(status)) { talloc_free(req); return NULL; } smb2_transport_send(req); return req; }
void broadcast_announce_request(struct subnet_record *subrec, struct work_record *work) { pstring outbuf; char *p; work->needannounce = True; DEBUG(3,("broadcast_announce_request: sending announce request for workgroup %s \ to subnet %s\n", work->work_group, subrec->subnet_name)); memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; SCVAL(p,0,ANN_AnnouncementRequest); p++; SCVAL(p,0,work->token); /* (local) Unique workgroup token id. */ p++; StrnCpy(p,global_myname,15); strupper(p); p = skip_string(p,1); send_mailslot(False, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), global_myname, 0x0, work->work_group,0x1e, subrec->bcast_ip, subrec->myip, DGRAM_PORT); }
static void send_lm_announcement(struct subnet_record *subrec, int announce_type, char *from_name, char *to_name, int to_type, struct in_addr to_ip, time_t announce_interval, char *server_name, int server_type, char *server_comment) { pstring outbuf; char *p=outbuf; memset(outbuf,'\0',sizeof(outbuf)); SSVAL(p,0,announce_type); SIVAL(p,2,server_type & ~SV_TYPE_LOCAL_LIST_ONLY); SCVAL(p,6,lp_major_announce_version()); /* Major version. */ SCVAL(p,7,lp_minor_announce_version()); /* Minor version. */ SSVAL(p,8,announce_interval); /* In seconds - according to spec. */ p += 10; StrnCpy(p,server_name,15); strupper(p); p = skip_string(p,1); pstrcpy(p,server_comment); p = skip_string(p,1); send_mailslot(False,LANMAN_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), from_name, 0x0, to_name, to_type, to_ip, subrec->myip, DGRAM_PORT); }
static void smbd_smb2_request_read_done(struct tevent_req *subreq) { struct smbd_smb2_request *req = tevent_req_callback_data(subreq, struct smbd_smb2_request); DATA_BLOB outbody; DATA_BLOB outdyn; uint8_t out_data_offset; DATA_BLOB out_data_buffer = data_blob_null; uint32_t out_data_remaining = 0; NTSTATUS status; NTSTATUS error; /* transport error */ status = smbd_smb2_read_recv(subreq, req, &out_data_buffer, &out_data_remaining); TALLOC_FREE(subreq); if (!NT_STATUS_IS_OK(status)) { error = smbd_smb2_request_error(req, status); if (!NT_STATUS_IS_OK(error)) { smbd_server_connection_terminate(req->xconn, nt_errstr(error)); return; } return; } out_data_offset = SMB2_HDR_BODY + 0x10; outbody = smbd_smb2_generate_outbody(req, 0x10); if (outbody.data == NULL) { error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY); if (!NT_STATUS_IS_OK(error)) { smbd_server_connection_terminate(req->xconn, nt_errstr(error)); return; } return; } SSVAL(outbody.data, 0x00, 0x10 + 1); /* struct size */ SCVAL(outbody.data, 0x02, out_data_offset); /* data offset */ SCVAL(outbody.data, 0x03, 0); /* reserved */ SIVAL(outbody.data, 0x04, out_data_buffer.length); /* data length */ SIVAL(outbody.data, 0x08, out_data_remaining); /* data remaining */ SIVAL(outbody.data, 0x0C, 0); /* reserved */ outdyn = out_data_buffer; error = smbd_smb2_request_done(req, outbody, &outdyn); if (!NT_STATUS_IS_OK(error)) { smbd_server_connection_terminate(req->xconn, nt_errstr(error)); return; } }
static void smb_set_enclen(char *buf,int len,uint16_t enc_ctx_num) { _smb_setlen_nbt(buf,len); SCVAL(buf,4,0xFF); SCVAL(buf,5,'E'); SSVAL(buf,6,enc_ctx_num); }
static void smbd_smb2_request_oplock_break_done(struct tevent_req *subreq) { struct smbd_smb2_request *req = tevent_req_callback_data(subreq, struct smbd_smb2_request); const uint8_t *inbody; int i = req->current_idx; uint64_t in_file_id_persistent; uint64_t in_file_id_volatile; uint8_t out_oplock_level = 0; DATA_BLOB outbody; NTSTATUS status; NTSTATUS error; /* transport error */ status = smbd_smb2_oplock_break_recv(subreq, &out_oplock_level); TALLOC_FREE(subreq); if (!NT_STATUS_IS_OK(status)) { error = smbd_smb2_request_error(req, status); if (!NT_STATUS_IS_OK(error)) { smbd_server_connection_terminate(req->sconn, nt_errstr(error)); return; } return; } inbody = (const uint8_t *)req->in.vector[i+1].iov_base; in_file_id_persistent = BVAL(inbody, 0x08); in_file_id_volatile = BVAL(inbody, 0x10); outbody = data_blob_talloc(req->out.vector, NULL, 0x18); if (outbody.data == NULL) { error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY); if (!NT_STATUS_IS_OK(error)) { smbd_server_connection_terminate(req->sconn, nt_errstr(error)); return; } return; } SSVAL(outbody.data, 0x00, 0x18); /* struct size */ SCVAL(outbody.data, 0x02, out_oplock_level); /* SMB2 oplock level */ SCVAL(outbody.data, 0x03, 0); /* reserved */ SIVAL(outbody.data, 0x04, 0); /* reserved */ SBVAL(outbody.data, 0x08, in_file_id_persistent); /* file id (persistent) */ SBVAL(outbody.data, 0x10, in_file_id_volatile); /* file id (volatile) */ error = smbd_smb2_request_done(req, outbody, NULL); if (!NT_STATUS_IS_OK(error)) { smbd_server_connection_terminate(req->sconn, nt_errstr(error)); return; } }
BOOL cli_lock64(struct cli_state *cli, int fnum, SMB_BIG_UINT offset, SMB_BIG_UINT len, int timeout, enum brl_type lock_type) { char *p; int saved_timeout = cli->timeout; int ltype; if (! (cli->capabilities & CAP_LARGE_FILES)) { return cli_lock(cli, fnum, offset, len, timeout, lock_type); } ltype = (lock_type == READ_LOCK? 1 : 0); ltype |= LOCKING_ANDX_LARGE_FILES; memset(cli->outbuf,'\0',smb_size); memset(cli->inbuf,'\0', smb_size); set_message(cli->outbuf,8,0,True); SCVAL(cli->outbuf,smb_com,SMBlockingX); SSVAL(cli->outbuf,smb_tid,cli->cnum); cli_setup_packet(cli); SCVAL(cli->outbuf,smb_vwv0,0xFF); SSVAL(cli->outbuf,smb_vwv2,fnum); SCVAL(cli->outbuf,smb_vwv3,ltype); SIVALS(cli->outbuf, smb_vwv4, timeout); SSVAL(cli->outbuf,smb_vwv6,0); SSVAL(cli->outbuf,smb_vwv7,1); p = smb_buf(cli->outbuf); SIVAL(p, 0, cli->pid); SOFF_T_R(p, 4, offset); SOFF_T_R(p, 12, len); p += 20; cli_setup_bcc(cli, p); cli_send_smb(cli); if (timeout != 0) { cli->timeout = (timeout == -1) ? 0x7FFFFFFF : (timeout + 5*1000); } if (!cli_receive_smb(cli)) { cli->timeout = saved_timeout; return False; } cli->timeout = saved_timeout; if (cli_is_error(cli)) { return False; } return True; }
static BOOL cli_set_ea(struct cli_state *cli, uint16 setup, char *param, unsigned int param_len, const char *ea_name, const char *ea_val, size_t ea_len) { unsigned int data_len = 0; char *data = NULL; char *rparam=NULL, *rdata=NULL; char *p; size_t ea_namelen = strlen(ea_name); if (ea_namelen == 0 && ea_len == 0) { data_len = 4; data = SMB_MALLOC(data_len); if (!data) { return False; } p = data; SIVAL(p,0,data_len); } else { data_len = 4 + 4 + ea_namelen + 1 + ea_len; data = SMB_MALLOC(data_len); if (!data) { return False; } p = data; SIVAL(p,0,data_len); p += 4; SCVAL(p, 0, 0); /* EA flags. */ SCVAL(p, 1, ea_namelen); SSVAL(p, 2, ea_len); memcpy(p+4, ea_name, ea_namelen+1); /* Copy in the name. */ memcpy(p+4+ea_namelen+1, ea_val, ea_len); } if (!cli_send_trans(cli, SMBtrans2, NULL, /* name */ -1, 0, /* fid, flags */ &setup, 1, 0, /* setup, length, max */ param, param_len, 2, /* param, length, max */ data, data_len, cli->max_xmit /* data, length, max */ )) { return False; } if (!cli_receive_trans(cli, SMBtrans2, &rparam, ¶m_len, &rdata, &data_len)) { return False; } SAFE_FREE(data); SAFE_FREE(rdata); SAFE_FREE(rparam); return True; }
size_t push_ascii_nstring(void *dest, const char *src) { size_t converted_size = 0; bool ret = convert_string_error(CH_UNIX, CH_DOS, src, -1, dest, sizeof(nstring), &converted_size); if (ret) { SCVAL(dest, sizeof(nstring)-1, 0); } else { SCVAL(dest, 0, 0); } return ret ? converted_size : (size_t)-1; }
int cli_nt_create_full(struct cli_state *cli, const char *fname, uint32 CreatFlags, uint32 DesiredAccess, uint32 FileAttributes, uint32 ShareAccess, uint32 CreateDisposition, uint32 CreateOptions, uint8 SecuityFlags) { char *p; int len; memset(cli->outbuf,'\0',smb_size); memset(cli->inbuf,'\0',smb_size); set_message(cli->outbuf,24,0,True); SCVAL(cli->outbuf,smb_com,SMBntcreateX); SSVAL(cli->outbuf,smb_tid,cli->cnum); cli_setup_packet(cli); SSVAL(cli->outbuf,smb_vwv0,0xFF); if (cli->use_oplocks) CreatFlags |= (REQUEST_OPLOCK|REQUEST_BATCH_OPLOCK); SIVAL(cli->outbuf,smb_ntcreate_Flags, CreatFlags); SIVAL(cli->outbuf,smb_ntcreate_RootDirectoryFid, 0x0); SIVAL(cli->outbuf,smb_ntcreate_DesiredAccess, DesiredAccess); SIVAL(cli->outbuf,smb_ntcreate_FileAttributes, FileAttributes); SIVAL(cli->outbuf,smb_ntcreate_ShareAccess, ShareAccess); SIVAL(cli->outbuf,smb_ntcreate_CreateDisposition, CreateDisposition); SIVAL(cli->outbuf,smb_ntcreate_CreateOptions, CreateOptions); SIVAL(cli->outbuf,smb_ntcreate_ImpersonationLevel, 0x02); SCVAL(cli->outbuf,smb_ntcreate_SecurityFlags, SecuityFlags); p = smb_buf(cli->outbuf); /* this alignment and termination is critical for netapp filers. Don't change */ p += clistr_align_out(cli, p, 0); len = clistr_push(cli, p, fname, -1, 0); p += len; SSVAL(cli->outbuf,smb_ntcreate_NameLength, len); /* sigh. this copes with broken netapp filer behaviour */ p += clistr_push(cli, p, "", -1, STR_TERMINATE); cli_setup_bcc(cli, p); cli_send_smb(cli); if (!cli_receive_smb(cli)) { return -1; } if (cli_is_error(cli)) { return -1; } return SVAL(cli->inbuf,smb_vwv2 + 1); }
/* setup a SMB packet at transport level */ struct smbcli_request *smbcli_request_setup_transport(struct smbcli_transport *transport, uint8_t command, unsigned int wct, unsigned int buflen) { struct smbcli_request *req; size_t size; size = NBT_HDR_SIZE + MIN_SMB_SIZE + wct*2 + buflen; req = talloc_zero(transport, struct smbcli_request); if (!req) { return NULL; } /* setup the request context */ req->state = SMBCLI_REQUEST_INIT; req->transport = transport; req->out.size = size; /* over allocate by a small amount */ req->out.allocated = req->out.size + REQ_OVER_ALLOCATION; req->out.buffer = talloc_zero_array(req, uint8_t, req->out.allocated); if (!req->out.buffer) { return NULL; } req->out.hdr = req->out.buffer + NBT_HDR_SIZE; req->out.vwv = req->out.hdr + HDR_VWV; req->out.wct = wct; req->out.data = req->out.vwv + VWV(wct) + 2; req->out.data_size = buflen; req->out.ptr = req->out.data; SCVAL(req->out.hdr, HDR_WCT, wct); SSVAL(req->out.vwv, VWV(wct), buflen); memcpy(req->out.hdr, "\377SMB", 4); SCVAL(req->out.hdr,HDR_COM,command); SCVAL(req->out.hdr,HDR_FLG, FLAG_CASELESS_PATHNAMES); SSVAL(req->out.hdr,HDR_FLG2, 0); /* copy the pid, uid and mid to the request */ SSVAL(req->out.hdr, HDR_PID, 0); SSVAL(req->out.hdr, HDR_UID, 0); SSVAL(req->out.hdr, HDR_MID, 0); SSVAL(req->out.hdr, HDR_TID,0); SSVAL(req->out.hdr, HDR_PIDHIGH,0); SIVAL(req->out.hdr, HDR_RCLS, 0); memset(req->out.hdr+HDR_SS_FIELD, 0, 10); return req; }
static BOOL cli_session_setup_plaintext(struct cli_state *cli, const char *user, const char *pass, const char *workgroup) { uint32 capabilities = cli_session_setup_capabilities(cli); fstring pword; int passlen; char *p; passlen = clistr_push(cli, pword, pass, sizeof(pword), STR_TERMINATE|STR_CONVERT); set_message(cli->outbuf,13,0,True); SCVAL(cli->outbuf,smb_com,SMBsesssetupX); cli_setup_packet(cli); SCVAL(cli->outbuf,smb_vwv0,0xFF); SSVAL(cli->outbuf,smb_vwv2,CLI_BUFFER_SIZE); SSVAL(cli->outbuf,smb_vwv3,2); SSVAL(cli->outbuf,smb_vwv4,cli->pid); SIVAL(cli->outbuf,smb_vwv5,cli->sesskey); SSVAL(cli->outbuf,smb_vwv7,passlen); SSVAL(cli->outbuf,smb_vwv8,0); SIVAL(cli->outbuf,smb_vwv11,capabilities); p = smb_buf(cli->outbuf); memcpy(p, pword, passlen); p += passlen; p += clistr_push(cli, p, user, -1, STR_TERMINATE|STR_CONVERT); /* username */ p += clistr_push(cli, p, workgroup, -1, STR_TERMINATE|STR_CONVERT); /* workgroup */ p += clistr_push(cli, p, "Unix", -1, STR_TERMINATE|STR_CONVERT); p += clistr_push(cli, p, "Samba", -1, STR_TERMINATE|STR_CONVERT); cli_setup_bcc(cli, p); cli_send_smb(cli); if (!cli_receive_smb(cli)) return False; show_msg(cli->inbuf); if (cli_is_error(cli)) { return False; } cli->vuid = SVAL(cli->inbuf,smb_uid); p = smb_buf(cli->inbuf); p += clistr_pull(cli, cli->server_os, p, sizeof(fstring), -1, STR_TERMINATE); p += clistr_pull(cli, cli->server_type, p, sizeof(fstring), -1, STR_TERMINATE); p += clistr_pull(cli, cli->server_domain, p, sizeof(fstring), -1, STR_TERMINATE); fstrcpy(cli->user_name, user); return True; }
/**************************************************************************** Lock a file. note that timeout is in units of 2 milliseconds ****************************************************************************/ BOOL cli_lock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int timeout, enum brl_type lock_type) { char *p; int saved_timeout = cli->timeout; memset(cli->outbuf,'\0',smb_size); memset(cli->inbuf,'\0', smb_size); set_message(cli->outbuf,8,0,True); SCVAL(cli->outbuf,smb_com,SMBlockingX); SSVAL(cli->outbuf,smb_tid,cli->cnum); cli_setup_packet(cli); SCVAL(cli->outbuf,smb_vwv0,0xFF); SSVAL(cli->outbuf,smb_vwv2,fnum); SCVAL(cli->outbuf,smb_vwv3,(lock_type == READ_LOCK? 1 : 0)); SIVALS(cli->outbuf, smb_vwv4, timeout); SSVAL(cli->outbuf,smb_vwv6,0); SSVAL(cli->outbuf,smb_vwv7,1); p = smb_buf(cli->outbuf); SSVAL(p, 0, cli->pid); SIVAL(p, 2, offset); SIVAL(p, 6, len); p += 10; cli_setup_bcc(cli, p); cli_send_smb(cli); if (timeout != 0) { cli->timeout = (timeout == -1) ? 0x7FFFFFFF : (timeout*2 + 5*1000); } if (!cli_receive_smb(cli)) { cli->timeout = saved_timeout; return False; } cli->timeout = saved_timeout; if (cli_is_error(cli)) { return False; } return True; }
static void smb2srv_break_send(struct ntvfs_request *ntvfs) { struct smb2srv_request *req; union smb_lock *io; SMB2SRV_CHECK_ASYNC_STATUS_ERR(io, union smb_lock); SMB2SRV_CHECK(smb2srv_setup_reply(req, 0x18, false, 0)); SCVAL(req->out.body, 0x02, io->smb2_break.out.oplock_level); SCVAL(req->out.body, 0x03, io->smb2_break.out.reserved); SIVAL(req->out.body, 0x04, io->smb2_break.out.reserved2); smb2srv_push_handle(req->out.body, 0x08,io->smb2_break.out.file.ntvfs); smb2srv_send_reply(req); }
static void new_break_message_smb1(files_struct *fsp, int cmd, char result[SMB1_BREAK_MESSAGE_LENGTH]) { memset(result,'\0',smb_size); srv_set_message(result,8,0,true); SCVAL(result,smb_com,SMBlockingX); SSVAL(result,smb_tid,fsp->conn->cnum); SSVAL(result,smb_pid,0xFFFF); SSVAL(result,smb_uid,0); SSVAL(result,smb_mid,0xFFFF); SCVAL(result,smb_vwv0,0xFF); SSVAL(result,smb_vwv2,fsp->fnum); SCVAL(result,smb_vwv3,LOCKING_ANDX_OPLOCK_RELEASE); SCVAL(result,smb_vwv3+1,cmd); }
bool sid_linearize(uint8_t *outbuf, size_t len, const struct dom_sid *sid) { size_t i; if (len < ndr_size_dom_sid(sid, 0)) return False; SCVAL(outbuf,0,sid->sid_rev_num); SCVAL(outbuf,1,sid->num_auths); memcpy(&outbuf[2], sid->id_auth, 6); for(i = 0; i < sid->num_auths; i++) SIVAL(outbuf, 8 + (i*4), sid->sub_auths[i]); return True; }
BOOL sid_linearize(char *outbuf, size_t len, const DOM_SID *sid) { size_t i; if (len < sid_size(sid)) return False; SCVAL(outbuf,0,sid->sid_rev_num); SCVAL(outbuf,1,sid->num_auths); memcpy(&outbuf[2], sid->id_auth, 6); for(i = 0; i < sid->num_auths; i++) SIVAL(outbuf, 8 + (i*4), sid->sub_auths[i]); return True; }
static void blocking_lock_reply_error(struct blocking_lock_record *blr, NTSTATUS status) { DEBUG(10, ("Replying with error=%s. BLR = %p\n", nt_errstr(status), blr)); switch(blr->req->cmd) { case SMBlockingX: reply_lockingX_error(blr, status); break; case SMBtrans2: case SMBtranss2: reply_nterror(blr->req, status); /* * construct_reply_common has done us the favor to pre-fill * the command field with SMBtranss2 which is wrong :-) */ SCVAL(blr->req->outbuf,smb_com,SMBtrans2); if (!srv_send_smb(smbd_server_fd(), (char *)blr->req->outbuf, true, blr->req->seqnum+1, IS_CONN_ENCRYPTED(blr->fsp->conn), NULL)) { exit_server_cleanly("blocking_lock_reply_error: " "srv_send_smb failed."); } TALLOC_FREE(blr->req->outbuf); break; default: DEBUG(0,("blocking_lock_reply_error: PANIC - unknown type on blocking lock queue - exiting.!\n")); exit_server("PANIC - unknown type on blocking lock queue"); } }
/* push a uint8_t */ _PUBLIC_ enum ndr_err_code ndr_push_uint8(struct ndr_push *ndr, int ndr_flags, uint8_t v) { NDR_PUSH_NEED_BYTES(ndr, 1); SCVAL(ndr->data, ndr->offset, v); ndr->offset += 1; return NDR_ERR_SUCCESS; }
/**************************************************************************** send a message ****************************************************************************/ int cli_message_text_build(struct cli_state *cli, char *msg, int len, int grp) { char *msgdos; int lendos; char *p; memset(cli->outbuf,'\0',smb_size); set_message(cli->outbuf,1,0,True); SCVAL(cli->outbuf,smb_com,SMBsendtxt); SSVAL(cli->outbuf,smb_tid,cli->cnum); cli_setup_packet(cli); SSVAL(cli->outbuf,smb_vwv0,grp); p = smb_buf(cli->outbuf); *p++ = 1; if ((lendos = (int)convert_string_allocate(NULL,CH_UNIX, CH_DOS, msg,len, (void **)(void *)&msgdos, True)) < 0 || !msgdos) { DEBUG(3,("Conversion failed, sending message in UNIX charset\n")); SSVAL(p, 0, len); p += 2; memcpy(p, msg, len); p += len; } else { SSVAL(p, 0, lendos); p += 2; memcpy(p, msgdos, lendos); p += lendos; SAFE_FREE(msgdos); } cli_setup_bcc(cli, p); return(PTR_DIFF(p, cli->outbuf)); }
BOOL prs_string2(BOOL charmode, const char *name, prs_struct *ps, int depth, STRING2 *str) { int i; char *q = prs_mem_get(ps, str->str_max_len); if (q == NULL) return False; if (UNMARSHALLING(ps)) { str->buffer = (unsigned char *)prs_alloc_mem(ps,str->str_max_len); if (str->buffer == NULL) return False; } if (UNMARSHALLING(ps)) { for (i = 0; i < str->str_str_len; i++) str->buffer[i] = CVAL(q,i); } else { for (i = 0; i < str->str_str_len; i++) SCVAL(q, i, str->buffer[i]); } DEBUG(5,("%s%04x %s: ", tab_depth(depth), ps->data_offset, name)); if (charmode) print_asc(5, (unsigned char*)str->buffer, str->str_str_len); else { for (i = 0; i < str->str_str_len; i++) DEBUG(5,("%02x ", str->buffer[i])); } DEBUG(5,("\n")); ps->data_offset += str->str_str_len; return True; }
BOOL prs_uint8s(BOOL charmode, const char *name, prs_struct *ps, int depth, uint8 *data8s, int len) { int i; char *q = prs_mem_get(ps, len); if (q == NULL) return False; if (UNMARSHALLING(ps)) { for (i = 0; i < len; i++) data8s[i] = CVAL(q,i); } else { for (i = 0; i < len; i++) SCVAL(q, i, data8s[i]); } DEBUG(5,("%s%04x %s: ", tab_depth(depth), ps->data_offset ,name)); if (charmode) print_asc(5, (unsigned char*)data8s, len); else { for (i = 0; i < len; i++) DEBUG(5,("%02x ", data8s[i])); } DEBUG(5,("\n")); ps->data_offset += len; return True; }