gssd.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Usermode daemon which assists the kernel when handling gssapi calls.
* It is gssd that actually implements all gssapi calls.
* Some calls, such as gss_sign, are implemented in the kernel on a per
* mechanism basis.
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/systeminfo.h>
#include <stdlib.h>
#include <stropts.h>
#include <fcntl.h>
#include <strings.h>
#include <signal.h>
#include <syslog.h>
#include "gssd.h"
int gssd_debug = 0; /* enable debugging printfs */
extern void gsscred_set_options(void);
void gssprog_1();
void gssd_setup(char *);
static void usage(void);
static void daemonize_start();
static void daemonize_ready(unsigned char status);
extern int svc_create_local_service();
/* following declarations needed in rpcgen-generated code */
int _rpcpmstart = 0; /* Started by a port monitor ? */
int _rpcfdtype; /* Whether Stream or Datagram ? */
int _rpcsvcdirty; /* Still serving ? */
static void
/* LINTED */
{
/* re-set the signal handler again to catch_hup, for next time */
/* mask any further signals while we're inside the handler. */
(void) sigfillset(&mask_set);
/* let admin know the sighup was caught and conf file re-read */
"catch_hup: read gsscred.conf opts");
if (gssd_debug)
"catch_hup: read gsscred.conf opts");
}
int
int argc;
char **argv;
{
int maxrecsz = RPC_MAXDATASIZE;
extern int optind;
int c;
extern int _getuid();
/* set locale and domain for internationalization */
/*
* take special note that "_getuid()" is called here. This is necessary
* since we must fake out the mechanism libraries calls to getuid()
* with a special routine that is provided as part of gssd. However,
* the call below MUST call the real getuid() to ensure it is running
* as root.
*/
#ifdef DEBUG
(void) setuid(0); /* DEBUG: set ruid to root */
#endif /* DEBUG */
if (_getuid()) {
#ifdef DEBUG
#else /* DEBUG */
exit(1);
#endif /* DEBUG */
}
gssd_setup(argv[0]);
switch (c) {
case 'd':
/* turn on debugging */
gssd_debug = 1;
break;
default:
usage();
}
usage();
}
/*
* Started by inetd if name of module just below stream
* head is either a sockmod or timod.
*/
char *netid;
netid = "ticotsord";
}
exit(1);
}
gettext("could not get the "
"right module"));
exit(1);
}
}
gettext("unable to set RPC max record size"));
exit(1);
}
/* XXX - is nconf even needed here? */
exit(1);
}
/*
* We use a NULL nconf because GSSPROG has already been
* registered with rpcbind.
*/
gettext("unable to register "
"(GSSPROG, GSSVERS)"));
exit(1);
}
if (nconf)
} else {
if (!gssd_debug)
"netpath", "gssd") == 0) {
exit(1);
}
/* service created, now the daemon parent can exit */
daemonize_ready(0);
}
if (gssd_debug) {
gettext("gssd start: \n"));
}
svc_run();
abort();
/*NOTREACHED*/
#ifdef lint
return (1);
#endif
}
static void
usage(void)
{
exit(1);
}
/*
* Fork, detach from tty, etc...
*/
static int write_pipe_fd = -1;
static
void
{
int pipe_fds[2];
unsigned char status = 1;
closefrom(0);
exit(1);
/* For daemonize_ready() */
switch (fork()) {
case -1:
exit(1);
/* NOTREACHED */
case 0:
break;
default:
/* Wait for child to be ready befor exiting */
}
(void) setsid();
}
static
void
daemonize_ready(unsigned char status)
{
if (write_pipe_fd == -1)
return;
(void) close(write_pipe_fd);
write_pipe_fd = -1;
}
/*ARGSUSED*/
int
{
return (1);
}