|
Packit Service |
102278 |
/* Author: Joshua Brindle
|
|
Packit Service |
102278 |
* Jason Tang <jtang@tresys.com>
|
|
Packit Service |
102278 |
* Ivan Gyurdiev <ivg2@cornell.edu>
|
|
Packit Service |
102278 |
*
|
|
Packit Service |
102278 |
* Copyright (C) 2004-2005 Tresys Technology, LLC
|
|
Packit Service |
102278 |
* Copyright (C) 2005 Red Hat Inc.
|
|
Packit Service |
102278 |
*
|
|
Packit Service |
102278 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
102278 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
102278 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
102278 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
102278 |
*
|
|
Packit Service |
102278 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
102278 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
102278 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
102278 |
* Lesser General Public License for more details.
|
|
Packit Service |
102278 |
*
|
|
Packit Service |
102278 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
102278 |
* License along with this library; if not, write to the Free Software
|
|
Packit Service |
102278 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit Service |
102278 |
*/
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
#include <stdarg.h>
|
|
Packit Service |
102278 |
#include <stdlib.h>
|
|
Packit Service |
102278 |
#include <stdio.h>
|
|
Packit Service |
102278 |
#include <errno.h>
|
|
Packit Service |
102278 |
#include <string.h>
|
|
Packit Service |
102278 |
#include "handle.h"
|
|
Packit Service |
102278 |
#include "debug.h"
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
int semanage_msg_get_level(semanage_handle_t * handle)
|
|
Packit Service |
102278 |
{
|
|
Packit Service |
102278 |
return handle->msg_level;
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
hidden_def(semanage_msg_get_level)
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
const char *semanage_msg_get_channel(semanage_handle_t * handle)
|
|
Packit Service |
102278 |
{
|
|
Packit Service |
102278 |
return handle->msg_channel;
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
hidden_def(semanage_msg_get_channel)
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
const char *semanage_msg_get_fname(semanage_handle_t * handle)
|
|
Packit Service |
102278 |
{
|
|
Packit Service |
102278 |
return handle->msg_fname;
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
hidden_def(semanage_msg_get_fname)
|
|
Packit Service |
102278 |
#ifdef __GNUC__
|
|
Packit Service |
102278 |
__attribute__ ((format(printf, 3, 4)))
|
|
Packit Service |
102278 |
#endif
|
|
Packit Service |
102278 |
void hidden semanage_msg_default_handler(void *varg __attribute__ ((unused)),
|
|
Packit Service |
102278 |
semanage_handle_t * handle,
|
|
Packit Service |
102278 |
const char *fmt, ...)
|
|
Packit Service |
102278 |
{
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
FILE *stream = NULL;
|
|
Packit Service |
102278 |
int errsv = 0;
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
switch (semanage_msg_get_level(handle)) {
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
case SEMANAGE_MSG_ERR:
|
|
Packit Service |
102278 |
stream = stderr;
|
|
Packit Service |
102278 |
errsv = errno;
|
|
Packit Service |
102278 |
break;
|
|
Packit Service |
102278 |
case SEMANAGE_MSG_WARN:
|
|
Packit Service |
102278 |
stream = stderr;
|
|
Packit Service |
102278 |
break;
|
|
Packit Service |
102278 |
default:
|
|
Packit Service |
102278 |
stream = stdout;
|
|
Packit Service |
102278 |
break;
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
fprintf(stream, "%s.%s: ",
|
|
Packit Service |
102278 |
semanage_msg_get_channel(handle),
|
|
Packit Service |
102278 |
semanage_msg_get_fname(handle));
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
va_list ap;
|
|
Packit Service |
102278 |
va_start(ap, fmt);
|
|
Packit Service |
102278 |
vfprintf(stream, fmt, ap);
|
|
Packit Service |
102278 |
va_end(ap);
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
if (errsv && errsv != ENOMEM)
|
|
Packit Service |
102278 |
fprintf(stream, " (%s).", strerror(errsv));
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
fprintf(stream, "\n");
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
#ifdef __GNUC__
|
|
Packit Service |
102278 |
__attribute__ ((format(printf, 3, 4)))
|
|
Packit Service |
102278 |
#endif
|
|
Packit Service |
102278 |
void hidden semanage_msg_relay_handler(void *varg,
|
|
Packit Service |
102278 |
sepol_handle_t * sepolh,
|
|
Packit Service |
102278 |
const char *fmt, ...)
|
|
Packit Service |
102278 |
{
|
|
Packit Service |
102278 |
va_list ap;
|
|
Packit Service |
102278 |
semanage_handle_t *sh = varg;
|
|
Packit Service |
102278 |
char buffer[1024];
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
if (!sh->msg_callback)
|
|
Packit Service |
102278 |
return;
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
va_start(ap, fmt);
|
|
Packit Service |
102278 |
vsnprintf(buffer, sizeof(buffer), fmt, ap);
|
|
Packit Service |
102278 |
va_end(ap);
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
sh->msg_fname = sepol_msg_get_fname(sepolh);
|
|
Packit Service |
102278 |
sh->msg_channel = sepol_msg_get_channel(sepolh);
|
|
Packit Service |
102278 |
sh->msg_level = sepol_msg_get_level(sepolh); /* XXX should map values */
|
|
Packit Service |
102278 |
sh->msg_callback(sh->msg_callback_arg, sh, "%s", buffer);
|
|
Packit Service |
102278 |
return;
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
extern void semanage_msg_set_callback(semanage_handle_t * handle,
|
|
Packit Service |
102278 |
#ifdef __GNUC__
|
|
Packit Service |
102278 |
__attribute__ ((format(printf, 3, 4)))
|
|
Packit Service |
102278 |
#endif
|
|
Packit Service |
102278 |
void (*msg_callback) (void *varg,
|
|
Packit Service |
102278 |
semanage_handle_t *
|
|
Packit Service |
102278 |
handle,
|
|
Packit Service |
102278 |
const char *fmt,
|
|
Packit Service |
102278 |
...),
|
|
Packit Service |
102278 |
void *msg_callback_arg)
|
|
Packit Service |
102278 |
{
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
handle->msg_callback = msg_callback;
|
|
Packit Service |
102278 |
handle->msg_callback_arg = msg_callback_arg;
|
|
Packit Service |
102278 |
}
|