xref: /titanic_41/usr/src/lib/libsmbfs/netsmb/smb_lib.h (revision 05ead181677a01a3a118f8b89ce79361113e34cf)
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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
37  */
38 
39 #ifndef _NETSMB_SMB_LIB_H_
40 #define	_NETSMB_SMB_LIB_H_
41 
42 /*
43  * Internal interface exported to our commands in:
44  *	usr/src/cmd/fs.d/smbclnt/
45  */
46 
47 #include <sys/types.h>
48 #include <sys/socket.h>
49 #include <netinet/in.h>
50 #include <arpa/inet.h>
51 #include <sys/byteorder.h>
52 
53 #include <netsmb/smbfs_api.h>
54 #include <netsmb/smb_dev.h>
55 
56 extern const char smbutil_std_opts[];
57 #define	STDPARAM_OPT	smbutil_std_opts
58 
59 /*
60  * bits to indicate the source of error
61  */
62 #define	SMB_ERRTYPE_MASK	0xf0000
63 #define	SMB_SYS_ERROR		0x00000
64 #define	SMB_RAP_ERROR		0x10000
65 #define	SMB_NB_ERROR		0x20000
66 
67 /*
68  * Size of all LM/NTLM hashes (16 bytes).
69  * The driver needs to know this, so it's
70  * defined by smb_dev.h
71  */
72 #define	NTLM_HASH_SZ		SMBIOC_HASH_SZ
73 #define	NTLM_CHAL_SZ		8	/* challenge size */
74 
75 /*
76  * This is what goes across the door call to the IOD
77  * when asking for a new connection.
78  */
79 struct smb_iod_ssn {
80 	struct smbioc_ossn iod_ossn;
81 	int		iod_authflags;	/* SMB_AT_x */
82 	uchar_t		iod_nthash[NTLM_HASH_SZ];
83 	uchar_t		iod_lmhash[NTLM_HASH_SZ];
84 	/* Kerberos cred. cache res. name? */
85 };
86 typedef struct smb_iod_ssn smb_iod_ssn_t;
87 
88 
89 /*
90  * SMB work context. Used to store all values which are necessary
91  * to establish connection to an SMB server.
92  */
93 struct smb_ctx {
94 	int		ct_flags;	/* SMBCF_ */
95 	int		ct_dev_fd;	/* device handle */
96 	int		ct_door_fd;	/* to smbiod */
97 	int		ct_parsedlevel;
98 	int		ct_minlevel;
99 	int		ct_maxlevel;
100 	char		*ct_fullserver; /* orig. server name from cmd line */
101 	char		*ct_srvaddr_s;	/* hostname or IP address of server */
102 	struct addrinfo *ct_addrinfo;	/* IP addresses of the server */
103 	struct nb_ctx	*ct_nb;		/* NetBIOS info. */
104 	char		*ct_locname;	/* local (machine) name */
105 	smb_iod_ssn_t	ct_iod_ssn;
106 	/* smbioc_oshare_t	ct_sh; XXX */
107 	int		ct_minauth;
108 	int		ct_shtype_req;	/* share type wanted */
109 	char		*ct_origshare;
110 	char		*ct_home;
111 
112 	/* Connection setup SMB stuff. */
113 	/* Strings from the SMB negotiate response. */
114 	char		*ct_srv_OS;
115 	char		*ct_srv_LM;
116 
117 	/* NTLM auth. stuff */
118 	uchar_t		ct_clnonce[NTLM_CHAL_SZ];
119 	uchar_t		ct_ntlm_chal[NTLM_CHAL_SZ];
120 	char		ct_password[SMBIOC_MAX_NAME];
121 
122 	/* See ssp.c */
123 	void		*ct_ssp_ctx;
124 	smbioc_ssn_work_t ct_work;
125 };
126 
127 
128 /*
129  * Short-hand for some of the substruct fields above
130  */
131 #define	ct_ssn		ct_iod_ssn.iod_ossn
132 #define	ct_vopt		ct_iod_ssn.iod_ossn.ssn_vopt
133 #define	ct_owner	ct_iod_ssn.iod_ossn.ssn_owner
134 #define	ct_srvaddr	ct_iod_ssn.iod_ossn.ssn_srvaddr
135 #define	ct_domain	ct_iod_ssn.iod_ossn.ssn_domain
136 #define	ct_user 	ct_iod_ssn.iod_ossn.ssn_user
137 #define	ct_srvname 	ct_iod_ssn.iod_ossn.ssn_srvname
138 #define	ct_authflags	ct_iod_ssn.iod_authflags
139 #define	ct_nthash	ct_iod_ssn.iod_nthash
140 #define	ct_lmhash	ct_iod_ssn.iod_lmhash
141 
142 #define	ct_sopt		ct_work.wk_sopt
143 #define	ct_iods		ct_work.wk_iods
144 #define	ct_tran_fd	ct_work.wk_iods.is_tran_fd
145 #define	ct_hflags	ct_work.wk_iods.is_hflags
146 #define	ct_hflags2	ct_work.wk_iods.is_hflags2
147 #define	ct_vcflags	ct_work.wk_iods.is_vcflags
148 #define	ct_ssn_key	ct_work.wk_iods.is_ssn_key
149 #define	ct_mac_seqno	ct_work.wk_iods.is_next_seq
150 #define	ct_mackeylen	ct_work.wk_iods.is_u_maclen
151 #define	ct_mackey	ct_work.wk_iods.is_u_mackey.lp_ptr
152 
153 
154 /*
155  * Bits in smb_ctx_t.ct_flags
156  */
157 #define	SMBCF_NOPWD		    0x0001 /* don't ask for a password */
158 #define	SMBCF_SRIGHTS		    0x0002 /* share access rights supplied */
159 #define	SMBCF_LOCALE		    0x0004 /* use current locale */
160 #define	SMBCF_CMD_DOM		    0x0010 /* CMD specified domain */
161 #define	SMBCF_CMD_USR		    0x0020 /* CMD specified user */
162 #define	SMBCF_CMD_PW		    0x0040 /* CMD specified password */
163 #define	SMBCF_RESOLVED		    0x8000 /* structure has been verified */
164 #define	SMBCF_KCBAD		0x00080000 /* keychain password failed */
165 #define	SMBCF_KCFOUND		0x00100000 /* password is from keychain */
166 #define	SMBCF_BROWSEOK		0x00200000 /* browser dialogue may be used */
167 #define	SMBCF_AUTHREQ		0x00400000 /* auth. dialog requested */
168 #define	SMBCF_KCSAVE		0x00800000 /* add to keychain requested */
169 #define	SMBCF_XXX		0x01000000 /* mount-all, a very bad thing */
170 #define	SMBCF_SSNACTIVE		0x02000000 /* session setup succeeded */
171 #define	SMBCF_KCDOMAIN		0x04000000 /* use domain in KC lookup */
172 
173 
174 /*
175  * Context management
176  */
177 
178 int  smb_ctx_init(struct smb_ctx *);
179 void smb_ctx_done(struct smb_ctx *);
180 int  smb_open_driver(void);
181 
182 int  smb_ctx_gethandle(struct smb_ctx *);
183 int  smb_ctx_findvc(struct smb_ctx *);
184 int  smb_ctx_newvc(struct smb_ctx *);
185 
186 /*
187  * I/O daemon stuff
188  */
189 
190 #define	SMBIOD_RUNDIR	"/var/run/smbiod"
191 #define	SMBIOD_SVC_DOOR	SMBIOD_RUNDIR "/.svc"
192 #define	SMBIOD_USR_DOOR	SMBIOD_RUNDIR "/%d"
193 #define	SMBIOD_START	1
194 
195 int  smb_iod_cl_newvc(smb_ctx_t *ctx);
196 char *smb_iod_door_path(void);
197 int smb_iod_open_door(int *);
198 int smb_iod_connect(struct smb_ctx *);
199 int smb_iod_work(struct smb_ctx *);
200 
201 /*
202  * Other stuff
203  */
204 
205 int  smb_open_rcfile(char *);
206 void smb_close_rcfile(void);
207 
208 void smb_simplecrypt(char *dst, const char *src);
209 int  smb_simpledecrypt(char *dst, const char *src);
210 
211 int	nls_setrecode(const char *, const char *);
212 int	nls_setlocale(const char *);
213 char	*nls_str_toext(char *, const char *);
214 char	*nls_str_toloc(char *, const char *);
215 void	*nls_mem_toext(void *, const void *, int);
216 void	*nls_mem_toloc(void *, const void *, int);
217 char	*nls_str_upper(char *, const char *);
218 char	*nls_str_lower(char *, const char *);
219 
220 char *smb_getprogname();
221 #define	__progname smb_getprogname()
222 
223 #endif /* _NETSMB_SMB_LIB_H_ */
224