idmapd.c revision 651c0131ccc65381cbda174bee44a4fd7a518d6b
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* main() of idmapd(1M)
*/
#include "idmapd.h"
#include <signal.h>
#include <string.h> /* strcmp */
#include <unistd.h> /* setsid */
#include <memory.h>
#include <stropts.h>
#include <netconfig.h>
#include <syslog.h>
#include <priv_utils.h> /* privileges */
#include <locale.h>
#include <sys/systeminfo.h>
#include <errno.h>
#include <zone.h>
#include <door.h>
#include <sys/resource.h>
static void hup_handler(int);
static void term_handler(int);
static void init_idmapd();
static void fini_idmapd();
#ifndef SIG_PF
#define SIG_PF void(*)(int)
#endif
#define _RPCSVC_CLOSEDOWN 120
int _rpcsvccount = 0; /* Number of requests being serviced */
#ifdef DEBUG
#define RPC_SVC_FG
#endif
/*
* This is needed for mech_krb5 -- we run as daemon, yes, but we want
* mech_krb5 to think we're root.
*
* someday we'll have extensions to libldap to pass those through to
* libsasl. Until then this interposer will have to do.
*
* Also, we have to tell lint to shut up: it thinks app_krb5_user_uid()
* is defined but not used.
*/
/*LINTLIBRARY*/
app_krb5_user_uid(void)
{
return (0);
}
static void
}
/*ARGSUSED*/
static void
hup_handler(int sig) {
if (load_config() < 0) {
(void) idmapdlog(LOG_NOTICE,
"idmapd: Failed to reload config");
}
}
/*ARGSUSED*/
static void
term_handler(int sig) {
fini_idmapd();
_exit(0);
}
static int pipe_fd = -1;
static void
daemonize_ready(void) {
char data = '\0';
/*
* wake the parent
*/
}
static int
daemonize_start(void) {
char data;
int status;
int devnull;
int filedes[2];
if (devnull < 0)
return (-1);
return (-1);
return (-1);
if (pid != 0) {
/*
* parent
*/
/* presume success */
_exit(0);
}
status = -1;
else
_exit(-1);
}
/*
* child
*/
(void) setsid();
(void) umask(0077);
return (0);
}
int
{
int c;
#ifdef RPC_SVC_FG
#else
#endif
switch (c) {
case 'd':
break;
default:
break;
}
}
/* set locale and domain for internationalization */
(void) textdomain(TEXT_DOMAIN);
"idmapd: With TX, idmapd runs only in the global zone");
exit(1);
}
/* create directories as root and chown to daemon uid */
exit(1);
exit(1);
if (daemonize_start() < 0) {
(void) perror("idmapd: unable to daemonize");
exit(-1);
}
} else
(void) umask(0077);
init_idmapd();
(char *)NULL) == -1) {
exit(1);
}
/* With doors RPC this just wastes this thread, oh well */
svc_run();
return (0);
}
static void
init_idmapd() {
int error;
"idmapd: unable to determine hostname, error: %d",
error);
exit(1);
}
"idmapd: unable to determine name service domain, error: %d",
error);
exit(1);
}
if (init_mapping_system() < 0) {
"idmapd: unable to initialize mapping system");
exit(1);
}
seteuid(0);
setegid(0);
"idmapd: unable to create door RPC service");
goto errout;
}
if (dfd == -1) {
goto errout;
}
goto errout;
}
} else {
}
return;
fini_idmapd();
exit(1);
}
static void
fini_idmapd() {
}
void
}
}