2 * Copyright (c) 2000-2001 Boris Popov
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * from: Id: smb_lib.h,v 1.24 2001/12/20 15:19:43 bp Exp
34 #ifndef _NETSMB_SMB_LIB_H_
35 #define _NETSMB_SMB_LIB_H_
37 #include <netsmb/smb.h>
38 #include <netsmb/smb_dev.h>
41 #define SMB_CFG_FILE "/etc/nsmb.conf"
44 #define STDPARAM_ARGS 'A':case 'B':case 'C':case 'E':case 'I': \
46 case 'N':case 'U':case 'R':case 'S':case 'T': \
47 case 'W':case 'O':case 'P'
49 #define STDPARAM_OPT "A:BCE:I:L:M:NO:P:U:R:S:T:W:"
52 * bits to indicate the source of error
54 #define SMB_ERRTYPE_MASK 0xf0000
55 #define SMB_SYS_ERROR 0x00000
56 #define SMB_RAP_ERROR 0x10000
57 #define SMB_NB_ERROR 0x20000
60 #define min(a,b) (((a)<(b)) ? (a) : (b))
63 #define getb(buf,ofs) (((const u_int8_t *)(buf))[ofs])
64 #define setb(buf,ofs,val) (((u_int8_t*)(buf))[ofs])=val
65 #define getbw(buf,ofs) ((u_int16_t)(getb(buf,ofs)))
66 #define getw(buf,ofs) (*((u_int16_t*)(&((u_int8_t*)(buf))[ofs])))
67 #define getdw(buf,ofs) (*((u_int32_t*)(&((u_int8_t*)(buf))[ofs])))
69 #if (BYTE_ORDER == LITTLE_ENDIAN)
71 #define getwle(buf,ofs) (*((u_int16_t*)(&((u_int8_t*)(buf))[ofs])))
72 #define getdle(buf,ofs) (*((u_int32_t*)(&((u_int8_t*)(buf))[ofs])))
73 #define getwbe(buf,ofs) (ntohs(getwle(buf,ofs)))
74 #define getdbe(buf,ofs) (ntohl(getdle(buf,ofs)))
76 #define setwle(buf,ofs,val) getwle(buf,ofs)=val
77 #define setwbe(buf,ofs,val) getwle(buf,ofs)=htons(val)
78 #define setdle(buf,ofs,val) getdle(buf,ofs)=val
79 #define setdbe(buf,ofs,val) getdle(buf,ofs)=htonl(val)
81 #else /* (BYTE_ORDER == LITTLE_ENDIAN) */
83 #define getwbe(buf,ofs) (*((u_int16_t*)(&((u_int8_t*)(buf))[ofs])))
84 #define getdbe(buf,ofs) (*((u_int32_t*)(&((u_int8_t*)(buf))[ofs])))
85 #define getwle(buf,ofs) (bswap16(getwbe(buf,ofs)))
86 #define getdle(buf,ofs) (bswap32(getdbe(buf,ofs)))
88 #define setwbe(buf,ofs,val) getwbe(buf,ofs)=val
89 #define setwle(buf,ofs,val) getwbe(buf,ofs)=bswap16(val)
90 #define setdbe(buf,ofs,val) getdbe(buf,ofs)=val
91 #define setdle(buf,ofs,val) getdbe(buf,ofs)=bswap32(val)
93 #endif /* (BYTE_ORDER == LITTLE_ENDIAN) */
96 * SMB work context. Used to store all values which is necessary
97 * to establish connection to an SMB server.
100 int ct_flags
; /* SMBCF_ */
101 int ct_fd
; /* handle of connection */
105 char * ct_srvaddr
; /* hostname or IP address of server */
106 char ct_locname
[SMB_MAXUSERNAMELEN
+ 1];
107 const char * ct_uncnext
;
108 struct nb_ctx
* ct_nb
;
109 struct smbioc_ossn ct_ssn
;
110 struct smbioc_oshare ct_sh
;
113 #define SMBCF_NOPWD 0x0001 /* don't ask for a password */
114 #define SMBCF_SRIGHTS 0x0002 /* share access rights was supplied */
115 #define SMBCF_LOCALE 0x0004 /* use current locale */
116 #define SMBCF_RESOLVED 0x8000 /* structure has been verified */
119 * request handling structures
125 struct mbuf
* m_next
;
129 struct mbuf
* mb_top
;
130 struct mbuf
* mb_cur
;
135 #define M_ALIGNFACTOR (sizeof(long))
136 #define M_ALIGN(len) (((len) + M_ALIGNFACTOR - 1) & ~(M_ALIGNFACTOR - 1))
137 #define M_BASESIZE (sizeof(struct mbuf))
138 #define M_MINSIZE (256 - M_BASESIZE)
139 #define M_TOP(m) ((char*)(m) + M_BASESIZE)
140 #define mtod(m,t) ((t)(m)->m_data)
141 #define M_TRAILINGSPACE(m) ((m)->m_maxlen - (m)->m_len)
147 struct smb_ctx
*rq_ctx
;
157 extern struct rcfile
*smb_rc
;
163 int smb_lib_init(void);
164 int smb_open_rcfile(void);
165 void smb_error(const char *, int,...);
166 char *smb_printb(char *, int, const struct smb_bitname
*);
167 void *smb_dumptree(void);
172 int smb_ctx_init(struct smb_ctx
*, int, char *[], int, int, int);
173 void smb_ctx_done(struct smb_ctx
*);
174 int smb_ctx_parseunc(struct smb_ctx
*, const char *, int, const char **);
175 int smb_ctx_setcharset(struct smb_ctx
*, const char *);
176 int smb_ctx_setserver(struct smb_ctx
*, const char *);
177 int smb_ctx_setuser(struct smb_ctx
*, const char *);
178 int smb_ctx_setshare(struct smb_ctx
*, const char *, int);
179 int smb_ctx_setscope(struct smb_ctx
*, const char *);
180 int smb_ctx_setworkgroup(struct smb_ctx
*, const char *);
181 int smb_ctx_setpassword(struct smb_ctx
*, const char *);
182 int smb_ctx_setsrvaddr(struct smb_ctx
*, const char *);
183 int smb_ctx_opt(struct smb_ctx
*, int, const char *);
184 int smb_ctx_lookup(struct smb_ctx
*, int, int);
185 int smb_ctx_login(struct smb_ctx
*);
186 int smb_ctx_readrc(struct smb_ctx
*);
187 int smb_ctx_resolve(struct smb_ctx
*);
188 int smb_ctx_setflags(struct smb_ctx
*, int, int, int);
190 int smb_smb_open_print_file(struct smb_ctx
*, int, int, const char *, smbfh
*);
191 int smb_smb_close_print_file(struct smb_ctx
*, smbfh
);
193 int smb_read(struct smb_ctx
*, smbfh
, off_t
, size_t, char *);
194 int smb_write(struct smb_ctx
*, smbfh
, off_t
, size_t, const char *);
196 #define smb_rq_getrequest(rqp) (&(rqp)->rq_rq)
197 #define smb_rq_getreply(rqp) (&(rqp)->rq_rp)
199 int smb_rq_init(struct smb_ctx
*, u_char
, size_t, struct smb_rq
**);
200 void smb_rq_done(struct smb_rq
*);
201 void smb_rq_wend(struct smb_rq
*);
202 int smb_rq_simple(struct smb_rq
*);
203 int smb_rq_dmem(struct mbdata
*, const char *, size_t);
204 int smb_rq_dstring(struct mbdata
*, const char *);
206 int smb_t2_request(struct smb_ctx
*, int, int, const char *,
207 int, void *, int, void *, int *, void *, int *, void *);
209 char* smb_simplecrypt(char *dst
, const char *src
);
210 int smb_simpledecrypt(char *dst
, const char *src
);
212 int m_getm(struct mbuf
*, size_t, struct mbuf
**);
213 int m_lineup(struct mbuf
*, struct mbuf
**);
214 int mb_init(struct mbdata
*, size_t);
215 int mb_initm(struct mbdata
*, struct mbuf
*);
216 int mb_done(struct mbdata
*);
217 int mb_fit(struct mbdata
*mbp
, size_t size
, void **pp
);
218 int mb_put_uint8(struct mbdata
*, u_int8_t
);
219 int mb_put_uint16be(struct mbdata
*, u_int16_t
);
220 int mb_put_uint16le(struct mbdata
*, u_int16_t
);
221 int mb_put_uint32be(struct mbdata
*, u_int32_t
);
222 int mb_put_uint32le(struct mbdata
*, u_int32_t
);
223 int mb_put_int64be(struct mbdata
*, int64_t);
224 int mb_put_int64le(struct mbdata
*, int64_t);
225 int mb_put_mem(struct mbdata
*, const char *, size_t);
226 int mb_put_pstring(struct mbdata
*mbp
, const char *s
);
227 int mb_put_mbuf(struct mbdata
*, struct mbuf
*);
229 int mb_get_uint8(struct mbdata
*, u_int8_t
*);
230 int mb_get_uint16(struct mbdata
*, u_int16_t
*);
231 int mb_get_uint16le(struct mbdata
*, u_int16_t
*);
232 int mb_get_uint16be(struct mbdata
*, u_int16_t
*);
233 int mb_get_uint32(struct mbdata
*, u_int32_t
*);
234 int mb_get_uint32be(struct mbdata
*, u_int32_t
*);
235 int mb_get_uint32le(struct mbdata
*, u_int32_t
*);
236 int mb_get_int64(struct mbdata
*, int64_t *);
237 int mb_get_int64be(struct mbdata
*, int64_t *);
238 int mb_get_int64le(struct mbdata
*, int64_t *);
239 int mb_get_mem(struct mbdata
*, char *, size_t);
241 extern u_char nls_lower
[256], nls_upper
[256];
243 int nls_setrecode(const char *, const char *);
244 int nls_setlocale(const char *);
245 char* nls_str_toext(char *, const char *);
246 char* nls_str_toloc(char *, const char *);
247 void* nls_mem_toext(void *, const void *, size_t);
248 void* nls_mem_toloc(void *, const void *, size_t);
249 char* nls_str_upper(char *, const char *);
250 char* nls_str_lower(char *, const char *);
254 #endif /* _NETSMB_SMB_LIB_H_ */