mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-18 17:00:49 +01:00
76064c01e5
In ypserv: yp_svc.c: - small signal handler tweak (hopefully the last): just use sigemptyset() to clear sa_mask. Makefile.yp: - Let the user specify the location of master.passwd when updating maps (e.g. make MASTER_PASSWD=/some/path/to/master.passwd). Editing the file to change the location of master.passwd still works. This is mostly to let yppassswdd specify the name of the master.passwd file itself. In yppasswdd: yppasswdd.c: - Roll in some minor changes (mostly casts) from Olaf Kirch's latest yppasswd package release (version 0.7). - Use daemon() instead of doing all the deamonizing gruntwork ourselves. - Call pw_init() after daemonizing ourselves. pw_init() sets up some resource limits and blocks some signals for us. We used to do this before every password change, but there's really no point in calling it more than once during the life of the program. - Change install_reaper() so that we can use it to de-install the SIGCHLD handler if we need to (and we do in pw_mkdb() -- this is what I get for splicing code from two different programs together). - Use sigemptyset(&act.sa_mask) rather than act.sa_mask = 0: the latter is decidedly non-portable. (In IRIX, HP-UX and Solaris, sigset_t is an array of longs, not an int.) update.c: - Roll in change from new version (check that we're not modifying an NIS entry in validate_args()). - Get rid of call to pw_init() (moved to yppasswdd.c). - Check return values from pw_util routines and return error status to yppasswd clients if there's a problem. - Straighten out password file copying mechanism a little. Keep a grip on the original password file rather than summarily overwriting it so that we can restore everything if we fail to fork() a process to update the NIS maps. - Pass the name of the password template file (specified with -m or /etc/master.passwd by default) to the yppwupdate script, which in turn should now pass it to /var/yp/Makefile. pw_util.c: - Nuke the pw_edit() and pw_prompt() functions -- we don't need them. - Change all warn()s, warnx()s and err()s to syslog()s. - Make sure we return error status to caller rather than bailing out in pw_lock() and pw_tmp(). - Don't block SIGTERM in pw_init() (by ignoring SIGTERM, we prevent yppasswdd from being shut down cleanly). - Don't let pw_error() exit. (This stuff was stolen from chpass and vipw which are interactive programs; it's okay to let pw_error() bail out for these programs, but not in a daemon like yppasswdd). - Fix signal handling in pw_mkdb (we need to temporarily de-install the SIGCHLD handler so that we can wait on the pwd_mkdb child ourselves). pw_copy.c: - Change all warn()s, warnx()s and err()s to syslog()s. - Add a bunch of returns() and make pw_copy() return and int ( 0 on success, -1 on failure) so that update.c can flag errors properly. - Return -1 after calling pw_error() to signal failures rather than relying on pw_error() to bail out. - Abort copying if we discover that we've been asked to change an entry for a user that exists in the NIS passwd maps but not in the master.passwd template file. This can happen if the passwd maps and the template file fall out of sync with each other (or if somebody tries to spoof us). The old behavior was to create add the entry to the password file, which yppasswdd should not do under any circumstances. Makefile: - update VERSION to 0.7 yppasswdd.8: - fix typo (forgot a carriage return somewhere) - remove bogus reference to pwunconv(8) which FreeBSD doesn't have. - bump version from 0.5 to 0.7 - Reflect changes in password file handling. yppwupdate: - Log map rebuilds to /var/yp/ypupdate.log. - Pass the name of the template password file to /var/yp/Makefile as $MASTER_PASSWD.
202 lines
4.3 KiB
C
202 lines
4.3 KiB
C
/*
|
|
* yppasswdd
|
|
* Copyright 1994 Olaf Kirch, <okir@monad.swb.de>
|
|
*
|
|
* This program is covered by the GNU General Public License, version 2.
|
|
* It is provided in the hope that it is useful. However, the author
|
|
* disclaims ALL WARRANTIES, expressed or implied. See the GPL for details.
|
|
*/
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/errno.h>
|
|
#include <sys/ioctl.h>
|
|
#include <sys/wait.h>
|
|
#include <termios.h>
|
|
#include <signal.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
#include <syslog.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <pwd.h>
|
|
|
|
#include <rpc/rpc.h>
|
|
#include <rpc/pmap_clnt.h>
|
|
#include "yppasswd.h"
|
|
|
|
extern char *optarg;
|
|
extern void pw_init __P((void));
|
|
static char *program_name = "";
|
|
static char *version = "yppsswdd " VERSION;
|
|
char *passfile = _PATH_MASTERPASSWD;
|
|
int allow_chfn = 0, allow_chsh = 0;
|
|
|
|
#define xprt_addr(xprt) (svc_getcaller(xprt)->sin_addr)
|
|
#define xprt_port(xprt) ntohs(svc_getcaller(xprt)->sin_port)
|
|
void yppasswdprog_1( struct svc_req *rqstp, SVCXPRT *transp );
|
|
void reaper( int sig );
|
|
|
|
/*==============================================================*
|
|
* RPC dispatch function
|
|
*==============================================================*/
|
|
void
|
|
yppasswdprog_1(struct svc_req *rqstp, SVCXPRT *transp)
|
|
{
|
|
union {
|
|
yppasswd yppasswdproc_update_1_arg;
|
|
} argument;
|
|
char *result;
|
|
xdrproc_t xdr_argument, xdr_result;
|
|
char *(*local)();
|
|
|
|
switch (rqstp->rq_proc) {
|
|
case NULLPROC:
|
|
(void)svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL);
|
|
return;
|
|
|
|
case YPPASSWDPROC_UPDATE:
|
|
xdr_argument = (xdrproc_t) xdr_yppasswd;
|
|
xdr_result = (xdrproc_t) xdr_int;
|
|
local = (char *(*)()) yppasswdproc_pwupdate_1;
|
|
break;
|
|
|
|
default:
|
|
svcerr_noproc(transp);
|
|
return;
|
|
}
|
|
bzero((char *)&argument, sizeof(argument));
|
|
if (!svc_getargs(transp, xdr_argument, &argument)) {
|
|
svcerr_decode(transp);
|
|
return;
|
|
}
|
|
result = (*local)(&argument, rqstp);
|
|
if (result != NULL
|
|
&& !svc_sendreply(transp, (xdrproc_t)xdr_result, result)) {
|
|
svcerr_systemerr(transp);
|
|
}
|
|
if (!svc_freeargs(transp, xdr_argument, &argument)) {
|
|
(void)fprintf(stderr, "unable to free arguments\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
static void
|
|
usage(FILE *fp, int n)
|
|
{
|
|
fprintf (fp, "usage: %s [-m master password file] [-f] [-s] [-h] [-v]\n", program_name );
|
|
exit(n);
|
|
}
|
|
|
|
void
|
|
reaper( int sig )
|
|
{
|
|
extern pid_t pid;
|
|
extern int pstat;
|
|
|
|
pid = waitpid(pid, &pstat, 0);
|
|
}
|
|
|
|
void
|
|
install_reaper( int on )
|
|
{
|
|
struct sigaction act, oact;
|
|
|
|
if (on) {
|
|
act.sa_handler = reaper;
|
|
sigemptyset(&act.sa_mask);
|
|
act.sa_flags = SA_RESTART;
|
|
} else {
|
|
act.sa_handler = SIG_DFL;
|
|
sigemptyset(&act.sa_mask);
|
|
act.sa_flags = SA_RESTART;
|
|
}
|
|
sigaction( SIGCHLD, &act, &oact );
|
|
}
|
|
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
SVCXPRT *transp;
|
|
char *sp;
|
|
int opterr;
|
|
int c;
|
|
|
|
program_name = argv[0];
|
|
if ((sp = strrchr(program_name, '/')) != NULL) {
|
|
program_name = ++sp;
|
|
}
|
|
|
|
/* Parse the command line options and arguments. */
|
|
opterr = 0;
|
|
while ((c = getopt(argc, argv, "m:fshv")) != EOF)
|
|
switch (c) {
|
|
case 'm':
|
|
passfile = strdup(optarg);
|
|
break;
|
|
case 'f':
|
|
allow_chfn = 1;
|
|
break;
|
|
case 's':
|
|
allow_chsh = 1;
|
|
break;
|
|
case 'h':
|
|
usage (stdout, 0);
|
|
break;
|
|
case 'v':
|
|
printf("%s\n", version);
|
|
exit(0);
|
|
case 0:
|
|
break;
|
|
case '?':
|
|
default:
|
|
usage(stderr, 1);
|
|
}
|
|
|
|
if (daemon(0,0)) {
|
|
perror("fork");
|
|
exit(1);
|
|
}
|
|
|
|
/*
|
|
* We can call this here since it does some necessary setup
|
|
* for us (blocking signals, setting resourse limits, etc.
|
|
*/
|
|
pw_init();
|
|
|
|
/* Initialize logging.
|
|
*/
|
|
openlog ( "yppasswdd", LOG_PID, LOG_AUTH );
|
|
|
|
/* Register a signal handler to reap children after they terminated
|
|
*/
|
|
install_reaper(1);
|
|
|
|
/*
|
|
* Create the RPC server
|
|
*/
|
|
(void)pmap_unset(YPPASSWDPROG, YPPASSWDVERS);
|
|
|
|
transp = svcudp_create(RPC_ANYSOCK);
|
|
if (transp == NULL) {
|
|
(void)fprintf(stderr, "cannot create udp service.\n");
|
|
exit(1);
|
|
}
|
|
if (!svc_register(transp, YPPASSWDPROG, YPPASSWDVERS, yppasswdprog_1,
|
|
IPPROTO_UDP)) {
|
|
(void)fprintf(stderr, "unable to register yppaswdd udp service.\n");
|
|
exit(1);
|
|
}
|
|
|
|
/*
|
|
* Run the server
|
|
*/
|
|
svc_run();
|
|
(void)fprintf(stderr, "svc_run returned\n");
|
|
|
|
return 1;
|
|
}
|
|
|