xref: /titanic_41/usr/src/uts/common/fs/smbclnt/netsmb/smb_subr.h (revision 430b4c467020edf2445feb0c21db01c88b86243a)
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_subr.h,v 1.13 2004/09/14 22:59:08 lindak Exp $
33  */
34 
35 /*
36  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
37  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
38  */
39 
40 #ifndef _NETSMB_SMB_SUBR_H_
41 #define	_NETSMB_SMB_SUBR_H_
42 
43 #include <sys/cmn_err.h>
44 #include <sys/lock.h>
45 #include <sys/note.h>
46 #include <netsmb/smb_conn.h>
47 
48 /* Helper function for SMBERROR */
49 /*PRINTFLIKE3*/
50 extern void smb_errmsg(int, const char *, const char *, ...)
51 	__KPRINTFLIKE(3);
52 void m_dumpm(mblk_t *m);
53 
54 /*
55  * Let's use C99 standard variadic macros!
56  * Also the C99 __func__ (function name) feature.
57  */
58 #define	SMBERROR(...) \
59 	smb_errmsg(CE_NOTE, __func__, __VA_ARGS__)
60 #define	SMBPANIC(...) \
61 	smb_errmsg(CE_PANIC, __func__, __VA_ARGS__)
62 #define	SMBSDEBUG(...) \
63 	smb_errmsg(CE_CONT, __func__, __VA_ARGS__)
64 #define	SMBIODEBUG(...) \
65 	smb_errmsg(CE_CONT, __func__, __VA_ARGS__)
66 #define	NBDEBUG(...) \
67 	smb_errmsg(CE_CONT, __func__, __VA_ARGS__)
68 
69 #if defined(DEBUG) || defined(lint)
70 
71 #define	DEBUG_ENTER(str) debug_enter(str)
72 
73 #else /* DEBUG or lint */
74 
75 #define	DEBUG_ENTER(str) ((void)0)
76 
77 #endif /* DEBUG or lint */
78 
79 typedef uint16_t	smb_unichar;
80 typedef	smb_unichar	*smb_uniptr;
81 
82 extern smb_unichar smb_unieol;
83 
84 struct mbchain;
85 struct smb_rq;
86 struct smb_vc;
87 
88 /*
89  * These are the attributes we can get from the server via
90  * SMB commands such as TRANS2_QUERY_FILE_INFORMATION
91  * with info level SMB_QFILEINFO_ALL_INFO, and directory
92  * FindFirst/FindNext info. levels FIND_DIRECTORY_INFO
93  * and FIND_BOTH_DIRECTORY_INFO, etc.
94  *
95  * Values in this struct are always native endian,
96  * and times are converted converted to Unix form.
97  * Note: zero in any of the times means "unknown".
98  */
99 typedef struct smbfattr {
100 	timespec_t	fa_createtime;	/* Note, != ctime */
101 	timespec_t	fa_atime;	/* these 3 are like unix */
102 	timespec_t	fa_mtime;
103 	timespec_t	fa_ctime;
104 	u_offset_t	fa_size;	/* EOF position */
105 	u_offset_t	fa_allocsz;	/* Allocated size. */
106 	uint32_t	fa_attr;	/* Ext. file (DOS) attr */
107 } smbfattr_t;
108 
109 /*
110  * Tunable timeout values.  See: smb_smb.c
111  */
112 extern int smb_timo_notice;
113 extern int smb_timo_default;
114 extern int smb_timo_open;
115 extern int smb_timo_read;
116 extern int smb_timo_write;
117 extern int smb_timo_append;
118 
119 #define	EMOREDATA (0x7fff)
120 
121 void smb_credinit(struct smb_cred *scred, cred_t *cr);
122 void smb_credrele(struct smb_cred *scred);
123 
124 void smb_oldlm_hash(const char *apwd, uchar_t *hash);
125 void smb_ntlmv1hash(const char *apwd, uchar_t *hash);
126 void smb_ntlmv2hash(const uchar_t *v1hash, const char *user,
127 	const char *destination, uchar_t *v2hash);
128 
129 int  smb_lmresponse(const uchar_t *hash, const uchar_t *C8, uchar_t *RN);
130 int  smb_ntlmv2response(const uchar_t *hash, const uchar_t *C8,
131     const uchar_t *blob, size_t bloblen, uchar_t **RN, size_t *RNlen);
132 int  smb_maperror(int eclass, int eno);
133 int  smb_maperr32(uint32_t eno);
134 int  smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp,
135     const char *src, int len, int caseopt, int *lenp);
136 int  smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp,
137     const char *src, int caseopt);
138 int  smb_put_string(struct smb_rq *rqp, const char *src);
139 int  smb_put_asunistring(struct smb_rq *rqp, const char *src);
140 int  smb_checksmp(void);
141 
142 int smb_cmp_sockaddr(struct sockaddr *, struct sockaddr *);
143 struct sockaddr *smb_dup_sockaddr(struct sockaddr *sa);
144 void smb_free_sockaddr(struct sockaddr *sa);
145 int smb_toupper(const char *, char *, size_t);
146 
147 void smb_rq_sign(struct smb_rq *);
148 int smb_rq_verify(struct smb_rq *);
149 int smb_calcv2mackey(struct smb_vc *, const uchar_t *,
150 	const uchar_t *, size_t);
151 int smb_calcmackey(struct smb_vc *, const uchar_t *,
152 	const uchar_t *, size_t);
153 void smb_crypto_mech_init(void);
154 
155 
156 /*
157  * SMB protocol level functions
158  */
159 int  smb_smb_echo(smb_vc_t *vcp, smb_cred_t *scred, int timo);
160 int  smb_smb_treeconnect(smb_share_t *ssp, smb_cred_t *scred);
161 int  smb_smb_treedisconnect(smb_share_t *ssp, smb_cred_t *scred);
162 
163 int
164 smb_smb_ntcreate(struct smb_share *ssp, struct mbchain *name_mb,
165 	uint32_t crflag, uint32_t req_acc, uint32_t efa, uint32_t sh_acc,
166 	uint32_t disp, uint32_t createopt,  uint32_t impersonate,
167 	struct smb_cred *scrp, uint16_t *fidp,
168 	uint32_t *cr_act_p, struct smbfattr *fap);
169 
170 int  smb_smb_close(struct smb_share *ssp, uint16_t fid,
171 	struct timespec *mtime, struct smb_cred *scrp);
172 
173 int
174 smb_smb_open_prjob(struct smb_share *ssp, char *title,
175 	uint16_t setuplen, uint16_t mode,
176 	struct smb_cred *scrp, uint16_t *fidp);
177 
178 int  smb_smb_close_prjob(struct smb_share *ssp, uint16_t fid,
179 	struct smb_cred *scrp);
180 
181 int smb_rwuio(smb_share_t *ssp, uint16_t fid, uio_rw_t rw,
182 	uio_t *uiop, smb_cred_t *scred, int timo);
183 
184 /*
185  * time conversions
186  */
187 
188 void smb_time_init(void);
189 void smb_time_fini(void);
190 
191 void  smb_time_local2server(struct timespec *tsp, int tzoff, long *seconds);
192 void  smb_time_server2local(ulong_t seconds, int tzoff, struct timespec *tsp);
193 void  smb_time_NT2local(uint64_t nsec, struct timespec *tsp);
194 void  smb_time_local2NT(struct timespec *tsp, uint64_t *nsec);
195 void  smb_time_unix2dos(struct timespec *tsp, int tzoff, uint16_t *ddp,
196 	uint16_t *dtp, uint8_t *dhp);
197 void smb_dos2unixtime(uint_t dd, uint_t dt, uint_t dh, int tzoff,
198 	struct timespec *tsp);
199 
200 #endif /* !_NETSMB_SMB_SUBR_H_ */
201