smb_subr.h revision 87192
1189251Ssam/* 2189251Ssam * Copyright (c) 2000-2001, Boris Popov 3189251Ssam * All rights reserved. 4189251Ssam * 5252726Srpaulo * Redistribution and use in source and binary forms, with or without 6252726Srpaulo * modification, are permitted provided that the following conditions 7189251Ssam * are met: 8189251Ssam * 1. Redistributions of source code must retain the above copyright 9189251Ssam * notice, this list of conditions and the following disclaimer. 10189251Ssam * 2. Redistributions in binary form must reproduce the above copyright 11189251Ssam * notice, this list of conditions and the following disclaimer in the 12189251Ssam * documentation and/or other materials provided with the distribution. 13189251Ssam * 3. All advertising materials mentioning features or use of this software 14189251Ssam * must display the following acknowledgement: 15189251Ssam * This product includes software developed by Boris Popov. 16189251Ssam * 4. Neither the name of the author nor the names of any co-contributors 17189251Ssam * may be used to endorse or promote products derived from this software 18189251Ssam * without specific prior written permission. 19189251Ssam * 20189251Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21209158Srpaulo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22189251Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23189251Ssam * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24189251Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25189251Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26189251Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27189251Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28189251Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29189251Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30189251Ssam * SUCH DAMAGE. 31189251Ssam * 32189251Ssam * $FreeBSD: head/sys/netsmb/smb_subr.h 87192 2001-12-02 08:47:29Z bp $ 33189251Ssam */ 34189251Ssam#ifndef _NETSMB_SMB_SUBR_H_ 35189251Ssam#define _NETSMB_SMB_SUBR_H_ 36189251Ssam 37189251Ssam#ifndef _KERNEL 38189251Ssam#error "This file shouldn't be included from userland programs" 39189251Ssam#endif 40189251Ssam 41189251Ssam#ifdef MALLOC_DECLARE 42189251SsamMALLOC_DECLARE(M_SMBTEMP); 43189251Ssam#endif 44189251Ssam 45189251Ssam#define FB_CURRENT 46189251Ssam 47189251Ssam#define SMBERROR(format, args...) printf("%s: "format, __FUNCTION__ ,## args) 48189251Ssam#define SMBPANIC(format, args...) printf("%s: "format, __FUNCTION__ ,## args) 49189251Ssam 50189251Ssam#ifdef SMB_SOCKET_DEBUG 51189251Ssam#define SMBSDEBUG(format, args...) printf("%s: "format, __FUNCTION__ ,## args) 52189251Ssam#else 53189251Ssam#define SMBSDEBUG(format, args...) 54189251Ssam#endif 55189251Ssam 56189251Ssam#ifdef SMB_IOD_DEBUG 57189251Ssam#define SMBIODEBUG(format, args...) printf("%s: "format, __FUNCTION__ ,## args) 58189251Ssam#else 59189251Ssam#define SMBIODEBUG(format, args...) 60189251Ssam#endif 61189251Ssam 62189251Ssam#ifdef SMB_SOCKETDATA_DEBUG 63189251Ssamvoid m_dumpm(struct mbuf *m); 64189251Ssam#else 65189251Ssam#define m_dumpm(m) 66189251Ssam#endif 67189251Ssam 68189251Ssam#define SMB_SIGMASK(set) \ 69189251Ssam (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \ 70189251Ssam SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \ 71189251Ssam SIGISMEMBER(set, SIGQUIT)) 72189251Ssam 73189251Ssam#define smb_suser(cred) suser_xxx(cred, NULL, 0) 74189251Ssam 75189251Ssam/* 76189251Ssam * Compatibility wrappers for simple locks 77189251Ssam */ 78189251Ssam 79189251Ssam#include <sys/mutex.h> 80189251Ssam 81189251Ssam#define smb_slock mtx 82189251Ssam#define smb_sl_init(mtx, desc) mtx_init(mtx, desc, MTX_DEF) 83189251Ssam#define smb_sl_destroy(mtx) mtx_destroy(mtx) 84189251Ssam#define smb_sl_lock(mtx) mtx_lock(mtx) 85189251Ssam#define smb_sl_unlock(mtx) mtx_unlock(mtx) 86189251Ssam 87189251Ssam 88189251Ssam#define SMB_STRFREE(p) do { if (p) smb_strfree(p); } while(0) 89189251Ssam 90189251Ssam/* 91189251Ssam * The simple try/catch/finally interface. 92189251Ssam * With GCC it is possible to allow more than one try/finally block per 93189251Ssam * function, but we'll avoid it to maintain portability. 94189251Ssam */ 95209158Srpaulo#define itry { \ 96189251Ssam __label__ _finlab, _catchlab; \ 97189251Ssam int _tval; \ 98189251Ssam 99189251Ssam#define icatch(var) \ 100189251Ssam goto _finlab; \ 101189251Ssam (void)&&_catchlab; \ 102189251Ssam _catchlab: \ 103189251Ssam var = _tval; 104189251Ssam 105189251Ssam#define ifinally (void)&&_finlab; \ 106189251Ssam _finlab: 107189251Ssam#define iendtry } 108189251Ssam 109189251Ssam#define inocatch \ 110189251Ssam goto _finlab; \ 111189251Ssam (void)&&_catchlab; \ 112189251Ssam _catchlab: \ 113 114#define ithrow(t) do { \ 115 if ((_tval = (int)(t)) != 0) \ 116 goto _catchlab; \ 117 } while (0) 118 119#define ierror(t,e) do { \ 120 if (t) { \ 121 _tval = e; \ 122 goto _catchlab; \ 123 } \ 124 } while (0) 125 126typedef u_int16_t smb_unichar; 127typedef smb_unichar *smb_uniptr; 128 129/* 130 * Crediantials of user/process being processing in the connection procedures 131 */ 132struct smb_cred { 133 struct thread * scr_td; 134 struct ucred * scr_cred; 135}; 136 137extern smb_unichar smb_unieol; 138 139struct mbchain; 140struct smb_vc; 141struct smb_rq; 142 143void smb_makescred(struct smb_cred *scred, struct thread *td, struct ucred *cred); 144int smb_proc_intr(struct proc *); 145char *smb_strdup(const char *s); 146void *smb_memdup(const void *umem, int len); 147char *smb_strdupin(char *s, int maxlen); 148void *smb_memdupin(void *umem, int len); 149void smb_strtouni(u_int16_t *dst, const char *src); 150void smb_strfree(char *s); 151void smb_memfree(void *s); 152void *smb_zmalloc(unsigned long size, struct malloc_type *type, int flags); 153 154int smb_encrypt(const u_char *apwd, u_char *C8, u_char *RN); 155int smb_ntencrypt(const u_char *apwd, u_char *C8, u_char *RN); 156int smb_maperror(int eclass, int eno); 157int smb_put_dmem(struct mbchain *mbp, struct smb_vc *vcp, 158 const char *src, int len, int caseopt); 159int smb_put_dstring(struct mbchain *mbp, struct smb_vc *vcp, 160 const char *src, int caseopt); 161int smb_put_string(struct smb_rq *rqp, const char *src); 162int smb_put_asunistring(struct smb_rq *rqp, const char *src); 163 164#endif /* !_NETSMB_SMB_SUBR_H_ */ 165