4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Usermode daemon which assists the kernel when handling gssapi calls.
30 * It is gssd that actually implements all gssapi calls.
31 * Some calls, such as gss_sign, are implemented in the kernel on a per
37 #include <rpc/rpc_com.h>
38 #include <sys/syslog.h>
39 #include <sys/termios.h>
41 #include <sys/utsname.h>
42 #include <sys/systeminfo.h>
51 int gssd_debug
= 0; /* enable debugging printfs */
52 extern void gsscred_set_options(void);
55 void gssd_setup(char *);
56 static void usage(void);
57 static void daemonize_start();
58 static void daemonize_ready(unsigned char status
);
59 extern int svc_create_local_service();
61 /* following declarations needed in rpcgen-generated code */
62 int _rpcpmstart
= 0; /* Started by a port monitor ? */
63 int _rpcfdtype
; /* Whether Stream or Datagram ? */
64 int _rpcsvcdirty
; /* Still serving ? */
69 catch_hup(int sig_num
)
71 sigset_t mask_set
; /* used to set a signal masking set. */
72 sigset_t old_set
; /* used to store the old mask set. */
74 /* re-set the signal handler again to catch_hup, for next time */
75 (void) signal(SIGHUP
, catch_hup
);
76 /* mask any further signals while we're inside the handler. */
77 (void) sigfillset(&mask_set
);
78 (void) sigprocmask(SIG_SETMASK
, &mask_set
, &old_set
);
80 gsscred_set_options();
82 /* let admin know the sighup was caught and conf file re-read */
84 "catch_hup: read gsscred.conf opts");
86 (void) fprintf(stderr
,
87 "catch_hup: read gsscred.conf opts");
89 (void) sigprocmask(SIG_SETMASK
, &old_set
, NULL
);
98 register SVCXPRT
*transp
;
99 int maxrecsz
= RPC_MAXDATASIZE
;
102 char mname
[FMNAMESZ
+ 1];
104 /* set locale and domain for internationalization */
105 setlocale(LC_ALL
, "");
106 textdomain(TEXT_DOMAIN
);
110 * Take special note that "getuid()" is called here. This call is used
111 * rather than app_krb5_user_uid(), to ensure gssd(8) is running as
115 (void) setuid(0); /* DEBUG: set ruid to root */
118 (void) fprintf(stderr
,
119 gettext("[%s] must be run as root\n"), argv
[0]);
121 (void) fprintf(stderr
, gettext(" warning only\n"));
129 while ((c
= getopt(argc
, argv
, "d")) != -1)
132 /* turn on debugging */
139 if (optind
!= argc
) {
143 gsscred_set_options();
144 (void) signal(SIGHUP
, catch_hup
);
147 * Started by inetd if name of module just below stream
148 * head is either a sockmod or timod.
150 if (!ioctl(0, I_LOOK
, mname
) &&
151 ((strcmp(mname
, "sockmod") == 0) ||
152 (strcmp(mname
, "timod") == 0))) {
155 struct netconfig
*nconf
;
157 openlog("gssd", LOG_PID
, LOG_DAEMON
);
159 if ((netid
= getenv("NLSPROVIDER")) == NULL
) {
163 if ((nconf
= getnetconfigent(netid
)) == NULL
) {
164 syslog(LOG_ERR
, gettext("cannot get transport info"));
168 if (strcmp(mname
, "sockmod") == 0) {
169 if (ioctl(0, I_POP
, 0) || ioctl(0, I_PUSH
, "timod")) {
171 gettext("could not get the "
176 if (!rpc_control(RPC_SVC_CONNMAXREC_SET
, &maxrecsz
)) {
178 gettext("unable to set RPC max record size"));
181 /* XXX - is nconf even needed here? */
182 if ((transp
= svc_tli_create(0, nconf
, NULL
, 0, 0)) == NULL
) {
183 syslog(LOG_ERR
, gettext("cannot create server handle"));
188 * We use a NULL nconf because GSSPROG has already been
189 * registered with rpcbind.
191 if (!svc_reg(transp
, GSSPROG
, GSSVERS
, gssprog_1
, NULL
)) {
193 gettext("unable to register "
194 "(GSSPROG, GSSVERS)"));
199 freenetconfigent(nconf
);
204 openlog("gssd", LOG_PID
, LOG_DAEMON
);
206 if (svc_create_local_service(gssprog_1
, GSSPROG
, GSSVERS
,
207 "netpath", "gssd") == 0) {
208 syslog(LOG_ERR
, gettext("unable to create service"));
212 /* service created, now the daemon parent can exit */
219 gettext("gssd start: \n"));
229 (void) fprintf(stderr
, gettext("usage: gssd [-dg]\n"));
235 * Fork, detach from tty, etc...
237 static int write_pipe_fd
= -1;
243 unsigned char status
= 1;
247 /* Open stdin/out/err, chdir, get a pipe */
248 if (open("/dev/null", O_RDONLY
) < 0 ||
249 open("/dev/null", O_WRONLY
) < 0 || dup(1) < 0 ||
250 chdir("/") < 0 || pipe(pipe_fds
) < 0)
253 /* For daemonize_ready() */
254 write_pipe_fd
= pipe_fds
[1];
263 /* Wait for child to be ready befor exiting */
264 (void) close(pipe_fds
[1]);
265 (void) signal(SIGPIPE
, SIG_DFL
);
266 (void) read(pipe_fds
[0], &status
, sizeof (status
));
270 (void) close(pipe_fds
[0]);
276 daemonize_ready(unsigned char status
)
278 if (write_pipe_fd
== -1)
281 (void) write(write_pipe_fd
, &status
, sizeof (status
));
282 (void) close(write_pipe_fd
);
288 gssprog_1_freeresult(SVCXPRT
*transport
, xdrproc_t xdr_res
, caddr_t res
)
290 xdr_free(xdr_res
, res
);