1/*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source.  A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12/*
13 * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
14 */
15
16#include <stdio.h>
17#include <stdarg.h>
18#include <assert.h>
19#include <dlfcn.h>
20#include <errno.h>
21#include <string.h>
22#include <syslog.h>
23#include <smbsrv/libsmb.h>
24
25/*
26 * This is exported NODIRECT so that smbd can provide it's own.
27 */
28void
29smb_vsyslog(int pri, const char *fmt, va_list ap)
30{
31	vsyslog(pri, fmt, ap);
32}
33
34/*
35 * This is exported NODIRECT so that fksmbd can provide it's own.
36 */
37void
38smb_syslog(int pri, const char *fmt, ...)
39{
40	va_list ap;
41
42	va_start(ap, fmt);
43	smb_vsyslog(pri, fmt, ap);
44	va_end(ap);
45}
46
47/*
48 * Helper for smb_vsyslog().  Does %m substitutions.
49 */
50char *
51smb_syslog_fmt_m(char *buf, int buflen, const char *str, int err)
52{
53	char		*bp = buf;
54	const char	*sp = str;
55	const char	*endp = buf + buflen - 1;
56
57	while ((*bp = *sp) != '\0' && bp != endp) {
58		if ((*sp++ == '%') && (*sp == 'm')) {
59			sp++;
60			if (strerror_r(err, bp, endp - bp) == 0)
61				bp += strlen(bp);
62		} else {
63			bp++;
64		}
65	}
66	*bp = '\0';
67
68	return (buf);
69}
70