xref: /illumos-gate/usr/src/lib/libsmbfs/netsmb/smb_lib.h (revision b424305435881ac456a9343be2898f1f86440f31)
1 /*
2  * Copyright (c) 2000-2001 Boris Popov
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
19  *
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
30  * SUCH DAMAGE.
31  *
32  * $Id: smb_lib.h,v 1.21.82.2 2005/06/02 00:55:39 lindak Exp $
33  */
34 
35 /*
36  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
37  * Use is subject to license terms.
38  */
39 
40 #ifndef _NETSMB_SMB_LIB_H_
41 #define	_NETSMB_SMB_LIB_H_
42 
43 #include <sys/types.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
47 #include <sys/byteorder.h>
48 
49 #include <netsmb/smb.h>
50 #include <netsmb/smb_dev.h>
51 
52 #define	SMB_CFG_FILE	"/etc/nsmb.conf"
53 #define	OLD_SMB_CFG_FILE	"/usr/local/etc/nsmb.conf"
54 
55 #define	STDPARAM_ARGS	\
56 	'A':case 'B':case 'C':case 'E':case 'I':case 'L':case \
57 	'M':case 'N':case 'U':case 'R':case 'S':case 'T':case \
58 	'W':case 'O':case 'P'
59 
60 #define	STDPARAM_OPT	"ABCE:I:L:M:NO:P:U:R:S:T:W:"
61 
62 /*
63  * bits to indicate the source of error
64  */
65 #define	SMB_ERRTYPE_MASK	0xf0000
66 #define	SMB_SYS_ERROR		0x00000
67 #define	SMB_RAP_ERROR		0x10000
68 #define	SMB_NB_ERROR		0x20000
69 
70 /*
71  * SMB work context. Used to store all values which are necessary
72  * to establish connection to an SMB server.
73  */
74 struct smb_ctx {
75 	int		ct_flags;	/* SMBCF_ */
76 	int		ct_fd;		/* handle of connection */
77 	int		ct_parsedlevel;
78 	int		ct_minlevel;
79 	int		ct_maxlevel;
80 	char		*ct_fullserver; /* original server name from cmd line */
81 	char		*ct_srvaddr;	/* hostname or IP address of server */
82 	struct sockaddr_in ct_srvinaddr; /* IP address of server */
83 	char		ct_locname[SMB_MAXUSERNAMELEN + 1];
84 	struct nb_ctx	*ct_nb;
85 	struct smbioc_ossn	ct_ssn;
86 	struct smbioc_oshare	ct_sh;
87 	char		*ct_origshare;
88 	char		*ct_home;
89 	void		*ct_secblob;
90 	int		ct_secbloblen;
91 	/* krb5 stuff: all anonymous struct pointers here. */
92 	struct _krb5_context *ct_krb5ctx;
93 	struct _krb5_ccache *ct_krb5cc; 	/* credentials cache */
94 	struct krb5_principal_data *ct_krb5cp;	/* client principal */
95 };
96 typedef struct smb_ctx smb_ctx_t;
97 
98 #define	SMBCF_NOPWD		    0x0001 /* don't ask for a password */
99 #define	SMBCF_SRIGHTS		    0x0002 /* share access rights supplied */
100 #define	SMBCF_LOCALE		    0x0004 /* use current locale */
101 #define	SMBCF_CMD_DOM		    0x0010 /* CMD specified domain */
102 #define	SMBCF_CMD_USR		    0x0020 /* CMD specified user */
103 #define	SMBCF_CMD_PW		    0x0040 /* CMD specified password */
104 #define	SMBCF_RESOLVED		    0x8000 /* structure has been verified */
105 #define	SMBCF_KCBAD		0x00080000 /* keychain password failed */
106 #define	SMBCF_KCFOUND		0x00100000 /* password is from keychain */
107 #define	SMBCF_BROWSEOK		0x00200000 /* browser dialogue may be used */
108 #define	SMBCF_AUTHREQ		0x00400000 /* auth. dialog requested */
109 #define	SMBCF_KCSAVE		0x00800000 /* add to keychain requested */
110 #define	SMBCF_XXX		0x01000000 /* mount-all, a very bad thing */
111 #define	SMBCF_SSNACTIVE		0x02000000 /* session setup succeeded */
112 #define	SMBCF_KCDOMAIN		0x04000000 /* use domain in KC lookup */
113 
114 /*
115  * access modes (see also smb_dev.h)
116  */
117 #define	SMBM_READ	S_IRUSR	/* read conn attrs. (like list shares) */
118 #define	SMBM_WRITE	S_IWUSR	/* modify conn attrs */
119 #define	SMBM_EXEC	S_IXUSR	/* can send SMB requests */
120 #define	SMBM_READGRP	S_IRGRP
121 #define	SMBM_WRITEGRP	S_IWGRP
122 #define	SMBM_EXECGRP	S_IXGRP
123 #define	SMBM_READOTH	S_IROTH
124 #define	SMBM_WRITEOTH	S_IWOTH
125 #define	SMBM_EXECOTH	S_IXOTH
126 #define	SMBM_ALL	S_IRWXU
127 #define	SMBM_DEFAULT	S_IRWXU
128 
129 
130 /*
131  * Share type for smb_ctx_init
132  */
133 #define	SMB_ST_DISK		STYPE_DISKTREE
134 #define	SMB_ST_PRINTER		STYPE_PRINTQ
135 #define	SMB_ST_COMM		STYPE_DEVICE
136 #define	SMB_ST_PIPE		STYPE_IPC
137 #define	SMB_ST_ANY		STYPE_UNKNOWN
138 #define	SMB_ST_MAX		STYPE_UNKNOWN
139 #define	SMB_ST_NONE		0xff	/* not a part of protocol */
140 
141 struct mbdata {
142 	struct mbuf	*mb_top;
143 	struct mbuf	*mb_cur;
144 	char		*mb_pos;
145 	int		mb_count;
146 };
147 typedef struct mbdata mbdata_t;
148 
149 struct smb_bitname {
150 	uint_t	bn_bit;
151 	char	*bn_name;
152 };
153 typedef struct smb_bitname smb_bitname_t;
154 
155 extern int smb_debug, smb_verbose;
156 extern struct rcfile *smb_rc;
157 
158 #ifdef __cplusplus
159 extern "C" {
160 #endif
161 
162 int  smb_lib_init(void);
163 int  smb_open_driver(void);
164 int  smb_open_rcfile(struct smb_ctx *ctx);
165 void smb_error(const char *, int, ...);
166 char *smb_printb(char *, int, const struct smb_bitname *);
167 
168 /*
169  * Context management
170  */
171 int  smb_ctx_init(struct smb_ctx *, int, char *[], int, int, int);
172 void smb_ctx_done(struct smb_ctx *);
173 int  smb_ctx_parseunc(struct smb_ctx *, const char *, int, const char **);
174 int  smb_ctx_setcharset(struct smb_ctx *, const char *);
175 int  smb_ctx_setfullserver(struct smb_ctx *, const char *);
176 void  smb_ctx_setserver(struct smb_ctx *, const char *);
177 int  smb_ctx_setuser(struct smb_ctx *, const char *, int);
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 *, int);
181 int  smb_ctx_setpassword(struct smb_ctx *, const char *, int);
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_findvc(struct smb_ctx *, int, int);
185 int  smb_ctx_negotiate(struct smb_ctx *, int, int, char *);
186 int  smb_ctx_tdis(struct smb_ctx *ctx);
187 int  smb_ctx_lookup(struct smb_ctx *, int, int);
188 int  smb_ctx_login(struct smb_ctx *);
189 int  smb_ctx_readrc(struct smb_ctx *);
190 int  smb_ctx_resolve(struct smb_ctx *);
191 int  smb_ctx_setflags(struct smb_ctx *, int, int, int);
192 int  smb_ctx_flags2(struct smb_ctx *);
193 
194 int  smb_smb_open_print_file(struct smb_ctx *, int, int, const char *, smbfh*);
195 int  smb_smb_close_print_file(struct smb_ctx *, smbfh);
196 
197 typedef void (*smb_ctx_close_hook_t)(struct smb_ctx *);
198 void smb_ctx_set_close_hook(smb_ctx_close_hook_t);
199 int  smb_fh_close(struct smb_ctx *ctx, smbfh fh);
200 int  smb_fh_open(struct smb_ctx *ctx, const char *, int, smbfh *);
201 int  smb_fh_read(struct smb_ctx *, smbfh, off_t, size_t, char *);
202 int  smb_fh_write(struct smb_ctx *, smbfh, off_t, size_t, const char *);
203 int  smb_fh_xactnp(struct smb_ctx *, smbfh, int, const char *,
204 	int *, char *, int *);
205 
206 int  smb_t2_request(struct smb_ctx *, int, uint16_t *, const char *,
207 	int, void *, int, void *, int *, void *, int *, void *, int *);
208 
209 void smb_simplecrypt(char *dst, const char *src);
210 int  smb_simpledecrypt(char *dst, const char *src);
211 
212 int	nls_setrecode(const char *, const char *);
213 int	nls_setlocale(const char *);
214 char	*nls_str_toext(char *, const char *);
215 char	*nls_str_toloc(char *, const char *);
216 void	*nls_mem_toext(void *, const void *, int);
217 void	*nls_mem_toloc(void *, const void *, int);
218 char	*nls_str_upper(char *, const char *);
219 char	*nls_str_lower(char *, const char *);
220 
221 int smb_get_authentication(char *, size_t, char *, size_t, char *, size_t,
222 	const char *, struct smb_ctx *);
223 int smb_browse(struct smb_ctx *, int);
224 void smb_save2keychain(struct smb_ctx *);
225 #define	smb_autherr(e) ((e) == EAUTH || (e) == EACCES || (e) == EPERM)
226 char *smb_strerror(int);
227 char *smb_getprogname();
228 #define	__progname smb_getprogname()
229 
230 extern char *unpercent(char *component);
231 
232 #ifdef __cplusplus
233 }
234 #endif
235 
236 #endif /* _NETSMB_SMB_LIB_H_ */
237