1*b819cea2SGordon Ross /* 2*b819cea2SGordon Ross * This file and its contents are supplied under the terms of the 3*b819cea2SGordon Ross * Common Development and Distribution License ("CDDL"), version 1.0. 4*b819cea2SGordon Ross * You may only use this file in accordance with the terms of version 5*b819cea2SGordon Ross * 1.0 of the CDDL. 6*b819cea2SGordon Ross * 7*b819cea2SGordon Ross * A full copy of the text of the CDDL should have accompanied this 8*b819cea2SGordon Ross * source. A copy of the CDDL is also available via the Internet at 9*b819cea2SGordon Ross * http://www.illumos.org/license/CDDL. 10*b819cea2SGordon Ross */ 11*b819cea2SGordon Ross 12*b819cea2SGordon Ross /* 13*b819cea2SGordon Ross * Copyright 2014 Nexenta Systems, Inc. All rights reserved. 14*b819cea2SGordon Ross */ 15*b819cea2SGordon Ross 16*b819cea2SGordon Ross #include <stdio.h> 17*b819cea2SGordon Ross #include <stdarg.h> 18*b819cea2SGordon Ross #include <errno.h> 19*b819cea2SGordon Ross #include <string.h> 20*b819cea2SGordon Ross #include <syslog.h> 21*b819cea2SGordon Ross #include <sys/strlog.h> 22*b819cea2SGordon Ross 23*b819cea2SGordon Ross #include <smbsrv/smbinfo.h> 24*b819cea2SGordon Ross #include <smbsrv/smb_ioctl.h> 25*b819cea2SGordon Ross #include "smbd.h" 26*b819cea2SGordon Ross 27*b819cea2SGordon Ross #include <libfakekernel/fakekernel.h> 28*b819cea2SGordon Ross 29*b819cea2SGordon Ross static const char *pri_name[LOG_DEBUG+1] = { 30*b819cea2SGordon Ross "emerg", "alert", "crit", "err", "warning", "notice", "info", "debug" 31*b819cea2SGordon Ross }; 32*b819cea2SGordon Ross 33*b819cea2SGordon Ross 34*b819cea2SGordon Ross /* 35*b819cea2SGordon Ross * Provide a replacement for libsmb:smb_vsyslog() that just 36*b819cea2SGordon Ross * prints the messages to stdout for "fksmbd" debugging. 37*b819cea2SGordon Ross */ 38*b819cea2SGordon Ross void 39*b819cea2SGordon Ross smb_vsyslog(int pri, const char *fmt, va_list ap) 40*b819cea2SGordon Ross { 41*b819cea2SGordon Ross int save_errno = errno; 42*b819cea2SGordon Ross char buf[SMBD_LOG_MSGSIZE]; 43*b819cea2SGordon Ross char *newfmt; 44*b819cea2SGordon Ross 45*b819cea2SGordon Ross pri &= LOG_PRIMASK; 46*b819cea2SGordon Ross 47*b819cea2SGordon Ross if (smbd.s_debug == 0 && pri > LOG_INFO) 48*b819cea2SGordon Ross return; 49*b819cea2SGordon Ross 50*b819cea2SGordon Ross newfmt = smb_syslog_fmt_m(buf, sizeof (buf), fmt, save_errno); 51*b819cea2SGordon Ross 52*b819cea2SGordon Ross flockfile(stdout); 53*b819cea2SGordon Ross (void) fprintf(stdout, "fksmbd.%s: ", pri_name[pri]); 54*b819cea2SGordon Ross /* LINTED E_SEC_PRINTF_VAR_FMT */ 55*b819cea2SGordon Ross (void) vfprintf(stdout, newfmt, ap); 56*b819cea2SGordon Ross (void) fprintf(stdout, "\n"); 57*b819cea2SGordon Ross funlockfile(stdout); 58*b819cea2SGordon Ross 59*b819cea2SGordon Ross (void) fflush(stdout); 60*b819cea2SGordon Ross } 61*b819cea2SGordon Ross 62*b819cea2SGordon Ross /* 63*b819cea2SGordon Ross * Provide a real function (one that prints something) to replace 64*b819cea2SGordon Ross * the stub in libfakekernel. This prints cmn_err() messages. 65*b819cea2SGordon Ross */ 66*b819cea2SGordon Ross void 67*b819cea2SGordon Ross fakekernel_putlog(char *msg, size_t len, int flags) 68*b819cea2SGordon Ross { 69*b819cea2SGordon Ross 70*b819cea2SGordon Ross /* 71*b819cea2SGordon Ross * [CE_CONT, CE_NOTE, CE_WARN, CE_PANIC] maps to 72*b819cea2SGordon Ross * [SL_NOTE, SL_NOTE, SL_WARN, SL_FATAL] 73*b819cea2SGordon Ross */ 74*b819cea2SGordon Ross if (smbd.s_debug == 0 && (flags & SL_NOTE)) 75*b819cea2SGordon Ross return; 76*b819cea2SGordon Ross (void) fwrite(msg, 1, len, stdout); 77*b819cea2SGordon Ross (void) fflush(stdout); 78*b819cea2SGordon Ross } 79*b819cea2SGordon Ross 80*b819cea2SGordon Ross /* 81*b819cea2SGordon Ross * Initialization function called at the start of fksmbd:main(). 82*b819cea2SGordon Ross * Call an empty function in both of libfksmbsrv, libfakekernel, 83*b819cea2SGordon Ross * just to force them to load so we can set breakpoints in them 84*b819cea2SGordon Ross * without debugger forceload tricks. This also avoids elfchk 85*b819cea2SGordon Ross * complaints from libfakekernel, which we don't call directly 86*b819cea2SGordon Ross * except for here. 87*b819cea2SGordon Ross */ 88*b819cea2SGordon Ross void 89*b819cea2SGordon Ross fksmbd_init(void) 90*b819cea2SGordon Ross { 91*b819cea2SGordon Ross fksmbsrv_drv_load(); 92*b819cea2SGordon Ross fakekernel_init(); 93*b819cea2SGordon Ross } 94