1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-27 14:04:05 +03:00

moved nmblib-specific code from util.c to nmblib.c.

(This used to be commit 1b9077a1d5295bc8522b83ebed2d41d5dbd28a27)
This commit is contained in:
Luke Leighton 2000-03-27 01:33:43 +00:00
parent 3a290ce80c
commit 4acd40ee00
3 changed files with 546 additions and 544 deletions

View File

@ -186,10 +186,212 @@ void CatchChildLeaveStatus(void);
int vslprintf(char *str, int n, char *format, va_list ap);
/*The following definitions come from libsmb/clientgen.c */
int cli_set_port(struct cli_state *cli, int port);
char *cli_errstr(struct cli_state *cli);
BOOL cli_api_pipe(struct cli_state *cli, char *pipe_name, int pipe_name_len,
uint16 *setup, uint32 setup_count, uint32 max_setup_count,
char *params, uint32 param_count, uint32 max_param_count,
char *data, uint32 data_count, uint32 max_data_count,
char **rparam, uint32 *rparam_count,
char **rdata, uint32 *rdata_count);
BOOL cli_api(struct cli_state *cli,
char *param, int prcnt, int mprcnt,
char *data, int drcnt, int mdrcnt,
char **rparam, int *rprcnt,
char **rdata, int *rdrcnt);
BOOL cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation);
int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, const char *));
BOOL cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
void (*fn)(const char *, uint32, const char *));
BOOL cli_session_setup(struct cli_state *cli,
char *user,
char *pass, int passlen,
char *ntpass, int ntpasslen,
char *workgroup);
BOOL cli_ulogoff(struct cli_state *cli);
BOOL cli_send_tconX(struct cli_state *cli,
char *share, char *dev, char *pass, int passlen);
BOOL cli_tdis(struct cli_state *cli);
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, enum brl_type lock_type);
BOOL cli_unlock(struct cli_state *cli, int fnum, uint32 offset, uint32 len);
size_t cli_read(struct cli_state *cli, int fnum, char *buf, off_t offset, size_t size);
ssize_t cli_write(struct cli_state *cli,
int fnum, uint16 write_mode,
char *buf, off_t offset, size_t size);
ssize_t cli_smbwrite(struct cli_state *cli,
int fnum, char *buf, off_t offset, size_t size1);
BOOL cli_getattrE(struct cli_state *cli, int fd,
uint16 *attr, size_t *size,
time_t *c_time, time_t *a_time, time_t *m_time);
BOOL cli_getatr(struct cli_state *cli, char *fname,
uint16 *attr, size_t *size, time_t *t);
BOOL cli_setatr(struct cli_state *cli, char *fname, uint16 attr, time_t t);
BOOL cli_qpathinfo(struct cli_state *cli, const char *fname,
time_t *c_time, time_t *a_time, time_t *m_time,
size_t *size, uint16 *mode);
BOOL cli_qpathinfo2(struct cli_state *cli, const char *fname,
time_t *c_time, time_t *a_time, time_t *m_time,
time_t *w_time, size_t *size, uint16 *mode,
SMB_INO_T *ino);
BOOL cli_qfileinfo(struct cli_state *cli, int fnum,
uint16 *mode, size_t *size,
time_t *c_time, time_t *a_time, time_t *m_time,
time_t *w_time, SMB_INO_T *ino);
int cli_list(struct cli_state *cli,const char *Mask,uint16 attribute,
void (*fn)(file_info *, const char *));
BOOL cli_oem_change_password(struct cli_state *cli, const char *user, const char *new_password,
const char *old_password);
BOOL cli_negprot(struct cli_state *cli);
BOOL cli_session_request(struct cli_state *cli,
struct nmb_name *calling, struct nmb_name *called);
BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip);
struct cli_state *cli_initialise(struct cli_state *cli);
void cli_shutdown(struct cli_state *cli);
int cli_error(struct cli_state *cli, uint8 *eclass, uint32 *num, uint32 *nt_rpc_error);
void cli_sockopt(struct cli_state *cli, char *options);
uint16 cli_setpid(struct cli_state *cli, uint16 pid);
BOOL cli_reestablish_connection(struct cli_state *cli);
BOOL cli_establish_connection(struct cli_state *cli,
char *dest_host, struct in_addr *dest_ip,
struct nmb_name *calling, struct nmb_name *called,
char *service, char *service_type,
BOOL do_shutdown, BOOL do_tcon);
int cli_printjob_del(struct cli_state *cli, int job);
int cli_print_queue(struct cli_state *cli,
void (*fn)(struct print_job_info *));
BOOL cli_chkpath(struct cli_state *cli, char *path);
BOOL cli_message_start(struct cli_state *cli, char *host, char *username,
int *grp);
BOOL cli_message_text(struct cli_state *cli, char *msg, int len, int grp);
BOOL cli_message_end(struct cli_state *cli, int grp);
BOOL cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail);
BOOL attempt_netbios_session_request(struct cli_state *cli, char *srchost, char *desthost,
struct in_addr *pdest_ip);
/*The following definitions come from libsmb/credentials.c */
char *credstr(uchar *cred);
void cred_session_key(DOM_CHAL *clnt_chal, DOM_CHAL *srv_chal, char *pass,
uchar session_key[8]);
void cred_create(uchar session_key[8], DOM_CHAL *stor_cred, UTIME timestamp,
DOM_CHAL *cred);
int cred_assert(DOM_CHAL *cred, uchar session_key[8], DOM_CHAL *stored_cred,
UTIME timestamp);
BOOL clnt_deal_with_creds(uchar sess_key[8],
DOM_CRED *sto_clnt_cred, DOM_CRED *rcv_srv_cred);
BOOL deal_with_creds(uchar sess_key[8],
DOM_CRED *sto_clnt_cred,
DOM_CRED *rcv_clnt_cred, DOM_CRED *rtn_srv_cred);
/*The following definitions come from libsmb/namequery.c */
BOOL name_status(int fd,char *name,int name_type,BOOL recurse,
struct in_addr to_ip,char *master,char *rname);
struct in_addr *name_query(int fd,const char *name,int name_type,
BOOL bcast,BOOL recurse,
struct in_addr to_ip, int *count);
FILE *startlmhosts(char *fname);
BOOL getlmhostsent( FILE *fp, pstring name, int *name_type, struct in_addr *ipaddr);
void endlmhosts(FILE *fp);
BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type);
BOOL find_master_ip(char *group, struct in_addr *master_ip);
BOOL lookup_pdc_name(const char *srcname, const char *domain, struct in_addr *pdc_ip, char *ret_name);
BOOL get_dc_list(char *group, struct in_addr **ip_list, int *count);
/*The following definitions come from libsmb/nmblib.c */
void debug_nmb_packet(struct packet_struct *p);
char *nmb_namestr(struct nmb_name *n);
struct packet_struct *copy_packet(struct packet_struct *packet);
void free_packet(struct packet_struct *packet);
struct packet_struct *parse_packet(char *buf,int length,
enum packet_type packet_type);
struct packet_struct *read_packet(int fd,enum packet_type packet_type);
void make_nmb_name( struct nmb_name *n, const char *name, int type);
BOOL nmb_name_equal(struct nmb_name *n1, struct nmb_name *n2);
int build_packet(char *buf, struct packet_struct *p);
BOOL send_packet(struct packet_struct *p);
struct packet_struct *receive_packet(int fd,enum packet_type type,int t);
struct packet_struct *receive_nmb_packet(int fd, int t, int trn_id);
struct packet_struct *receive_dgram_packet(int fd, int t, char *mailslot_name);
BOOL match_mailslot_name(struct packet_struct *p, char *mailslot_name);
void sort_query_replies(char *data, int n, struct in_addr ip);
char *dns_to_netbios_name(char *dns_name);
int name_mangle( char *In, char *Out, char name_type );
int name_extract(char *buf,int ofs,char *name);
int name_len(char *s1);
/*The following definitions come from libsmb/nterr.c */
char *get_nt_error_msg(uint32 nt_code);
/*The following definitions come from libsmb/passchange.c */
BOOL remote_password_change(const char *remote_machine, const char *user_name,
const char *old_passwd, const char *new_passwd,
char *err_str, size_t err_str_len);
/*The following definitions come from libsmb/pwd_cache.c */
void pwd_init(struct pwd_info *pwd);
void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key);
BOOL pwd_compare(struct pwd_info *pwd1, struct pwd_info *pwd2);
void pwd_read(struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt);
void pwd_set_nullpwd(struct pwd_info *pwd);
void pwd_set_cleartext(struct pwd_info *pwd, char *clr);
void pwd_get_cleartext(struct pwd_info *pwd, char *clr);
void pwd_set_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16]);
void pwd_get_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16]);
void pwd_make_lm_nt_16(struct pwd_info *pwd, char *clr);
void pwd_make_lm_nt_owf(struct pwd_info *pwd, uchar cryptkey[8]);
void pwd_get_lm_nt_owf(struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24]);
/*The following definitions come from lib/smbrun.c */
int smbrun(char *cmd,char *outfile,BOOL shared);
/*The following definitions come from libsmb/smbdes.c */
void E_P16(unsigned char *p14,unsigned char *p16);
void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24);
void D_P16(unsigned char *p14, unsigned char *in, unsigned char *out);
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 SamOEMhash( unsigned char *data, unsigned char *key, int val);
/*The following definitions come from libsmb/smbencrypt.c */
void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24);
void E_md4hash(uchar *passwd, uchar *p16);
void nt_lm_owf_gen(char *pwd, uchar nt_p16[16], uchar p16[16]);
void SMBOWFencrypt(uchar passwd[16], uchar *c8, uchar p24[24]);
void NTLMSSPOWFencrypt(uchar passwd[8], uchar *ntlmchalresp, uchar p24[24]);
void SMBNTencrypt(uchar *passwd, uchar *c8, uchar *p24);
BOOL make_oem_passwd_hash(char data[516], const char *passwd, uchar old_pw_hash[16], BOOL unicode);
/*The following definitions come from libsmb/smberr.c */
char *smb_errstr(char *inbuf);
/*The following definitions come from libsmb/unexpected.c */
void unexpected_packet(struct packet_struct *p);
void clear_unexpected(time_t t);
struct packet_struct *receive_unexpected(enum packet_type packet_type, int id,
char *mailslot_name);
/*The following definitions come from lib/snprintf.c */
@ -274,14 +476,29 @@ BOOL map_username(char *user);
struct passwd *Get_Pwnam(char *user,BOOL allow_change);
BOOL user_in_list(char *user,char *list);
/*The following definitions come from lib/util_array.c */
void free_void_array(uint32 num_entries, void **entries,
void(free_item)(void*));
void* add_copy_to_array(uint32 *len, void ***array, const void *item,
void*(item_dup)(const void*), BOOL alloc_anyway);
void* add_item_to_array(uint32 *len, void ***array, void *item);
void free_use_info_array(uint32 num_entries, struct use_info **entries);
struct use_info* add_use_info_to_array(uint32 *len, struct use_info ***array,
const struct use_info *name);
void free_char_array(uint32 num_entries, char **entries);
char* add_chars_to_array(uint32 *len, char ***array, const char *name);
void free_uint32_array(uint32 num_entries, uint32 **entries);
uint32* add_uint32s_to_array(uint32 *len, uint32 ***array, const uint32 *name);
void free_sid_array(uint32 num_entries, DOM_SID **entries);
DOM_SID* add_sid_to_array(uint32 *len, DOM_SID ***array, const DOM_SID *sid);
/*The following definitions come from lib/util.c */
char *tmpdir(void);
BOOL in_group(gid_t group, gid_t current_gid, int ngroups, gid_t *groups);
char *Atoic(char *p, int *n, char *c);
char *get_numlist(char *p, uint32 **num, int *count);
char *dns_to_netbios_name(char *dns_name);
int name_mangle( char *In, char *Out, char name_type );
BOOL file_exist(char *fname,SMB_STRUCT_STAT *sbuf);
int file_rename(char *from, char *to);
time_t file_modtime(char *fname);
@ -299,8 +516,6 @@ void make_dir_struct(char *buf,char *mask,char *fname,SMB_OFF_T size,int mode,ti
void close_low_fds(void);
int set_blocking(int fd, BOOL set);
SMB_OFF_T transfer_file(int infd,int outfd,SMB_OFF_T n,char *header,int headlen,int align);
int name_extract(char *buf,int ofs,char *name);
int name_len(char *s1);
void msleep(int t);
BOOL unix_do_match(char *str, char *regexp, BOOL case_sig);
BOOL mask_match(char *str, char *regexp, BOOL case_sig, BOOL trans2);
@ -352,23 +567,6 @@ char *myhostname(void);
char *lock_path(char *name);
char *parent_dirname(const char *path);
/*The following definitions come from lib/util_array.c */
void free_void_array(uint32 num_entries, void **entries,
void(free_item)(void*));
void* add_copy_to_array(uint32 *len, void ***array, const void *item,
void*(item_dup)(const void*), BOOL alloc_anyway);
void* add_item_to_array(uint32 *len, void ***array, void *item);
void free_use_info_array(uint32 num_entries, struct use_info **entries);
struct use_info* add_use_info_to_array(uint32 *len, struct use_info ***array,
const struct use_info *name);
void free_char_array(uint32 num_entries, char **entries);
char* add_chars_to_array(uint32 *len, char ***array, const char *name);
void free_uint32_array(uint32 num_entries, uint32 **entries);
uint32* add_uint32s_to_array(uint32 *len, uint32 ***array, const uint32 *name);
void free_sid_array(uint32 num_entries, DOM_SID **entries);
DOM_SID* add_sid_to_array(uint32 *len, DOM_SID ***array, const DOM_SID *sid);
/*The following definitions come from lib/util_file.c */
BOOL do_file_lock(int fd, int waitsecs, int type);
@ -558,204 +756,6 @@ void split_at_last_component_w(smb_ucs2_t *path, smb_ucs2_t *front, smb_ucs2_t s
smb_ucs2_t *octal_string_w(int i);
smb_ucs2_t *string_truncate_w(smb_ucs2_t *s, size_t length);
/*The following definitions come from libsmb/clientgen.c */
int cli_set_port(struct cli_state *cli, int port);
char *cli_errstr(struct cli_state *cli);
BOOL cli_api_pipe(struct cli_state *cli, char *pipe_name, int pipe_name_len,
uint16 *setup, uint32 setup_count, uint32 max_setup_count,
char *params, uint32 param_count, uint32 max_param_count,
char *data, uint32 data_count, uint32 max_data_count,
char **rparam, uint32 *rparam_count,
char **rdata, uint32 *rdata_count);
BOOL cli_api(struct cli_state *cli,
char *param, int prcnt, int mprcnt,
char *data, int drcnt, int mdrcnt,
char **rparam, int *rprcnt,
char **rdata, int *rdrcnt);
BOOL cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation);
int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, const char *));
BOOL cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
void (*fn)(const char *, uint32, const char *));
BOOL cli_session_setup(struct cli_state *cli,
char *user,
char *pass, int passlen,
char *ntpass, int ntpasslen,
char *workgroup);
BOOL cli_ulogoff(struct cli_state *cli);
BOOL cli_send_tconX(struct cli_state *cli,
char *share, char *dev, char *pass, int passlen);
BOOL cli_tdis(struct cli_state *cli);
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, enum brl_type lock_type);
BOOL cli_unlock(struct cli_state *cli, int fnum, uint32 offset, uint32 len);
size_t cli_read(struct cli_state *cli, int fnum, char *buf, off_t offset, size_t size);
ssize_t cli_write(struct cli_state *cli,
int fnum, uint16 write_mode,
char *buf, off_t offset, size_t size);
ssize_t cli_smbwrite(struct cli_state *cli,
int fnum, char *buf, off_t offset, size_t size1);
BOOL cli_getattrE(struct cli_state *cli, int fd,
uint16 *attr, size_t *size,
time_t *c_time, time_t *a_time, time_t *m_time);
BOOL cli_getatr(struct cli_state *cli, char *fname,
uint16 *attr, size_t *size, time_t *t);
BOOL cli_setatr(struct cli_state *cli, char *fname, uint16 attr, time_t t);
BOOL cli_qpathinfo(struct cli_state *cli, const char *fname,
time_t *c_time, time_t *a_time, time_t *m_time,
size_t *size, uint16 *mode);
BOOL cli_qpathinfo2(struct cli_state *cli, const char *fname,
time_t *c_time, time_t *a_time, time_t *m_time,
time_t *w_time, size_t *size, uint16 *mode,
SMB_INO_T *ino);
BOOL cli_qfileinfo(struct cli_state *cli, int fnum,
uint16 *mode, size_t *size,
time_t *c_time, time_t *a_time, time_t *m_time,
time_t *w_time, SMB_INO_T *ino);
int cli_list(struct cli_state *cli,const char *Mask,uint16 attribute,
void (*fn)(file_info *, const char *));
BOOL cli_oem_change_password(struct cli_state *cli, const char *user, const char *new_password,
const char *old_password);
BOOL cli_negprot(struct cli_state *cli);
BOOL cli_session_request(struct cli_state *cli,
struct nmb_name *calling, struct nmb_name *called);
BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip);
struct cli_state *cli_initialise(struct cli_state *cli);
void cli_shutdown(struct cli_state *cli);
int cli_error(struct cli_state *cli, uint8 *eclass, uint32 *num, uint32 *nt_rpc_error);
void cli_sockopt(struct cli_state *cli, char *options);
uint16 cli_setpid(struct cli_state *cli, uint16 pid);
BOOL cli_reestablish_connection(struct cli_state *cli);
BOOL cli_establish_connection(struct cli_state *cli,
char *dest_host, struct in_addr *dest_ip,
struct nmb_name *calling, struct nmb_name *called,
char *service, char *service_type,
BOOL do_shutdown, BOOL do_tcon);
int cli_printjob_del(struct cli_state *cli, int job);
int cli_print_queue(struct cli_state *cli,
void (*fn)(struct print_job_info *));
BOOL cli_chkpath(struct cli_state *cli, char *path);
BOOL cli_message_start(struct cli_state *cli, char *host, char *username,
int *grp);
BOOL cli_message_text(struct cli_state *cli, char *msg, int len, int grp);
BOOL cli_message_end(struct cli_state *cli, int grp);
BOOL cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail);
BOOL attempt_netbios_session_request(struct cli_state *cli, char *srchost, char *desthost,
struct in_addr *pdest_ip);
/*The following definitions come from libsmb/credentials.c */
char *credstr(uchar *cred);
void cred_session_key(DOM_CHAL *clnt_chal, DOM_CHAL *srv_chal, char *pass,
uchar session_key[8]);
void cred_create(uchar session_key[8], DOM_CHAL *stor_cred, UTIME timestamp,
DOM_CHAL *cred);
int cred_assert(DOM_CHAL *cred, uchar session_key[8], DOM_CHAL *stored_cred,
UTIME timestamp);
BOOL clnt_deal_with_creds(uchar sess_key[8],
DOM_CRED *sto_clnt_cred, DOM_CRED *rcv_srv_cred);
BOOL deal_with_creds(uchar sess_key[8],
DOM_CRED *sto_clnt_cred,
DOM_CRED *rcv_clnt_cred, DOM_CRED *rtn_srv_cred);
/*The following definitions come from libsmb/namequery.c */
BOOL name_status(int fd,char *name,int name_type,BOOL recurse,
struct in_addr to_ip,char *master,char *rname);
struct in_addr *name_query(int fd,const char *name,int name_type,
BOOL bcast,BOOL recurse,
struct in_addr to_ip, int *count);
FILE *startlmhosts(char *fname);
BOOL getlmhostsent( FILE *fp, pstring name, int *name_type, struct in_addr *ipaddr);
void endlmhosts(FILE *fp);
BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type);
BOOL find_master_ip(char *group, struct in_addr *master_ip);
BOOL lookup_pdc_name(const char *srcname, const char *domain, struct in_addr *pdc_ip, char *ret_name);
BOOL get_dc_list(char *group, struct in_addr **ip_list, int *count);
/*The following definitions come from libsmb/nmblib.c */
void debug_nmb_packet(struct packet_struct *p);
char *nmb_namestr(struct nmb_name *n);
struct packet_struct *copy_packet(struct packet_struct *packet);
void free_packet(struct packet_struct *packet);
struct packet_struct *parse_packet(char *buf,int length,
enum packet_type packet_type);
struct packet_struct *read_packet(int fd,enum packet_type packet_type);
void make_nmb_name( struct nmb_name *n, const char *name, int type);
BOOL nmb_name_equal(struct nmb_name *n1, struct nmb_name *n2);
int build_packet(char *buf, struct packet_struct *p);
BOOL send_packet(struct packet_struct *p);
struct packet_struct *receive_packet(int fd,enum packet_type type,int t);
struct packet_struct *receive_nmb_packet(int fd, int t, int trn_id);
struct packet_struct *receive_dgram_packet(int fd, int t, char *mailslot_name);
BOOL match_mailslot_name(struct packet_struct *p, char *mailslot_name);
void sort_query_replies(char *data, int n, struct in_addr ip);
/*The following definitions come from libsmb/nterr.c */
char *get_nt_error_msg(uint32 nt_code);
/*The following definitions come from libsmb/passchange.c */
BOOL remote_password_change(const char *remote_machine, const char *user_name,
const char *old_passwd, const char *new_passwd,
char *err_str, size_t err_str_len);
/*The following definitions come from libsmb/pwd_cache.c */
void pwd_init(struct pwd_info *pwd);
void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key);
BOOL pwd_compare(struct pwd_info *pwd1, struct pwd_info *pwd2);
void pwd_read(struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt);
void pwd_set_nullpwd(struct pwd_info *pwd);
void pwd_set_cleartext(struct pwd_info *pwd, char *clr);
void pwd_get_cleartext(struct pwd_info *pwd, char *clr);
void pwd_set_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16]);
void pwd_get_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16]);
void pwd_make_lm_nt_16(struct pwd_info *pwd, char *clr);
void pwd_make_lm_nt_owf(struct pwd_info *pwd, uchar cryptkey[8]);
void pwd_get_lm_nt_owf(struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24]);
/*The following definitions come from libsmb/smbdes.c */
void E_P16(unsigned char *p14,unsigned char *p16);
void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24);
void D_P16(unsigned char *p14, unsigned char *in, unsigned char *out);
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 SamOEMhash( unsigned char *data, unsigned char *key, int val);
/*The following definitions come from libsmb/smbencrypt.c */
void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24);
void E_md4hash(uchar *passwd, uchar *p16);
void nt_lm_owf_gen(char *pwd, uchar nt_p16[16], uchar p16[16]);
void SMBOWFencrypt(uchar passwd[16], uchar *c8, uchar p24[24]);
void NTLMSSPOWFencrypt(uchar passwd[8], uchar *ntlmchalresp, uchar p24[24]);
void SMBNTencrypt(uchar *passwd, uchar *c8, uchar *p24);
BOOL make_oem_passwd_hash(char data[516], const char *passwd, uchar old_pw_hash[16], BOOL unicode);
/*The following definitions come from libsmb/smberr.c */
char *smb_errstr(char *inbuf);
/*The following definitions come from libsmb/unexpected.c */
void unexpected_packet(struct packet_struct *p);
void clear_unexpected(time_t t);
struct packet_struct *receive_unexpected(enum packet_type packet_type, int id,
char *mailslot_name);
/*The following definitions come from locking/brlock.c */
void brl_init(int read_only);
@ -838,10 +838,6 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question,
struct name_record **n);
void kill_async_dns_child(void);
/*The following definitions come from nmbd/nmbd.c */
BOOL reload_services(BOOL test);
/*The following definitions come from nmbd/nmbd_become_dmb.c */
void add_domain_names(time_t t);
@ -872,6 +868,9 @@ void announce_and_sync_with_domain_master_browser( struct subnet_record *subrec,
void collect_all_workgroup_names_from_wins_server(time_t t);
void sync_all_dmbs(time_t t);
/*The following definitions come from nmbd/nmbd.c */
/*The following definitions come from nmbd/nmbd_elections.c */
void check_master_browser_exists(time_t t);
@ -1550,11 +1549,6 @@ void pcap_printer_fn(void (*fn)(char *, char *));
void cups_printer_fn(void (*fn)(char *, char *));
int cups_printername_ok(char *name);
/*The following definitions come from printing/print_svid.c */
void sysv_printer_fn(void (*fn)(char *, char *));
int sysv_printername_ok(char *name);
/*The following definitions come from printing/printing.c */
void lpq_reset(int snum);
@ -1569,6 +1563,11 @@ void printjob_decode(int jobid, int *snum, int *job);
void status_printqueue(connection_struct *conn,int snum,int status);
void load_printers(void);
/*The following definitions come from printing/print_svid.c */
void sysv_printer_fn(void (*fn)(char *, char *));
int sysv_printername_ok(char *name);
/*The following definitions come from profile/profile.c */
BOOL profile_setup(BOOL rdonly);
@ -1734,6 +1733,109 @@ BOOL do_wks_query_info(struct cli_state *cli,
char *server_name, uint32 switch_value,
WKS_INFO_100 *wks100);
/*The following definitions come from rpcclient/cmd_lsarpc.c */
void cmd_lsa_query_info(struct client_info *info);
void cmd_lsa_lookup_sids(struct client_info *info);
/*The following definitions come from rpcclient/cmd_netlogon.c */
void cmd_netlogon_login_test(struct client_info *info);
/*The following definitions come from rpcclient/cmd_reg.c */
void cmd_reg_enum(struct client_info *info);
void cmd_reg_query_key(struct client_info *info);
void cmd_reg_create_val(struct client_info *info);
void cmd_reg_delete_val(struct client_info *info);
void cmd_reg_delete_key(struct client_info *info);
void cmd_reg_create_key(struct client_info *info);
void cmd_reg_test_key_sec(struct client_info *info);
void cmd_reg_get_key_sec(struct client_info *info);
/*The following definitions come from rpcclient/cmd_samr.c */
void cmd_sam_ntchange_pwd(struct client_info *info);
void cmd_sam_test(struct client_info *info);
void cmd_sam_enum_users(struct client_info *info);
void cmd_sam_query_user(struct client_info *info);
void cmd_sam_query_groups(struct client_info *info);
void cmd_sam_enum_aliases(struct client_info *info);
/*The following definitions come from rpcclient/cmd_srvsvc.c */
void cmd_srv_query_info(struct client_info *info);
void cmd_srv_enum_conn(struct client_info *info);
void cmd_srv_enum_shares(struct client_info *info);
void cmd_srv_enum_sess(struct client_info *info);
void cmd_srv_enum_files(struct client_info *info);
/*The following definitions come from rpcclient/cmd_wkssvc.c */
void cmd_wks_query_info(struct client_info *info);
/*The following definitions come from rpcclient/display.c */
char *get_file_mode_str(uint32 share_mode);
char *get_file_oplock_str(uint32 op_type);
char *get_share_type_str(uint32 type);
char *get_server_type_str(uint32 type);
void display_srv_info_101(FILE *out_hnd, enum action_type action,
SRV_INFO_101 *sv101);
void display_srv_info_102(FILE *out_hnd, enum action_type action,SRV_INFO_102 *sv102);
void display_srv_info_ctr(FILE *out_hnd, enum action_type action,SRV_INFO_CTR *ctr);
void display_conn_info_0(FILE *out_hnd, enum action_type action,
CONN_INFO_0 *info0);
void display_conn_info_1(FILE *out_hnd, enum action_type action,
CONN_INFO_1 *info1, CONN_INFO_1_STR *str1);
void display_srv_conn_info_0_ctr(FILE *out_hnd, enum action_type action,
SRV_CONN_INFO_0 *ctr);
void display_srv_conn_info_1_ctr(FILE *out_hnd, enum action_type action,
SRV_CONN_INFO_1 *ctr);
void display_srv_conn_info_ctr(FILE *out_hnd, enum action_type action,
SRV_CONN_INFO_CTR *ctr);
void display_share_info_1(FILE *out_hnd, enum action_type action,
SRV_SHARE_INFO_1 *info1);
void display_share_info_2(FILE *out_hnd, enum action_type action,
SRV_SHARE_INFO_2 *info2);
void display_srv_share_info_ctr(FILE *out_hnd, enum action_type action,
SRV_SHARE_INFO_CTR *ctr);
void display_file_info_3(FILE *out_hnd, enum action_type action,
FILE_INFO_3 *info3, FILE_INFO_3_STR *str3);
void display_srv_file_info_3_ctr(FILE *out_hnd, enum action_type action,
SRV_FILE_INFO_3 *ctr);
void display_srv_file_info_ctr(FILE *out_hnd, enum action_type action,
SRV_FILE_INFO_CTR *ctr);
void display_server(FILE *out_hnd, enum action_type action,
char *sname, uint32 type, char *comment);
void display_share(FILE *out_hnd, enum action_type action,
char *sname, uint32 type, char *comment);
void display_share2(FILE *out_hnd, enum action_type action,
char *sname, uint32 type, char *comment,
uint32 perms, uint32 max_uses, uint32 num_uses,
char *path, char *passwd);
void display_name(FILE *out_hnd, enum action_type action,
char *sname);
void display_group_rid_info(FILE *out_hnd, enum action_type action,
uint32 num_gids, DOM_GID *gid);
void display_alias_name_info(FILE *out_hnd, enum action_type action,
uint32 num_aliases, fstring *alias_name, uint32 *num_als_usrs);
void display_sam_user_info_21(FILE *out_hnd, enum action_type action, SAM_USER_INFO_21 *usr);
char *get_sec_mask_str(uint32 type);
void display_sec_access(FILE *out_hnd, enum action_type action, SEC_ACCESS *info);
void display_sec_ace(FILE *out_hnd, enum action_type action, SEC_ACE *ace);
void display_sec_acl(FILE *out_hnd, enum action_type action, SEC_ACL *sec_acl);
void display_sec_desc(FILE *out_hnd, enum action_type action, SEC_DESC *sec);
char *get_reg_val_type_str(uint32 type);
void display_reg_value_info(FILE *out_hnd, enum action_type action,
char *val_name, uint32 val_type, BUFFER2 *value);
void display_reg_key_info(FILE *out_hnd, enum action_type action,
char *key_name, time_t key_mod_time);
/*The following definitions come from rpcclient/rpcclient.c */
void rpcclient_init(void);
/*The following definitions come from rpc_parse/parse_creds.c */
BOOL make_creds_unix(CREDS_UNIX *r_u, const char* user_name,
@ -2752,109 +2854,6 @@ uint32 lookup_user_rid(char *user_name, uint32 *rid);
BOOL api_wkssvc_rpc(pipes_struct *p, prs_struct *data);
/*The following definitions come from rpcclient/cmd_lsarpc.c */
void cmd_lsa_query_info(struct client_info *info);
void cmd_lsa_lookup_sids(struct client_info *info);
/*The following definitions come from rpcclient/cmd_netlogon.c */
void cmd_netlogon_login_test(struct client_info *info);
/*The following definitions come from rpcclient/cmd_reg.c */
void cmd_reg_enum(struct client_info *info);
void cmd_reg_query_key(struct client_info *info);
void cmd_reg_create_val(struct client_info *info);
void cmd_reg_delete_val(struct client_info *info);
void cmd_reg_delete_key(struct client_info *info);
void cmd_reg_create_key(struct client_info *info);
void cmd_reg_test_key_sec(struct client_info *info);
void cmd_reg_get_key_sec(struct client_info *info);
/*The following definitions come from rpcclient/cmd_samr.c */
void cmd_sam_ntchange_pwd(struct client_info *info);
void cmd_sam_test(struct client_info *info);
void cmd_sam_enum_users(struct client_info *info);
void cmd_sam_query_user(struct client_info *info);
void cmd_sam_query_groups(struct client_info *info);
void cmd_sam_enum_aliases(struct client_info *info);
/*The following definitions come from rpcclient/cmd_srvsvc.c */
void cmd_srv_query_info(struct client_info *info);
void cmd_srv_enum_conn(struct client_info *info);
void cmd_srv_enum_shares(struct client_info *info);
void cmd_srv_enum_sess(struct client_info *info);
void cmd_srv_enum_files(struct client_info *info);
/*The following definitions come from rpcclient/cmd_wkssvc.c */
void cmd_wks_query_info(struct client_info *info);
/*The following definitions come from rpcclient/display.c */
char *get_file_mode_str(uint32 share_mode);
char *get_file_oplock_str(uint32 op_type);
char *get_share_type_str(uint32 type);
char *get_server_type_str(uint32 type);
void display_srv_info_101(FILE *out_hnd, enum action_type action,
SRV_INFO_101 *sv101);
void display_srv_info_102(FILE *out_hnd, enum action_type action,SRV_INFO_102 *sv102);
void display_srv_info_ctr(FILE *out_hnd, enum action_type action,SRV_INFO_CTR *ctr);
void display_conn_info_0(FILE *out_hnd, enum action_type action,
CONN_INFO_0 *info0);
void display_conn_info_1(FILE *out_hnd, enum action_type action,
CONN_INFO_1 *info1, CONN_INFO_1_STR *str1);
void display_srv_conn_info_0_ctr(FILE *out_hnd, enum action_type action,
SRV_CONN_INFO_0 *ctr);
void display_srv_conn_info_1_ctr(FILE *out_hnd, enum action_type action,
SRV_CONN_INFO_1 *ctr);
void display_srv_conn_info_ctr(FILE *out_hnd, enum action_type action,
SRV_CONN_INFO_CTR *ctr);
void display_share_info_1(FILE *out_hnd, enum action_type action,
SRV_SHARE_INFO_1 *info1);
void display_share_info_2(FILE *out_hnd, enum action_type action,
SRV_SHARE_INFO_2 *info2);
void display_srv_share_info_ctr(FILE *out_hnd, enum action_type action,
SRV_SHARE_INFO_CTR *ctr);
void display_file_info_3(FILE *out_hnd, enum action_type action,
FILE_INFO_3 *info3, FILE_INFO_3_STR *str3);
void display_srv_file_info_3_ctr(FILE *out_hnd, enum action_type action,
SRV_FILE_INFO_3 *ctr);
void display_srv_file_info_ctr(FILE *out_hnd, enum action_type action,
SRV_FILE_INFO_CTR *ctr);
void display_server(FILE *out_hnd, enum action_type action,
char *sname, uint32 type, char *comment);
void display_share(FILE *out_hnd, enum action_type action,
char *sname, uint32 type, char *comment);
void display_share2(FILE *out_hnd, enum action_type action,
char *sname, uint32 type, char *comment,
uint32 perms, uint32 max_uses, uint32 num_uses,
char *path, char *passwd);
void display_name(FILE *out_hnd, enum action_type action,
char *sname);
void display_group_rid_info(FILE *out_hnd, enum action_type action,
uint32 num_gids, DOM_GID *gid);
void display_alias_name_info(FILE *out_hnd, enum action_type action,
uint32 num_aliases, fstring *alias_name, uint32 *num_als_usrs);
void display_sam_user_info_21(FILE *out_hnd, enum action_type action, SAM_USER_INFO_21 *usr);
char *get_sec_mask_str(uint32 type);
void display_sec_access(FILE *out_hnd, enum action_type action, SEC_ACCESS *info);
void display_sec_ace(FILE *out_hnd, enum action_type action, SEC_ACE *ace);
void display_sec_acl(FILE *out_hnd, enum action_type action, SEC_ACL *sec_acl);
void display_sec_desc(FILE *out_hnd, enum action_type action, SEC_DESC *sec);
char *get_reg_val_type_str(uint32 type);
void display_reg_value_info(FILE *out_hnd, enum action_type action,
char *val_name, uint32 val_type, BUFFER2 *value);
void display_reg_key_info(FILE *out_hnd, enum action_type action,
char *key_name, time_t key_mod_time);
/*The following definitions come from rpcclient/rpcclient.c */
void rpcclient_init(void);
/*The following definitions come from smbd/blocking.c */
BOOL push_blocking_lock_request( char *inbuf, int length, int lock_timeout, int lock_num);
@ -3242,6 +3241,19 @@ BOOL unbecome_authenticated_pipe_user(pipes_struct *p);
void become_root(BOOL save_dir) ;
void unbecome_root(BOOL restore_dir);
/*The following definitions come from smbd/vfs.c */
int vfs_init_default(connection_struct *conn);
BOOL vfs_init_custom(connection_struct *conn);
BOOL vfs_directory_exist(connection_struct *conn, char *dname,
SMB_STRUCT_STAT *st);
BOOL vfs_file_exist(connection_struct *conn,char *fname,SMB_STRUCT_STAT *sbuf);
ssize_t vfs_write_data(files_struct *fsp,char *buffer,size_t N);
SMB_OFF_T vfs_transfer_file(int in_fd, files_struct *in_fsp,
int out_fd, files_struct *out_fsp,
SMB_OFF_T n, char *header, int headlen, int align);
char *vfs_readdirname(connection_struct *conn, void *p);
/*The following definitions come from smbd/vfs-wrap.c */
int vfswrap_dummy_connect(struct vfs_connection_struct *conn, char *service,
@ -3269,19 +3281,6 @@ int vfswrap_unlink(char *path);
int vfswrap_chmod(char *path, mode_t mode);
int vfswrap_utime(char *path, struct utimbuf *times);
/*The following definitions come from smbd/vfs.c */
int vfs_init_default(connection_struct *conn);
BOOL vfs_init_custom(connection_struct *conn);
BOOL vfs_directory_exist(connection_struct *conn, char *dname,
SMB_STRUCT_STAT *st);
BOOL vfs_file_exist(connection_struct *conn,char *fname,SMB_STRUCT_STAT *sbuf);
ssize_t vfs_write_data(files_struct *fsp,char *buffer,size_t N);
SMB_OFF_T vfs_transfer_file(int in_fd, files_struct *in_fsp,
int out_fd, files_struct *out_fsp,
SMB_OFF_T n, char *header, int headlen, int align);
char *vfs_readdirname(connection_struct *conn, void *p);
/*The following definitions come from smbwrapper/realcalls.c */
int real_utime(const char *name, struct utimbuf *buf);

View File

@ -194,144 +194,6 @@ char *get_numlist(char *p, uint32 **num, int *count)
return p;
}
#define TRUNCATE_NETBIOS_NAME 1
/*******************************************************************
convert, possibly using a stupid microsoft-ism which has destroyed
the transport independence of netbios (for CIFS vendors that usually
use the Win95-type methods, not for NT to NT communication, which uses
DCE/RPC and therefore full-length unicode strings...) a dns name into
a netbios name.
the netbios name (NOT necessarily null-terminated) is truncated to 15
characters.
******************************************************************/
char *dns_to_netbios_name(char *dns_name)
{
static char netbios_name[16];
int i;
StrnCpy(netbios_name, dns_name, 15);
netbios_name[15] = 0;
#ifdef TRUNCATE_NETBIOS_NAME
/* ok. this is because of a stupid microsoft-ism. if the called host
name contains a '.', microsoft clients expect you to truncate the
netbios name up to and including the '.' this even applies, by
mistake, to workgroup (domain) names, which is _really_ daft.
*/
for (i = 15; i >= 0; i--)
{
if (netbios_name[i] == '.')
{
netbios_name[i] = 0;
break;
}
}
#endif /* TRUNCATE_NETBIOS_NAME */
return netbios_name;
}
/****************************************************************************
interpret the weird netbios "name". Return the name type
****************************************************************************/
static int name_interpret(char *in,char *out)
{
int ret;
int len = (*in++) / 2;
*out=0;
if (len > 30 || len<1) return(0);
while (len--)
{
if (in[0] < 'A' || in[0] > 'P' || in[1] < 'A' || in[1] > 'P') {
*out = 0;
return(0);
}
*out = ((in[0]-'A')<<4) + (in[1]-'A');
in += 2;
out++;
}
*out = 0;
ret = out[-1];
#ifdef NETBIOS_SCOPE
/* Handle any scope names */
while(*in)
{
*out++ = '.'; /* Scope names are separated by periods */
len = *(unsigned char *)in++;
StrnCpy(out, in, len);
out += len;
*out=0;
in += len;
}
#endif
return(ret);
}
/****************************************************************************
mangle a name into netbios format
Note: <Out> must be (33 + strlen(scope) + 2) bytes long, at minimum.
****************************************************************************/
int name_mangle( char *In, char *Out, char name_type )
{
int i;
int c;
int len;
char buf[20];
char *p = Out;
extern pstring global_scope;
/* Safely copy the input string, In, into buf[]. */
(void)memset( buf, 0, 20 );
if (strcmp(In,"*") == 0)
buf[0] = '*';
else
(void)slprintf( buf, sizeof(buf) - 1, "%-15.15s%c", In, name_type );
/* Place the length of the first field into the output buffer. */
p[0] = 32;
p++;
/* Now convert the name to the rfc1001/1002 format. */
for( i = 0; i < 16; i++ )
{
c = toupper( buf[i] );
p[i*2] = ( (c >> 4) & 0x000F ) + 'A';
p[(i*2)+1] = (c & 0x000F) + 'A';
}
p += 32;
p[0] = '\0';
/* Add the scope string. */
for( i = 0, len = 0; NULL != global_scope; i++, len++ )
{
switch( global_scope[i] )
{
case '\0':
p[0] = len;
if( len > 0 )
p[len+1] = 0;
return( name_len(Out) );
case '.':
p[0] = len;
p += (len + 1);
len = -1;
break;
default:
p[len+1] = global_scope[i];
break;
}
}
return( name_len(Out) );
} /* name_mangle */
/*******************************************************************
check if a file exists - call vfs_file_exist for samba files
@ -939,59 +801,6 @@ SMB_OFF_T transfer_file(int infd,int outfd,SMB_OFF_T n,char *header,int headlen,
}
/****************************************************************************
find a pointer to a netbios name
****************************************************************************/
static char *name_ptr(char *buf,int ofs)
{
unsigned char c = *(unsigned char *)(buf+ofs);
if ((c & 0xC0) == 0xC0)
{
uint16 l = RSVAL(buf, ofs) & 0x3FFF;
DEBUG(5,("name ptr to pos %d from %d is %s\n",l,ofs,buf+l));
return(buf + l);
}
else
return(buf+ofs);
}
/****************************************************************************
extract a netbios name from a buf
****************************************************************************/
int name_extract(char *buf,int ofs,char *name)
{
char *p = name_ptr(buf,ofs);
int d = PTR_DIFF(p,buf+ofs);
pstrcpy(name,"");
if (d < -50 || d > 50) return(0);
return(name_interpret(p,name));
}
/****************************************************************************
return the total storage length of a mangled name
****************************************************************************/
int name_len(char *s1)
{
/* NOTE: this argument _must_ be unsigned */
unsigned char *s = (unsigned char *)s1;
int len;
/* If the two high bits of the byte are set, return 2. */
if (0xC0 == (*s & 0xC0))
return(2);
/* Add up the length bytes. */
for (len = 1; (*s); s += (*s) + 1) {
len += *s + 1;
SMB_ASSERT(len < 80);
}
return(len);
} /* name_len */
/*******************************************************************
sleep for a specified number of milliseconds
********************************************************************/

View File

@ -80,7 +80,7 @@ static void debug_nmb_res_rec(struct res_rec *res, char *hdr)
for (j = 0; j < 16; j++)
{
unsigned char x = res->rdata[i+j];
uchar x = res->rdata[i+j];
if (x < 32 || x > 127) x = '.';
if (i+j >= res->rdlength) break;
@ -92,7 +92,7 @@ static void debug_nmb_res_rec(struct res_rec *res, char *hdr)
for (j = 0; j < 16; j++)
{
if (i+j >= res->rdlength) break;
DEBUGADD(4, ("%02X", (unsigned char)res->rdata[i+j]));
DEBUGADD(4, ("%02X", (uchar)res->rdata[i+j]));
}
DEBUGADD(4, ("\n"));
@ -153,7 +153,7 @@ void debug_nmb_packet(struct packet_struct *p)
/*******************************************************************
handle "compressed" name pointers
******************************************************************/
static BOOL handle_name_ptrs(unsigned char *ubuf,int *offset,int length,
static BOOL handle_name_ptrs(uchar *ubuf,int *offset,int length,
BOOL *got_pointer,int *ret)
{
int loop_count=0;
@ -176,7 +176,7 @@ static BOOL handle_name_ptrs(unsigned char *ubuf,int *offset,int length,
static int parse_nmb_name(char *inbuf,int offset,int length, struct nmb_name *name)
{
int m,n=0;
unsigned char *ubuf = (unsigned char *)inbuf;
uchar *ubuf = (uchar *)inbuf;
int ret = 0;
BOOL got_pointer=False;
int loop_count=0;
@ -202,7 +202,7 @@ static int parse_nmb_name(char *inbuf,int offset,int length, struct nmb_name *na
ret += m + 2;
offset++;
while (m > 0) {
unsigned char c1,c2;
uchar c1,c2;
c1 = ubuf[offset++]-'A';
c2 = ubuf[offset++]-'A';
if ((c1 & 0xF0) || (c2 & 0xF0) || (n > sizeof(name->name)-1))
@ -215,7 +215,7 @@ static int parse_nmb_name(char *inbuf,int offset,int length, struct nmb_name *na
if (n==16) {
/* parse out the name type,
its always in the 16th byte of the name */
name->name_type = ((unsigned char)name->name[15]) & 0xff;
name->name_type = ((uchar)name->name[15]) & 0xff;
/* remove trailing spaces */
name->name[15] = 0;
@ -393,7 +393,7 @@ static int put_res_rec(char *buf,int offset,struct res_rec *recs,int count)
/*******************************************************************
put a compressed name pointer record into a packet
******************************************************************/
static int put_compressed_name_ptr(unsigned char *buf,int offset,struct res_rec *rec,int ptr_offset)
static int put_compressed_name_ptr(uchar *buf,int offset,struct res_rec *rec,int ptr_offset)
{
int ret=0;
buf[offset] = (0xC0 | ((ptr_offset >> 8) & 0xFF));
@ -784,7 +784,7 @@ static BOOL send_udp(int fd,char *buf,int len,struct in_addr ip,int port)
static int build_dgram(char *buf,struct packet_struct *p)
{
struct dgram_packet *dgram = &p->packet.dgram;
unsigned char *ubuf = (unsigned char *)buf;
uchar *ubuf = (uchar *)buf;
int offset=0;
/* put in the header */
@ -852,7 +852,7 @@ BOOL nmb_name_equal(struct nmb_name *n1, struct nmb_name *n2)
static int build_nmb(char *buf,struct packet_struct *p)
{
struct nmb_packet *nmb = &p->packet.nmb;
unsigned char *ubuf = (unsigned char *)buf;
uchar *ubuf = (uchar *)buf;
int offset=0;
/* put in the header */
@ -1082,3 +1082,197 @@ void sort_query_replies(char *data, int n, struct in_addr ip)
qsort(data, n, 6, QSORT_CAST name_query_comp);
}
#define TRUNCATE_NETBIOS_NAME 1
/*******************************************************************
convert, possibly using a stupid microsoft-ism which has destroyed
the transport independence of netbios (for CIFS vendors that usually
use the Win95-type methods, not for NT to NT communication, which uses
DCE/RPC and therefore full-length unicode strings...) a dns name into
a netbios name.
the netbios name (NOT necessarily null-terminated) is truncated to 15
characters.
******************************************************************/
char *dns_to_netbios_name(char *dns_name)
{
static char netbios_name[16];
int i;
StrnCpy(netbios_name, dns_name, 15);
netbios_name[15] = 0;
#ifdef TRUNCATE_NETBIOS_NAME
/* ok. this is because of a stupid microsoft-ism. if the called host
name contains a '.', microsoft clients expect you to truncate the
netbios name up to and including the '.' this even applies, by
mistake, to workgroup (domain) names, which is _really_ daft.
*/
for (i = 15; i >= 0; i--)
{
if (netbios_name[i] == '.')
{
netbios_name[i] = 0;
break;
}
}
#endif /* TRUNCATE_NETBIOS_NAME */
return netbios_name;
}
/****************************************************************************
interpret the weird netbios "name". Return the name type
****************************************************************************/
static int name_interpret(char *in,char *out)
{
int ret;
int len = (*in++) / 2;
*out=0;
if (len > 30 || len<1) return(0);
while (len--)
{
if (in[0] < 'A' || in[0] > 'P' || in[1] < 'A' || in[1] > 'P') {
*out = 0;
return(0);
}
*out = ((in[0]-'A')<<4) + (in[1]-'A');
in += 2;
out++;
}
*out = 0;
ret = out[-1];
#ifdef NETBIOS_SCOPE
/* Handle any scope names */
while(*in)
{
*out++ = '.'; /* Scope names are separated by periods */
len = *(uchar *)in++;
StrnCpy(out, in, len);
out += len;
*out=0;
in += len;
}
#endif
return(ret);
}
/****************************************************************************
mangle a name into netbios format
Note: <Out> must be (33 + strlen(scope) + 2) bytes long, at minimum.
****************************************************************************/
int name_mangle( char *In, char *Out, char name_type )
{
int i;
int c;
int len;
char buf[20];
char *p = Out;
extern pstring global_scope;
/* Safely copy the input string, In, into buf[]. */
(void)memset( buf, 0, 20 );
if (strcmp(In,"*") == 0)
buf[0] = '*';
else
(void)slprintf( buf, sizeof(buf) - 1, "%-15.15s%c", In, name_type );
/* Place the length of the first field into the output buffer. */
p[0] = 32;
p++;
/* Now convert the name to the rfc1001/1002 format. */
for( i = 0; i < 16; i++ )
{
c = toupper( buf[i] );
p[i*2] = ( (c >> 4) & 0x000F ) + 'A';
p[(i*2)+1] = (c & 0x000F) + 'A';
}
p += 32;
p[0] = '\0';
/* Add the scope string. */
for( i = 0, len = 0; NULL != global_scope; i++, len++ )
{
switch( global_scope[i] )
{
case '\0':
p[0] = len;
if( len > 0 )
p[len+1] = 0;
return( name_len(Out) );
case '.':
p[0] = len;
p += (len + 1);
len = -1;
break;
default:
p[len+1] = global_scope[i];
break;
}
}
return( name_len(Out) );
} /* name_mangle */
/****************************************************************************
find a pointer to a netbios name
****************************************************************************/
static char *name_ptr(char *buf,int ofs)
{
uchar c = *(uchar *)(buf+ofs);
if ((c & 0xC0) == 0xC0)
{
uint16 l = RSVAL(buf, ofs) & 0x3FFF;
DEBUG(5,("name ptr to pos %d from %d is %s\n",l,ofs,buf+l));
return(buf + l);
}
else
return(buf+ofs);
}
/****************************************************************************
extract a netbios name from a buf
****************************************************************************/
int name_extract(char *buf,int ofs,char *name)
{
char *p = name_ptr(buf,ofs);
int d = PTR_DIFF(p,buf+ofs);
pstrcpy(name,"");
if (d < -50 || d > 50) return(0);
return(name_interpret(p,name));
}
/****************************************************************************
return the total storage length of a mangled name
****************************************************************************/
int name_len(char *s1)
{
/* NOTE: this argument _must_ be unsigned */
uchar *s = (uchar *)s1;
int len;
/* If the two high bits of the byte are set, return 2. */
if (0xC0 == (*s & 0xC0))
return(2);
/* Add up the length bytes. */
for (len = 1; (*s); s += (*s) + 1) {
len += *s + 1;
SMB_ASSERT(len < 80);
}
return(len);
} /* name_len */