void construct_reply_common(char *inbuf,char *outbuf) { memset(outbuf,'\0',smb_size); set_message(outbuf,0,0,True); CVAL(outbuf,smb_com) = CVAL(inbuf,smb_com); memcpy(outbuf+4,inbuf+4,4); CVAL(outbuf,smb_rcls) = SMB_SUCCESS; CVAL(outbuf,smb_reh) = 0; SCVAL(outbuf,smb_flg, FLAG_REPLY | (CVAL(inbuf,smb_flg) & FLAG_CASELESS_PATHNAMES)); /* bit 7 set means a reply */ SSVAL(outbuf,smb_flg2,FLAGS2_LONG_PATH_COMPONENTS); /* say we support long filenames */ SSVAL(outbuf,smb_err,SMB_SUCCESS); SSVAL(outbuf,smb_tid,SVAL(inbuf,smb_tid)); SSVAL(outbuf,smb_pid,SVAL(inbuf,smb_pid)); SSVAL(outbuf,smb_uid,SVAL(inbuf,smb_uid)); SSVAL(outbuf,smb_mid,SVAL(inbuf,smb_mid)); }
smb_ucs2_t toupper_w(smb_ucs2_t v) { smb_ucs2_t ret; /* LE to native. */ codepoint_t cp = SVAL(&v,0); cp = toupper_m(cp); /* native to LE. */ SSVAL(&ret,0,cp); return ret; }
BOOL cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail) { memset(cli->outbuf,'\0',smb_size); set_message(cli->outbuf,0,0,True); SCVAL(cli->outbuf,smb_com,SMBdskattr); SSVAL(cli->outbuf,smb_tid,cli->cnum); cli_setup_packet(cli); cli_send_smb(cli); if (!cli_receive_smb(cli)) { return False; } *bsize = SVAL(cli->inbuf,smb_vwv1)*SVAL(cli->inbuf,smb_vwv2); *total = SVAL(cli->inbuf,smb_vwv0); *avail = SVAL(cli->inbuf,smb_vwv3); return True; }
void reply_pipe_read_and_X(struct smb_request *req) { smb_np_struct *p = get_rpc_pipe_p(SVAL(req->inbuf,smb_vwv2)); int smb_maxcnt = SVAL(req->inbuf,smb_vwv5); int smb_mincnt = SVAL(req->inbuf,smb_vwv6); int nread = -1; char *data; bool unused; /* we don't use the offset given to use for pipe reads. This is deliberate, instead we always return the next lump of data on the pipe */ #if 0 uint32 smb_offs = IVAL(req->inbuf,smb_vwv3); #endif if (!p) { reply_doserror(req, ERRDOS, ERRbadfid); return; } reply_outbuf(req, 12, smb_maxcnt); data = smb_buf(req->outbuf); nread = read_from_pipe(p, data, smb_maxcnt, &unused); if (nread < 0) { reply_doserror(req, ERRDOS, ERRnoaccess); return; } srv_set_message((char *)req->outbuf, 12, nread, False); SSVAL(req->outbuf,smb_vwv5,nread); SSVAL(req->outbuf,smb_vwv6,smb_offset(data,req->outbuf)); SSVAL(smb_buf(req->outbuf),-2,nread); DEBUG(3,("readX-IPC pnum=%04x min=%d max=%d nread=%d\n", p->pnum, smb_mincnt, smb_maxcnt, nread)); chain_reply(req); }
NTSTATUS cli_get_fs_quota_info(struct cli_state *cli, int quota_fnum, SMB_NTQUOTA_STRUCT *pqt) { uint16_t setup[1]; uint8_t param[2]; uint8_t *rdata=NULL; uint32_t rdata_count=0; SMB_NTQUOTA_STRUCT qt; NTSTATUS status; ZERO_STRUCT(qt); if (!cli||!pqt) { smb_panic("cli_get_fs_quota_info() called with NULL Pointer!"); } SSVAL(setup + 0, 0, TRANSACT2_QFSINFO); SSVAL(param,0,SMB_FS_QUOTA_INFORMATION); status = cli_trans(talloc_tos(), cli, SMBtrans2, NULL, -1, /* name, fid */ 0, 0, /* function, flags */ setup, 1, 0, /* setup */ param, 2, 0, /* param */ NULL, 0, 560, /* data */ NULL, /* recv_flags2 */ NULL, 0, NULL, /* rsetup */ NULL, 0, NULL, /* rparam */ &rdata, 48, &rdata_count); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("SMB_FS_QUOTA_INFORMATION failed: %s\n", nt_errstr(status))); return status; } /* unknown_1 24 NULL bytes in pdata*/ /* the soft quotas 8 bytes (uint64_t)*/ qt.softlim = BVAL(rdata,24); /* the hard quotas 8 bytes (uint64_t)*/ qt.hardlim = BVAL(rdata,32); /* quota_flags 2 bytes **/ qt.qflags = SVAL(rdata,40); qt.qtype = SMB_USER_FS_QUOTA_TYPE; *pqt = qt; TALLOC_FREE(rdata); return status; }
struct pending_message_list *get_open_deferred_message(uint16 mid) { struct pending_message_list *pml; for (pml = deferred_open_queue; pml; pml = pml->next) { if (SVAL(pml->buf.data,smb_mid) == mid) { return pml; } } return NULL; }
size_t clistr_pull_fn(const char *inbuf, char *dest, const void *src, int dest_len, int src_len, int flags) { return pull_string_fn(inbuf, SVAL(inbuf, smb_flg2), dest, src, dest_len, src_len, flags); }
NTSTATUS smbd_smb2_request_process_break(struct smbd_smb2_request *req) { const uint8_t *inhdr; const uint8_t *inbody; int i = req->current_idx; size_t expected_body_size = 0x18; size_t body_size; uint8_t in_oplock_level; uint64_t in_file_id_persistent; uint64_t in_file_id_volatile; struct tevent_req *subreq; inhdr = (const uint8_t *)req->in.vector[i+0].iov_base; if (req->in.vector[i+1].iov_len != (expected_body_size & 0xFFFFFFFE)) { return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER); } inbody = (const uint8_t *)req->in.vector[i+1].iov_base; body_size = SVAL(inbody, 0x00); if (body_size != expected_body_size) { return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER); } in_oplock_level = CVAL(inbody, 0x02); if (in_oplock_level != SMB2_OPLOCK_LEVEL_NONE && in_oplock_level != SMB2_OPLOCK_LEVEL_II) { return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER); } /* 0x03 1 bytes reserved */ /* 0x04 4 bytes reserved */ in_file_id_persistent = BVAL(inbody, 0x08); in_file_id_volatile = BVAL(inbody, 0x10); if (req->compat_chain_fsp) { /* skip check */ } else if (in_file_id_persistent != in_file_id_volatile) { return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED); } subreq = smbd_smb2_oplock_break_send(req, req->sconn->smb2.event_ctx, req, in_oplock_level, in_file_id_volatile); if (subreq == NULL) { return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY); } tevent_req_set_callback(subreq, smbd_smb2_request_oplock_break_done, req); return smbd_smb2_request_pending_queue(req, subreq); }
bool cli_is_dos_error(struct cli_state *cli) { uint32 flgs2 = SVAL(cli->inbuf,smb_flg2); /* A socket error is always a DOS error. */ if (cli->fd == -1 && cli->smb_rw_error != 0) { return True; } return cli_is_error(cli) && !(flgs2 & FLAGS2_32_BIT_ERROR_CODES); }
static void vxfs_print_ace_buf(char *buf, int count) { int i, offset = 0; uint16_t type, perm; uint32_t id; DEBUG(10, ("vfs_vxfs: Printing aces:\n")); for (i = 0; i < count; i++) { type = SVAL(buf, offset); offset += 2; perm = SVAL(buf, offset); offset += 2; id = IVAL(buf, offset); offset += 4; DEBUG(10, ("vfs_vxfs: type = %u, perm = %u, id = %u\n", (unsigned int)type, (unsigned int)perm, (unsigned int)id)); } }
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); }
_PUBLIC_ enum ndr_err_code ndr_pull_AV_PAIR_LIST(struct ndr_pull *ndr, int ndr_flags, struct AV_PAIR_LIST *r) { uint32_t cntr_pair_0; TALLOC_CTX *_mem_save_pair_0; if (ndr_flags & NDR_SCALARS) { uint32_t offset = 0; NDR_CHECK(ndr_pull_align(ndr, 4)); r->count = 0; if (ndr->data_size > 0) { NDR_PULL_NEED_BYTES(ndr, 4); } while (offset + 4 <= ndr->data_size) { uint16_t length; uint16_t type; type = SVAL(ndr->data + offset, 0); if (type == MsvAvEOL) { r->count++; break; } length = SVAL(ndr->data + offset, 2); offset += length + 4; r->count++; } NDR_PULL_ALLOC_N(ndr, r->pair, r->count); _mem_save_pair_0 = NDR_PULL_GET_MEM_CTX(ndr); NDR_PULL_SET_MEM_CTX(ndr, r->pair, 0); for (cntr_pair_0 = 0; cntr_pair_0 < r->count; cntr_pair_0++) { NDR_CHECK(ndr_pull_AV_PAIR(ndr, NDR_SCALARS, &r->pair[cntr_pair_0])); } NDR_PULL_SET_MEM_CTX(ndr, _mem_save_pair_0, 0); } if (ndr_flags & NDR_BUFFERS) { _mem_save_pair_0 = NDR_PULL_GET_MEM_CTX(ndr); NDR_PULL_SET_MEM_CTX(ndr, r->pair, 0); for (cntr_pair_0 = 0; cntr_pair_0 < r->count; cntr_pair_0++) { NDR_CHECK(ndr_pull_AV_PAIR(ndr, NDR_BUFFERS, &r->pair[cntr_pair_0])); } NDR_PULL_SET_MEM_CTX(ndr, _mem_save_pair_0, 0); } return NDR_ERR_SUCCESS; }
BOOL open_was_deferred(uint16 mid) { struct pending_message_list *pml; for (pml = deferred_open_queue; pml; pml = pml->next) { if (SVAL(pml->buf.data,smb_mid) == mid) { set_saved_ntstatus(NT_STATUS_OK); return True; } } return False; }
/* * Compare aces * This will compare two ace entries for sorting * each entry contains: type, perms and id * Sort by type first, if type is same sort by id. */ static int vxfs_ace_cmp(const void *ace1, const void *ace2) { int ret = 0; uint16_t type_a1, type_a2; uint32_t id_a1, id_a2; /* Type must be compared first */ type_a1 = SVAL(ace1, 0); type_a2 = SVAL(ace2, 0); ret = (type_a1 - type_a2); if (!ret) { /* Compare ID under type */ /* skip perm thus take offset as 4*/ id_a1 = IVAL(ace1, 4); id_a2 = IVAL(ace2, 4); ret = id_a1 - id_a2; } return ret; }
int unistrcpy(uint16 *dst, uint16 *src) { int num_wchars = 0; while (SVAL(src,0)) { *dst++ = *src++; num_wchars++; } *dst = 0; return num_wchars; }
void pike_module_init( void ) { STRS(data) = make_shared_string("data"); STRS(file) = make_shared_string("file"); STRS(method) = make_shared_string("method"); STRS(protocol) = make_shared_string("protocol"); STRS(query) = make_shared_string("query"); STRS(raw_url) = make_shared_string("raw_url"); SVAL(data)->type = T_STRING; SVAL(file)->type = T_STRING; SVAL(method)->type = T_STRING; SVAL(protocol)->type = T_STRING; SVAL(query)->type = T_STRING; SVAL(raw_url)->type = T_STRING; add_function_constant( "parse_headers", f_parse_headers, "function(string:mapping)", 0); add_function_constant( "parse_query_string", f_parse_query_string, "function(string,mapping:void)", OPT_SIDE_EFFECT); add_function_constant( "get_address", f_get_address, "function(string:string)", 0); start_new_program(); ADD_STORAGE( buffer ); add_function( "append", f_buf_append, "function(string:int)", OPT_SIDE_EFFECT ); add_function( "create", f_buf_create, "function(mapping,mapping:void)", 0 ); set_exit_callback(free_buf_struct); set_init_callback(alloc_buf_struct); parsehttp_program = end_program(); add_program_constant("ParseHTTP", parsehttp_program, 0); }
int reply_pipe_read_and_X(char *inbuf,char *outbuf,int length,int bufsize) { smb_np_struct *p = get_rpc_pipe_p(inbuf,smb_vwv2); int smb_maxcnt = SVAL(inbuf,smb_vwv5); int smb_mincnt = SVAL(inbuf,smb_vwv6); int nread = -1; char *data; BOOL unused; /* we don't use the offset given to use for pipe reads. This is deliberate, instead we always return the next lump of data on the pipe */ #if 0 uint32 smb_offs = IVAL(inbuf,smb_vwv3); #endif if (!p) { return(ERROR_DOS(ERRDOS,ERRbadfid)); } set_message(outbuf,12,0,True); data = smb_buf(outbuf); nread = read_from_pipe(p, data, smb_maxcnt, &unused); if (nread < 0) { return(UNIXERROR(ERRDOS,ERRnoaccess)); } SSVAL(outbuf,smb_vwv5,nread); SSVAL(outbuf,smb_vwv6,smb_offset(data,outbuf)); SSVAL(smb_buf(outbuf),-2,nread); DEBUG(3,("readX-IPC pnum=%04x min=%d max=%d nread=%d\n", p->pnum, smb_mincnt, smb_maxcnt, nread)); /* Ensure we set up the message length to include the data length read. */ set_message_bcc(outbuf,nread); return chain_reply(inbuf,outbuf,length,bufsize); }
NTSTATUS smbd_smb2_request_process_notify(struct smbd_smb2_request *req) { NTSTATUS status; const uint8_t *inbody; int i = req->current_idx; uint16_t in_flags; uint32_t in_output_buffer_length; uint64_t in_file_id_persistent; uint64_t in_file_id_volatile; uint64_t in_completion_filter; struct tevent_req *subreq; status = smbd_smb2_request_verify_sizes(req, 0x20); if (!NT_STATUS_IS_OK(status)) { return smbd_smb2_request_error(req, status); } inbody = (const uint8_t *)req->in.vector[i+1].iov_base; in_flags = SVAL(inbody, 0x02); in_output_buffer_length = IVAL(inbody, 0x04); in_file_id_persistent = BVAL(inbody, 0x08); in_file_id_volatile = BVAL(inbody, 0x10); in_completion_filter = IVAL(inbody, 0x18); /* * 0x00010000 is what Windows 7 uses, * Windows 2008 uses 0x00080000 */ if (in_output_buffer_length > lp_smb2_max_trans()) { return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER); } if (req->compat_chain_fsp) { /* skip check */ } else if (in_file_id_persistent != in_file_id_volatile) { return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED); } subreq = smbd_smb2_notify_send(req, req->sconn->smb2.event_ctx, req, in_flags, in_output_buffer_length, in_file_id_volatile, in_completion_filter); if (subreq == NULL) { return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY); } tevent_req_set_callback(subreq, smbd_smb2_request_notify_done, req); return smbd_smb2_request_pending_queue(req, subreq); }
/* handle oplock break requests from the server - return true if the request was an oplock break */ bool smbcli_handle_oplock_break(struct smbcli_transport *transport, unsigned int len, const uint8_t *hdr, const uint8_t *vwv) { /* we must be very fussy about what we consider an oplock break to avoid matching readbraw replies */ if (len != MIN_SMB_SIZE + VWV(8) + NBT_HDR_SIZE || (CVAL(hdr, HDR_FLG) & FLAG_REPLY) || CVAL(hdr,HDR_COM) != SMBlockingX || SVAL(hdr, HDR_MID) != 0xFFFF || SVAL(vwv,VWV(6)) != 0 || SVAL(vwv,VWV(7)) != 0) { return false; } if (transport->oplock.handler) { uint16_t tid = SVAL(hdr, HDR_TID); uint16_t fnum = SVAL(vwv,VWV(2)); uint8_t level = CVAL(vwv,VWV(3)+1); transport->oplock.handler(transport, tid, fnum, level, transport->oplock.private_data); } return true; }
size_t clistr_pull_fn(const char *function, unsigned int line, struct cli_state *cli, char *dest, const void *src, int dest_len, int src_len, int flags) { return pull_string_fn(function, line, cli->inbuf, SVAL(cli->inbuf, smb_flg2), dest, src, dest_len, src_len, flags); }
static void filter_request(char *buf) { int msg_type = CVAL(buf,0); int type = CVAL(buf,smb_com); pstring name1,name2; unsigned x; if (msg_type) { /* it's a netbios special */ switch (msg_type) { case 0x81: /* session request */ name_extract(buf,4,name1); name_extract(buf,4 + name_len(buf + 4),name2); d_printf("sesion_request: %s -> %s\n", name1, name2); if (netbiosname) { /* replace the destination netbios name */ name_mangle(netbiosname, buf+4, 0x20); } } return; } /* it's an ordinary SMB request */ switch (type) { case SMBsesssetupX: /* force the client capabilities */ x = IVAL(buf,smb_vwv11); d_printf("SMBsesssetupX cap=0x%08x\n", x); d_printf("pwlen=%d/%d\n", SVAL(buf, smb_vwv7), SVAL(buf, smb_vwv8)); system("mv sessionsetup.dat sessionsetup1.dat"); save_file("sessionsetup.dat", smb_buf(buf), SVAL(buf, smb_vwv7)); x = (x | CLI_CAPABILITY_SET) & ~CLI_CAPABILITY_MASK; SIVAL(buf, smb_vwv11, x); break; } }
void reply_pipe_write(struct smb_request *req) { smb_np_struct *p = get_rpc_pipe_p(SVAL(req->inbuf,smb_vwv0)); size_t numtowrite = SVAL(req->inbuf,smb_vwv1); int nwritten; char *data; if (!p) { reply_doserror(req, ERRDOS, ERRbadfid); return; } if (p->vuid != req->vuid) { reply_nterror(req, NT_STATUS_INVALID_HANDLE); return; } data = smb_buf(req->inbuf) + 3; if (numtowrite == 0) { nwritten = 0; } else { nwritten = write_to_pipe(p, data, numtowrite); } if ((nwritten == 0 && numtowrite != 0) || (nwritten < 0)) { reply_unixerror(req, ERRDOS, ERRnoaccess); return; } reply_outbuf(req, 1, 0); SSVAL(req->outbuf,smb_vwv0,nwritten); DEBUG(3,("write-IPC pnum=%04x nwritten=%d\n", p->pnum, nwritten)); return; }
/* trans2 open implementation */ static NTSTATUS trans2_open(struct smbsrv_request *req, struct trans_op *op) { struct smb_trans2 *trans = op->trans; union smb_open *io; /* make sure we got enough parameters */ if (trans->in.params.length < 29) { return NT_STATUS_FOOBAR; } io = talloc(op, union smb_open); NT_STATUS_HAVE_NO_MEMORY(io); io->t2open.level = RAW_OPEN_T2OPEN; io->t2open.in.flags = SVAL(trans->in.params.data, VWV(0)); io->t2open.in.open_mode = SVAL(trans->in.params.data, VWV(1)); io->t2open.in.search_attrs = SVAL(trans->in.params.data, VWV(2)); io->t2open.in.file_attrs = SVAL(trans->in.params.data, VWV(3)); io->t2open.in.write_time = srv_pull_dos_date(req->smb_conn, trans->in.params.data + VWV(4)); io->t2open.in.open_func = SVAL(trans->in.params.data, VWV(6)); io->t2open.in.size = IVAL(trans->in.params.data, VWV(7)); io->t2open.in.timeout = IVAL(trans->in.params.data, VWV(9)); io->t2open.in.num_eas = 0; io->t2open.in.eas = NULL; smbsrv_blob_pull_string(&req->in.bufinfo, &trans->in.params, 28, &io->t2open.in.fname, 0); if (io->t2open.in.fname == NULL) { return NT_STATUS_FOOBAR; } TRANS2_CHECK(ea_pull_list(&trans->in.data, io, &io->t2open.in.num_eas, &io->t2open.in.eas)); op->op_info = io; op->send_fn = trans2_open_send; return ntvfs_open(req->ntvfs, io); }
BOOL cli_receive_smb(struct cli_state *cli) { extern int smb_read_error; BOOL ret; /* fd == -1 causes segfaults -- Tom ([email protected]) */ if (cli->fd == -1) return False; again: ret = client_receive_smb(cli->fd,cli->inbuf,abs(cli->timeout)); if (ret) { /* it might be an oplock break request */ if (!(CVAL(cli->inbuf, smb_flg) & FLAG_REPLY) && CVAL(cli->inbuf,smb_com) == SMBlockingX && SVAL(cli->inbuf,smb_vwv6) == 0 && SVAL(cli->inbuf,smb_vwv7) == 0) { if (cli->oplock_handler) { int fnum = SVAL(cli->inbuf,smb_vwv2); unsigned char level = CVAL(cli->inbuf,smb_vwv3+1); if (!cli->oplock_handler(cli, fnum, level)) return False; } /* try to prevent loops */ SCVAL(cli->inbuf,smb_com,0xFF); goto again; } } /* If the server is not responding, note that now */ if (!ret) { cli->smb_rw_error = smb_read_error; close(cli->fd); cli->fd = -1; } return ret; }
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; }
int unistrlen(uint16 *s) { int len; if (!s) { return -1; } for (len=0; SVAL(s,0); s++,len++) { ; } return len; }
size_t pull_string_fn(const char *function, unsigned int line, const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { #ifdef DEVELOPER if (dest_len != (size_t)-1) clobber_region(function, line, dest, dest_len); #endif if (!(flags & STR_ASCII) && \ ((flags & STR_UNICODE || \ (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) { return pull_ucs2(base_ptr, dest, src, dest_len, src_len, flags); } return pull_ascii(dest, src, dest_len, src_len, flags); }
static BOOL cli_dfs_check_error( struct cli_state *cli, NTSTATUS status ) { uint32 flgs2 = SVAL(cli->inbuf,smb_flg2); /* only deal with DS when we negotiated NT_STATUS codes and UNICODE */ if ( !( (flgs2&FLAGS2_32_BIT_ERROR_CODES) && (flgs2&FLAGS2_UNICODE_STRINGS) ) ) return False; if ( NT_STATUS_EQUAL( status, NT_STATUS(IVAL(cli->inbuf,smb_rcls)) ) ) return True; return False; }
const char *va_str_val(Value value) { if (value.type == VAL_TYPE_STR) { return SVAL(value); } else if (value.type == VAL_TYPE_REGEX) { return RVAL(value).regex_pattern; } else if (value.type == VAL_TYPE_SHELL_COMMAND) { return CVAL(value); } assert(!"Invalid value type"); return NULL; }
void va_free_value(Value value) { if (!STR_BASED_VAL(value)) { return; } if (value.type == VAL_TYPE_STR) { free(SVAL(value)); } else if (value.type == VAL_TYPE_REGEX) { free(RVAL(value).regex_pattern); } else if (value.type == VAL_TYPE_SHELL_COMMAND) { free(CVAL(value)); } }