rpc.nispasswdd.c revision 7d1e83948cb684521e72cab96020be241508f449
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <stdlib.h> /* getenv, exit */
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <memory.h>
#include <syslog.h>
#include <stropts.h>
#include <netdir.h>
#include <synch.h>
#include <rpcsvc/yppasswd.h>
#include <rpcsvc/nispasswd.h>
#include <rpcsvc/nis_dhext.h>
#include "npd_svcsubr.h"
int verbose = 0;
/*
* generate keys if none exist or if admin. is changing another
* users password.
*/
static int __svc_priv_port_create(void);
static void set_rpc_gss_svc_names(void);
int
{
int i;
int c;
int mins;
int status;
int connmaxrec = RPC_MAXDATASIZE;
switch (c) {
case 'a':
if (max_attempts < 0) {
"%s: invalid number of maximum attempts\n",
argv[0]);
exit(1);
}
break;
case 'c':
if (mins <= 0) {
"%s: invalid cache time\n", argv[0]);
exit(1);
}
break;
case 'D': /* debug mode */
break;
case 'g': /* generate new keys if none exist */
generatekeys = TRUE;
break;
case 'v': /* verbose mode */
verbose++;
break;
case 'Y': /* YP forward mode */
exit(1);
}
break;
case '?':
"Usage: %s [-a attempts] [-c minutes] [-D] [-g] [-v]\n",
argv[0]);
exit(1);
}
}
/*
* this check should be removed if 'root' is not the
* owner of the table or if 'root' is not a member of
* the nis+ admins. group.
* of course: you also don't want someone to spoof the
* the daemon.
*/
char err_string[256];
"must be superuser to run %s", argv[0]);
exit(1);
}
if (pid < 0) {
perror("cannot fork");
exit(1);
}
if (pid)
exit(0);
closefrom(0);
(void) dup2(i, 1);
(void) dup2(i, 2);
(void) setsid();
}
/*
* should I be running ?
* Get the list of directories the local NIS+ server serves and
* check if it is the master server of any 'org_dir' listed.
*/
status);
else
status);
__msgout("exiting ...");
exit(1);
}
if (status != NIS_SUCCESS) {
if (verbose)
else
__msgout(" ... exiting ...");
exit(1);
}
/* old server */
__msgout("NIS+ server does not support the new statistics tags");
exit(1);
}
__msgout("Local NIS+ server is not a master server");
__msgout(" ... exiting ...");
exit(1);
}
/* Specify maximum connection oriented RPC record size */
__msgout("unable to set maximum RPC record size");
}
/*
* Check if NIS+ server is running in NIS compat mode.
* Register YPD only if this is the case.
*/
__msgout("unable to de-register (YPPASSWDPROG, YPPASSWDVERS)");
__msgout(" ... exiting ...");
exit(1);
}
if (__svc_priv_port_create() == FALSE) {
__msgout("unable to create (YPPASSWDPROG, YPPASSWDVERS)");
/* continue */
}
}
__msgout("unable to de-register (NISPASSWD_PROG, NISPASSWD_VERS)");
__msgout(" ... exiting ...");
exit(1);
}
"circuit_v") == 0) {
__msgout("unable to create (NISPASSWD_PROG, NISPASSWD_VERS)");
__msgout(" ... exiting ...");
exit(1);
}
__msgout("unable to de-register (NISPASSWD_PROG, NISPASSWD_VERS2)");
__msgout(" ... exiting ...");
exit(1);
}
"circuit_v") == 0) {
__msgout("unable to create (NISPASSWD_PROG, NISPASSWD_VERS2)");
__msgout(" ... exiting ...");
exit(1);
}
__msgout("starting rpc.nispasswdd ...");
svc_run();
__msgout("svc_run returned");
return (1);
}
static void
{
else
}
static bool_t
{
void *handlep;
(void) nc_perror("cannot get any transport information");
return (FALSE);
}
}
}
(void) endnetconfig(handlep);
__msgout("no NC_INET/NC_INET6 NC_TPI_CLTS/NC_UPD transports");
return (FALSE);
}
if (nconf4 != 0)
if (nconf6 != 0)
__msgout("unable to open connection for NIS requests");
(void) endnetconfig(handlep);
return (FALSE);
}
if (fd4 != -1) {
__msgout("unable to get reserved port for NC_INET");
netdir_perror("");
(void) endnetconfig(handlep);
return (FALSE);
}
}
if (fd6 != -1) {
__msgout("unable to get reserved port for NC_INET6");
netdir_perror("");
(void) endnetconfig(handlep);
return (FALSE);
}
}
__msgout("unable to create (YPPASSWDPROG, YPPASSWDVERS)");
(void) endnetconfig(handlep);
return (FALSE);
}
if (transp4 != 0)
if (transp6 != 0)
__msgout("unable to register (YPPASSWDPROG, YPPASSWDVERS)");
if (transp4 != 0)
(void) svc_destroy(transp4);
if (transp6 != 0)
(void) svc_destroy(transp6);
(void) endnetconfig(handlep);
return (FALSE);
}
(void) endnetconfig(handlep);
return (TRUE);
}
static void
{
union {
} argument;
union {
} result;
case NULLPROC:
__msgout("received NIS+ null proc call");
(void) svc_sendreply(transp,
return;
case NISPASSWD_AUTHENTICATE:
break;
case NISPASSWD_UPDATE:
break;
default:
return;
}
return;
}
(char *)&result) == 0)) {
}
__msgout("unable to free arguments");
exit(1);
}
__msgout("unable to free results");
/* NOTREACHED */
}
static void
{
union {
} argument;
union {
} result;
case NULLPROC:
__msgout("received NIS+ null proc call");
(void) svc_sendreply(transp,
return;
case NISPASSWD_AUTHENTICATE:
break;
case NISPASSWD_UPDATE:
break;
default:
return;
}
return;
}
(char *)&result) == 0)) {
}
__msgout("unable to free arguments");
exit(1);
}
__msgout("unable to free results");
/* NOTREACHED */
}
static void
{
union {
struct yppasswd yppasswdproc_update_1_arg;
} argument;
union {
} result;
#ifdef SHD_WE_ALWAYS
#endif
case NULLPROC:
__msgout("received NIS null proc call");
(void) svc_sendreply(transp,
return;
case YPPASSWDPROC_UPDATE:
break;
default:
return;
}
#ifdef SHD_WE_ALWAYS
/*
* update request received, lets just check the port
*/
(void) nc_perror("could not get transport information");
return;
}
if (nconf)
(void) freenetconfigent(nconf);
return;
}
if (nconf)
(void) freenetconfigent(nconf);
#endif
return;
}
(char *)&result)) {
}
__msgout("unable to free arguments");
exit(1);
}
}
/*
* Loop thru mech list from security conf file and set
* the RPC GSS service name(s). Stop processing list if
* the classic AUTH_DES compat entry is encountered.
*/
static void
{
mechanism_t **mechs;
mechanism_t **mpp;
/* "nispasswd" + 1 = 10 */
int slen;
char *lh = nis_local_host();
if (! lh) {
"can't set RPC GSS service name: can't get local host name");
return;
}
/* '@' + NUL = 2 */
sizeof (svc_name)) {
"can't set RPC GSS service name: svc_name bufsize too small");
return;
}
/* service names are of the form svc@server.dom */
/* remove trailing '.' */
if (AUTH_DES_COMPAT_CHK(mp))
break;
if (! VALID_MECH_ENTRY(mp))
continue;
0, NISPASSWD_PROG,
if (val) {
if (verbose)
"RPC GSS service name for mechanism '%s' set",
} else {
"can't set RPC GSS svc name '%s'"
"for mech '%s': RPC GSS err = %d,"
"sys err = %d",
}
0, NISPASSWD_PROG,
if (val) {
if (verbose)
"RPC GSS service name for mechanism '%s' set",
} else {
"can't set RPC GSS svc name '%s'"
"for mech '%s': RPC GSS err = %d,"
"sys err = %d",
}
}
return;
}
}