Skip to content

Commit

Permalink
Make shadow_logfd and Prog not extern
Browse files Browse the repository at this point in the history
Closes #444
Closes #465

Signed-off-by: Serge Hallyn <[email protected]>
  • Loading branch information
hallyn committed Dec 23, 2021
1 parent b8c67c3 commit 79157cb
Show file tree
Hide file tree
Showing 79 changed files with 371 additions and 217 deletions.
2 changes: 2 additions & 0 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ libshadow_la_SOURCES = \
nss.c \
nscd.c \
nscd.h \
shadowlog.c \
shadowlog.h \
sssd.c \
sssd.h \
pam_defs.h \
Expand Down
1 change: 1 addition & 0 deletions lib/commonio.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#endif /* WITH_TCB */
#include "prototypes.h"
#include "commonio.h"
#include "shadowlog_internal.h"

/* local function prototypes */
static int lrename (const char *, const char *);
Expand Down
1 change: 1 addition & 0 deletions lib/encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include "prototypes.h"
#include "defines.h"
#include "shadowlog_internal.h"

/*@exposed@*//*@null@*/char *pw_encrypt (const char *clear, const char *salt)
{
Expand Down
1 change: 1 addition & 0 deletions lib/getdef.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <libeconf.h>
#endif
#include "getdef.h"
#include "shadowlog_internal.h"
/*
* A configuration item definition.
*/
Expand Down
1 change: 1 addition & 0 deletions lib/nscd.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "defines.h"
#include "prototypes.h"
#include "nscd.h"
#include "shadowlog_internal.h"

#define MSG_NSCD_FLUSH_CACHE_FAILED "%s: Failed to flush the nscd cache.\n"

Expand Down
1 change: 1 addition & 0 deletions lib/nss.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdatomic.h>
#include "prototypes.h"
#include "../libsubid/subid.h"
#include "shadowlog_internal.h"

#define NSSWITCH "/etc/nsswitch.conf"

Expand Down
3 changes: 0 additions & 3 deletions lib/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@
#include "defines.h"
#include "commonio.h"

extern /*@observer@*/ const char *Prog; /* Program name showed in error messages */
extern FILE *shadow_logfd; /* file descripter to which error messages are printed */

/* addgrps.c */
#if defined (HAVE_SETGROUPS) && ! defined (USE_PAM)
extern int add_groups (const char *);
Expand Down
1 change: 1 addition & 0 deletions lib/run_part.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <sys/wait.h>
#include <unistd.h>
#include <lib/prototypes.h>
#include "shadowlog_internal.h"

int run_part (char *script_path, char *name, char *action)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/selinux.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <selinux/label.h>
#include "prototypes.h"

#include "shadowlog_internal.h"

static bool selinux_checked = false;
static bool selinux_enabled;
static /*@null@*/struct selabel_handle *selabel_hnd = NULL;
Expand Down
1 change: 1 addition & 0 deletions lib/semanage.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <semanage/semanage.h>
#include "prototypes.h"

#include "shadowlog_internal.h"

#ifndef DEFAULT_SERANGE
#define DEFAULT_SERANGE "s0"
Expand Down
28 changes: 28 additions & 0 deletions lib/shadowlog.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "shadowlog.h"

#include "lib/shadowlog_internal.h"

void log_set_progname(const char *progname)
{
Prog = progname;
}

const char *log_get_progname(void)
{
return Prog;
}

void log_set_logfd(FILE *fd)
{
if (NULL != fd)
shadow_logfd = fd;
else
shadow_logfd = stderr;
}

FILE *log_get_logfd(void)
{
if (shadow_logfd != NULL)
return shadow_logfd;
return stderr;
}
41 changes: 41 additions & 0 deletions lib/shadowlog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2021 , Serge Hallyn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the copyright holders or contributors may not be used to
* endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/* $Id$ */
#ifndef _LOG_H
#define _LOG_H
#include <stdio.h>

extern void log_set_progname(const char *);
extern const char *log_get_progname(void);
extern void log_set_logfd(FILE *fd);
extern FILE *log_get_logfd(void);
extern void log_dolog(char *, ...);

#endif
2 changes: 2 additions & 0 deletions lib/shadowlog_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const char *Prog; /* Program name showed in error messages */
FILE *shadow_logfd; /* file descripter to which error messages are printed */
2 changes: 2 additions & 0 deletions lib/spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "exitcodes.h"
#include "prototypes.h"

#include "shadowlog_internal.h"

int run_command (const char *cmd, const char *argv[],
/*@null@*/const char *envp[], /*@out@*/int *status)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/sssd.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "prototypes.h"
#include "sssd.h"

#include "shadowlog_internal.h"

#define MSG_SSSD_FLUSH_CACHE_FAILED "%s: Failed to flush the sssd cache."

int sssd_flush_cache (int dbflags)
Expand Down
2 changes: 2 additions & 0 deletions lib/tcbfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "shadowio.h"
#include "tcbfuncs.h"

#include "shadowlog_internal.h"

#define SHADOWTCB_HASH_BY 1000
#define SHADOWTCB_LOCK_SUFFIX ".lock"

Expand Down
2 changes: 2 additions & 0 deletions libmisc/addgrps.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <stdio.h>
#include <grp.h>
#include <errno.h>
#include "shadowlog.h"

#ident "$Id$"

Expand All @@ -58,6 +59,7 @@ int add_groups (const char *list)
char *token;
char buf[1024];
int ret;
FILE *shadow_logfd = log_get_logfd();

if (strlen (list) >= sizeof (buf)) {
errno = EINVAL;
Expand Down
3 changes: 2 additions & 1 deletion libmisc/audit_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <errno.h>
#include <stdio.h>
#include "prototypes.h"
#include "shadowlog.h"
int audit_fd;

void audit_help_open (void)
Expand All @@ -59,7 +60,7 @@ void audit_help_open (void)
return;
}
(void) fputs (_("Cannot open audit interface - aborting.\n"),
shadow_logfd);
log_get_logfd());
exit (EXIT_FAILURE);
}
}
Expand Down
2 changes: 2 additions & 0 deletions libmisc/chowntty.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "defines.h"
#include <pwd.h>
#include "getdef.h"
#include "shadowlog.h"

/*
* chown_tty() sets the login tty to be owned by the new user ID
Expand Down Expand Up @@ -75,6 +76,7 @@ void chown_tty (const struct passwd *info)
if ( (fchown (STDIN_FILENO, info->pw_uid, gid) != 0)
|| (fchmod (STDIN_FILENO, (mode_t)getdef_num ("TTYPERM", 0600)) != 0)) {
int err = errno;
FILE *shadow_logfd = log_get_logfd();

fprintf (shadow_logfd,
_("Unable to change owner or mode of tty stdin: %s"),
Expand Down
25 changes: 13 additions & 12 deletions libmisc/cleanup_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "groupio.h"
#include "sgroupio.h"
#include "prototypes.h"
#include "shadowlog.h"

/*
* cleanup_report_add_group - Report failure to add a group to the system
Expand All @@ -48,7 +49,7 @@ void cleanup_report_add_group (void *group_name)

SYSLOG ((LOG_ERR, "failed to add group %s", name));
#ifdef WITH_AUDIT
audit_logger (AUDIT_ADD_GROUP, Prog,
audit_logger (AUDIT_ADD_GROUP, log_get_progname(),
"",
name, AUDIT_NO_ID,
SHADOW_AUDIT_FAILURE);
Expand All @@ -66,7 +67,7 @@ void cleanup_report_del_group (void *group_name)

SYSLOG ((LOG_ERR, "failed to remove group %s", name));
#ifdef WITH_AUDIT
audit_logger (AUDIT_DEL_GROUP, Prog,
audit_logger (AUDIT_DEL_GROUP, log_get_progname(),
"",
name, AUDIT_NO_ID,
SHADOW_AUDIT_FAILURE);
Expand All @@ -83,7 +84,7 @@ void cleanup_report_mod_group (void *cleanup_info)
gr_dbname (),
info->action));
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_ACCT, Prog,
audit_logger (AUDIT_USER_ACCT, log_get_progname(),
info->audit_msg,
info->name, AUDIT_NO_ID,
SHADOW_AUDIT_FAILURE);
Expand All @@ -101,7 +102,7 @@ void cleanup_report_mod_gshadow (void *cleanup_info)
sgr_dbname (),
info->action));
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_ACCT, Prog,
audit_logger (AUDIT_USER_ACCT, log_get_progname(),
info->audit_msg,
info->name, AUDIT_NO_ID,
SHADOW_AUDIT_FAILURE);
Expand All @@ -121,7 +122,7 @@ void cleanup_report_add_group_group (void *group_name)

SYSLOG ((LOG_ERR, "failed to add group %s to %s", name, gr_dbname ()));
#ifdef WITH_AUDIT
audit_logger (AUDIT_ADD_GROUP, Prog,
audit_logger (AUDIT_ADD_GROUP, log_get_progname(),
"adding group to /etc/group",
name, AUDIT_NO_ID,
SHADOW_AUDIT_FAILURE);
Expand All @@ -141,7 +142,7 @@ void cleanup_report_add_group_gshadow (void *group_name)

SYSLOG ((LOG_ERR, "failed to add group %s to %s", name, sgr_dbname ()));
#ifdef WITH_AUDIT
audit_logger (AUDIT_ADD_GROUP, Prog,
audit_logger (AUDIT_ADD_GROUP, log_get_progname(),
"adding group to /etc/gshadow",
name, AUDIT_NO_ID,
SHADOW_AUDIT_FAILURE);
Expand All @@ -164,7 +165,7 @@ void cleanup_report_del_group_group (void *group_name)
"failed to remove group %s from %s",
name, gr_dbname ()));
#ifdef WITH_AUDIT
audit_logger (AUDIT_ADD_GROUP, Prog,
audit_logger (AUDIT_ADD_GROUP, log_get_progname(),
"removing group from /etc/group",
name, AUDIT_NO_ID,
SHADOW_AUDIT_FAILURE);
Expand All @@ -187,7 +188,7 @@ void cleanup_report_del_group_gshadow (void *group_name)
"failed to remove group %s from %s",
name, sgr_dbname ()));
#ifdef WITH_AUDIT
audit_logger (AUDIT_ADD_GROUP, Prog,
audit_logger (AUDIT_ADD_GROUP, log_get_progname(),
"removing group from /etc/gshadow",
name, AUDIT_NO_ID,
SHADOW_AUDIT_FAILURE);
Expand All @@ -203,9 +204,9 @@ void cleanup_report_del_group_gshadow (void *group_name)
void cleanup_unlock_group (unused void *arg)
{
if (gr_unlock () == 0) {
fprintf (shadow_logfd,
fprintf (log_get_logfd(),
_("%s: failed to unlock %s\n"),
Prog, gr_dbname ());
log_get_progname(), gr_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
#ifdef WITH_AUDIT
audit_logger_message ("unlocking group file",
Expand All @@ -223,9 +224,9 @@ void cleanup_unlock_group (unused void *arg)
void cleanup_unlock_gshadow (unused void *arg)
{
if (sgr_unlock () == 0) {
fprintf (shadow_logfd,
fprintf (log_get_logfd(),
_("%s: failed to unlock %s\n"),
Prog, sgr_dbname ());
log_get_progname(), sgr_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ()));
#ifdef WITH_AUDIT
audit_logger_message ("unlocking gshadow file",
Expand Down
Loading

0 comments on commit 79157cb

Please sign in to comment.