4 Copyright (c) 2000 The Regents of the University of Michigan.
7 Copyright (c) 2000 Dug Song <dugsong@UMICH.EDU>.
8 Copyright (c) 2002 Andy Adamson <andros@UMICH.EDU>.
9 Copyright (c) 2002 Marius Aamodt Eriksen <marius@UMICH.EDU>.
10 All rights reserved, all wrongs reversed.
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions
16 1. Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18 2. Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
21 3. Neither the name of the University nor the names of its
22 contributors may be used to endorse or promote products derived
23 from this software without specific prior written permission.
25 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <sys/types.h>
42 #include <sys/param.h>
43 #include <sys/socket.h>
58 #include "krb5_util.h"
61 char pipefs_dir[PATH_MAX] = GSSD_PIPEFS_DIR;
62 char pipefs_nfsdir[PATH_MAX] = GSSD_PIPEFS_DIR;
63 char keytabfile[PATH_MAX] = GSSD_DEFAULT_KEYTAB_FILE;
64 char ccachedir[PATH_MAX] = GSSD_DEFAULT_CRED_DIR;
66 int lgssd_mutex_downcall = -1;
68 static int lgssd_create_mutex(int *semid)
73 id = semget(IPC_PRIVATE, 1, IPC_CREAT);
75 printerr(0, "semget: %s\n", strerror(errno));
80 if (semctl(id, 0, SETVAL, arg) != 0) {
81 printerr(0, "semctl: %s\n", strerror(errno));
82 semctl(id, 1, IPC_RMID, arg);
90 void lgssd_init_mutexs(void)
92 if (lgssd_create_mutex(&lgssd_mutex_downcall)) {
93 printerr(0, "can't create downcall mutex\n");
98 void lgssd_fini_mutexs(void)
102 if (lgssd_mutex_downcall != -1)
103 semctl(lgssd_mutex_downcall, 1, IPC_RMID, arg);
106 void lgssd_mutex_get(int semid)
108 struct sembuf op[1] = { {0, -1, SEM_UNDO} };
111 rc = semop(semid, op, 1);
113 printerr(0, "exit on mutex_get err %d: %s\n",
114 rc, strerror(errno));
119 void lgssd_mutex_put(int semid)
121 struct sembuf op[1] = { {0, 1, 0} };
124 rc = semop(semid, op, 1);
126 printerr(0, "ignore mutex_put err %d: %s\n",
127 rc, strerror(errno));
131 static void lgssd_cleanup(void)
135 /* make sure all children finished */
137 child_pid = waitpid(-1, NULL, 0);
141 printerr(3, "cleanup: child %d terminated\n", child_pid);
146 /* destroy krb5 machine creds */
147 gssd_destroy_krb5_machine_creds();
153 printerr(1, "exiting on signal %d\n", signal);
161 /* don't exit on SIGHUP */
162 printerr(1, "Received SIGHUP... Ignoring.\n");
167 usage(char *progname)
169 fprintf(stderr, "usage: %s [-f] [-v] [-p pipefsdir] [-k keytab] [-d ccachedir]\n",
175 main(int argc, char *argv[])
183 while ((opt = getopt(argc, argv, "fvrmMp:k:d:")) != -1) {
195 strncpy(pipefs_dir, optarg, sizeof(pipefs_dir));
196 if (pipefs_dir[sizeof(pipefs_dir)-1] != '\0')
197 errx(1, "pipefs path name too long");
200 strncpy(keytabfile, optarg, sizeof(keytabfile));
201 if (keytabfile[sizeof(keytabfile)-1] != '\0')
202 errx(1, "keytab path name too long");
205 strncpy(ccachedir, optarg, sizeof(ccachedir));
206 if (ccachedir[sizeof(ccachedir)-1] != '\0')
207 errx(1, "ccachedir path name too long");
215 if ((progname = strrchr(argv[0], '/')))
220 initerr(progname, verbosity, fg);
222 if (gssd_check_mechs() != 0)
223 errx(1, "Problem with gssapi library");
225 if (gssd_get_local_realm())
226 errx(1, "get local realm");
228 if (!fg && daemon(0, 0) < 0)
231 /* This should be checked _after_ daemon(), because we need to own
232 * the undo-able semaphore by this process
234 gssd_init_unique(GSSD_CLI);
236 /* Process keytab file and get machine credentials. This will modify
237 * disk status so do it after we are sure we are the only instance
239 if (gssd_refresh_krb5_machine_creds())
242 signal(SIGINT, sig_die);
243 signal(SIGTERM, sig_die);
244 signal(SIGHUP, sig_hup);
247 /* Determine Kerberos information from the kernel */
248 gssd_obtain_kernel_krb5_info();
253 printerr(0, "lgssd initialized and ready to serve\n");
257 printerr(0, "lgssd exiting\n");