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 <assert.h>
19*b819cea2SGordon Ross #include <dlfcn.h>
20*b819cea2SGordon Ross #include <errno.h>
21*b819cea2SGordon Ross #include <string.h>
22*b819cea2SGordon Ross #include <syslog.h>
23*b819cea2SGordon Ross #include <smbsrv/libsmb.h>
24*b819cea2SGordon Ross 
25*b819cea2SGordon Ross /*
26*b819cea2SGordon Ross  * This is exported NODIRECT so that smbd can provide it's own.
27*b819cea2SGordon Ross  */
28*b819cea2SGordon Ross void
smb_vsyslog(int pri,const char * fmt,va_list ap)29*b819cea2SGordon Ross smb_vsyslog(int pri, const char *fmt, va_list ap)
30*b819cea2SGordon Ross {
31*b819cea2SGordon Ross 	vsyslog(pri, fmt, ap);
32*b819cea2SGordon Ross }
33*b819cea2SGordon Ross 
34*b819cea2SGordon Ross /*
35*b819cea2SGordon Ross  * This is exported NODIRECT so that fksmbd can provide it's own.
36*b819cea2SGordon Ross  */
37*b819cea2SGordon Ross void
smb_syslog(int pri,const char * fmt,...)38*b819cea2SGordon Ross smb_syslog(int pri, const char *fmt, ...)
39*b819cea2SGordon Ross {
40*b819cea2SGordon Ross 	va_list ap;
41*b819cea2SGordon Ross 
42*b819cea2SGordon Ross 	va_start(ap, fmt);
43*b819cea2SGordon Ross 	smb_vsyslog(pri, fmt, ap);
44*b819cea2SGordon Ross 	va_end(ap);
45*b819cea2SGordon Ross }
46*b819cea2SGordon Ross 
47*b819cea2SGordon Ross /*
48*b819cea2SGordon Ross  * Helper for smb_vsyslog().  Does %m substitutions.
49*b819cea2SGordon Ross  */
50*b819cea2SGordon Ross char *
smb_syslog_fmt_m(char * buf,int buflen,const char * str,int err)51*b819cea2SGordon Ross smb_syslog_fmt_m(char *buf, int buflen, const char *str, int err)
52*b819cea2SGordon Ross {
53*b819cea2SGordon Ross 	char		*bp = buf;
54*b819cea2SGordon Ross 	const char	*sp = str;
55*b819cea2SGordon Ross 	const char	*endp = buf + buflen - 1;
56*b819cea2SGordon Ross 
57*b819cea2SGordon Ross 	while ((*bp = *sp) != '\0' && bp != endp) {
58*b819cea2SGordon Ross 		if ((*sp++ == '%') && (*sp == 'm')) {
59*b819cea2SGordon Ross 			sp++;
60*b819cea2SGordon Ross 			if (strerror_r(err, bp, endp - bp) == 0)
61*b819cea2SGordon Ross 				bp += strlen(bp);
62*b819cea2SGordon Ross 		} else {
63*b819cea2SGordon Ross 			bp++;
64*b819cea2SGordon Ross 		}
65*b819cea2SGordon Ross 	}
66*b819cea2SGordon Ross 	*bp = '\0';
67*b819cea2SGordon Ross 
68*b819cea2SGordon Ross 	return (buf);
69*b819cea2SGordon Ross }
70