smb_subr.h revision 75374
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 * $FreeBSD: head/sys/netsmb/smb_subr.h 75374 2001-04-10 07:59:06Z bp $ 33 */ 34#ifndef _NETSMB_SMB_SUBR_H_ 35#define _NETSMB_SMB_SUBR_H_ 36 37#ifndef _KERNEL 38#error "This file shouldn't be included from userland programs" 39#endif 40 41#ifdef MALLOC_DECLARE 42MALLOC_DECLARE(M_SMBTEMP); 43#endif 44 45#if __FreeBSD_version > 500000 46#define FB_CURRENT 47#else 48# if __FreeBSD_version > 400000 49# define FB_RELENG4 50# else 51# error "Unsupported version of FreeBSD" 52# endif 53#endif 54 55#define SMBERROR(format, args...) printf("%s: "format, __FUNCTION__ ,## args) 56#define SMBPANIC(format, args...) printf("%s: "format, __FUNCTION__ ,## args) 57 58#ifdef SMB_SOCKET_DEBUG 59#define SMBSDEBUG(format, args...) printf("%s: "format, __FUNCTION__ ,## args) 60#else 61#define SMBSDEBUG(format, args...) 62#endif 63 64#ifdef SMB_IOD_DEBUG 65#define SMBIODEBUG(format, args...) printf("%s: "format, __FUNCTION__ ,## args) 66#else 67#define SMBIODEBUG(format, args...) 68#endif 69 70#ifdef SMB_SOCKETDATA_DEBUG 71void m_dumpm(struct mbuf *m); 72#else 73#define m_dumpm(m) 74#endif 75 76#if __FreeBSD_version > 400009 77#define SMB_SIGMASK(set) \ 78 (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \ 79 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \ 80 SIGISMEMBER(set, SIGQUIT)) 81 82#define smb_suser(cred) suser_xxx(cred, NULL, 0) 83#else 84#define SMB_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \ 85 sigmask(SIGHUP)|sigmask(SIGQUIT)) 86 87#define smb_suser(cred) suser((cred), NULL) 88#endif 89 90/* 91 * Compatibility wrappers for simple locks 92 */ 93#if __FreeBSD_version < 500000 94 95#include <sys/lock.h> 96 97#define lockdestroy(lock) 98#define smb_slock simplelock 99#define smb_sl_init(mtx, desc) simple_lock_init(mtx) 100#define smb_sl_destroy(mtx) 101#define smb_sl_lock(mtx) simple_lock(mtx) 102#define smb_sl_unlock(mtx) simple_unlock(mtx) 103/* 104#define mtx lock 105#define mtx_init(mtx, desc, flags) lockinit(mtx, PWAIT, desc, 0, 0) 106#define mtx_lock(mtx) lockmgr(mtx, LK_EXCLUSIVE, NULL, curproc) 107#define mtx_unlock(mtx) lockmgr(mtx, LK_RELEASE, NULL, curproc) 108#define mtx_destroy(mtx) 109*/ 110#else 111 112#include <sys/mutex.h> 113 114#define smb_slock mtx 115#define smb_sl_init(mtx, desc) mtx_init(mtx, desc, MTX_DEF) 116#define smb_sl_destroy(mtx) mtx_destroy(mtx) 117#define smb_sl_lock(mtx) mtx_lock(mtx) 118#define smb_sl_unlock(mtx) mtx_unlock(mtx) 119 120#endif 121 122#define SMB_STRFREE(p) do { if (p) smb_strfree(p); } while(0) 123 124/* 125 * The simple try/catch/finally interface. 126 * With GCC it is possible to allow more than one try/finally block per 127 * function, but we'll avoid it to maintain portability. 128 */ 129#define itry { \ 130 __label__ _finlab, _catchlab; \ 131 int _tval; \ 132 133#define icatch(var) \ 134 goto _finlab; \ 135 (void)&&_catchlab; \ 136 _catchlab: \ 137 var = _tval; 138 139#define ifinally (void)&&_finlab; \ 140 _finlab: 141#define iendtry } 142 143#define inocatch \ 144 goto _finlab; \ 145 (void)&&_catchlab; \ 146 _catchlab: \ 147 148#define ithrow(t) do { \ 149 if ((_tval = (int)(t)) != 0) \ 150 goto _catchlab; \ 151 } while (0) 152 153#define ierror(t,e) do { \ 154 if (t) { \ 155 _tval = e; \ 156 goto _catchlab; \ 157 } \ 158 } while (0) 159 160typedef u_int16_t smb_unichar; 161typedef smb_unichar *smb_uniptr; 162 163/* 164 * Crediantials of user/process being processing in the connection procedures 165 */ 166struct smb_cred { 167 struct proc * scr_p; 168 struct ucred * scr_cred; 169}; 170 171extern smb_unichar smb_unieol; 172 173struct mbchain; 174struct smb_vc; 175struct smb_rq; 176 177void smb_makescred(struct smb_cred *scred, struct proc *p, struct ucred *cred); 178int smb_proc_intr(struct proc *); 179char *smb_strdup(const char *s); 180void *smb_memdup(const void *umem, int len); 181char *smb_strdupin(char *s, int maxlen); 182void *smb_memdupin(void *umem, int len); 183void smb_strtouni(u_int16_t *dst, const char *src); 184void smb_strfree(char *s); 185void smb_memfree(void *s); 186void *smb_zmalloc(unsigned long size, struct malloc_type *type, int flags); 187 188int smb_encrypt(const u_char *apwd, u_char *C8, u_char *RN); 189int smb_ntencrypt(const u_char *apwd, u_char *C8, u_char *RN); 190int smb_maperror(int eclass, int eno); 191int smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp, 192 const char *src, int len, int caseopt); 193int smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp, 194 const char *src, int caseopt); 195int smb_put_string(struct smb_rq *rqp, const char *src); 196int smb_put_asunistring(struct smb_rq *rqp, const char *src); 197 198#endif /* !_NETSMB_SMB_SUBR_H_ */ 199