]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/gssd/gssd.c
The default expiration of kernel gss contexts is the expiration
[nfs-utils.git] / utils / gssd / gssd.c
1 /*
2   gssd.c
3
4   Copyright (c) 2000 The Regents of the University of Michigan.
5   All rights reserved.
6
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.
11
12   Redistribution and use in source and binary forms, with or without
13   modification, are permitted provided that the following conditions
14   are met:
15
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.
24
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.
36
37 */
38
39 #include "config.h"
40
41 #include <sys/param.h>
42 #include <sys/socket.h>
43 #include <rpc/rpc.h>
44
45 #include <unistd.h>
46 #include <err.h>
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <string.h>
50 #include <signal.h>
51 #include "gssd.h"
52 #include "err_util.h"
53 #include "gss_util.h"
54 #include "krb5_util.h"
55
56 char pipefs_dir[PATH_MAX] = GSSD_PIPEFS_DIR;
57 char pipefs_nfsdir[PATH_MAX] = GSSD_PIPEFS_DIR;
58 char keytabfile[PATH_MAX] = GSSD_DEFAULT_KEYTAB_FILE;
59 char ccachedir[PATH_MAX] = GSSD_DEFAULT_CRED_DIR;
60 char *ccachesearch[GSSD_MAX_CCACHE_SEARCH + 1];
61 int  use_memcache = 0;
62 int  root_uses_machine_creds = 1;
63 unsigned int  context_timeout = 0;
64
65 void
66 sig_die(int signal)
67 {
68         /* destroy krb5 machine creds */
69         if (root_uses_machine_creds)
70                 gssd_destroy_krb5_machine_creds();
71         printerr(1, "exiting on signal %d\n", signal);
72         exit(1);
73 }
74
75 void
76 sig_hup(int signal)
77 {
78         /* don't exit on SIGHUP */
79         printerr(1, "Received SIGHUP... Ignoring.\n");
80         return;
81 }
82
83 static void
84 usage(char *progname)
85 {
86         fprintf(stderr, "usage: %s [-f] [-M] [-n] [-v] [-r] [-p pipefsdir] [-k keytab] [-d ccachedir] [-t timeout]\n",
87                 progname);
88         exit(1);
89 }
90
91 int
92 main(int argc, char *argv[])
93 {
94         int fg = 0;
95         int verbosity = 0;
96         int rpc_verbosity = 0;
97         int opt;
98         int i;
99         extern char *optarg;
100         char *progname;
101
102         memset(ccachesearch, 0, sizeof(ccachesearch));
103         while ((opt = getopt(argc, argv, "fvrmnMp:k:d:t:")) != -1) {
104                 switch (opt) {
105                         case 'f':
106                                 fg = 1;
107                                 break;
108                         case 'm':
109                                 /* Accept but ignore this. Now the default. */
110                                 break;
111                         case 'M':
112                                 use_memcache = 1;
113                                 break;
114                         case 'n':
115                                 root_uses_machine_creds = 0;
116                                 break;
117                         case 'v':
118                                 verbosity++;
119                                 break;
120                         case 'r':
121                                 rpc_verbosity++;
122                                 break;
123                         case 'p':
124                                 strncpy(pipefs_dir, optarg, sizeof(pipefs_dir));
125                                 if (pipefs_dir[sizeof(pipefs_dir)-1] != '\0')
126                                         errx(1, "pipefs path name too long");
127                                 break;
128                         case 'k':
129                                 strncpy(keytabfile, optarg, sizeof(keytabfile));
130                                 if (keytabfile[sizeof(keytabfile)-1] != '\0')
131                                         errx(1, "keytab path name too long");
132                                 break;
133                         case 'd':
134                                 strncpy(ccachedir, optarg, sizeof(ccachedir));
135                                 if (ccachedir[sizeof(ccachedir)-1] != '\0')
136                                         errx(1, "ccachedir path name too long");
137                                 break;
138                         case 't':
139                                 context_timeout = atoi(optarg);
140                                 break;
141                         default:
142                                 usage(argv[0]);
143                                 break;
144                 }
145         }
146
147         i = 0;
148         ccachesearch[i++] = strtok(ccachedir, ":");
149         do {
150                 ccachesearch[i++] = strtok(NULL, ":");
151         } while (ccachesearch[i-1] != NULL && i < GSSD_MAX_CCACHE_SEARCH);
152
153         snprintf(pipefs_nfsdir, sizeof(pipefs_nfsdir), "%s/%s",
154                  pipefs_dir, GSSD_SERVICE_NAME);
155         if (pipefs_nfsdir[sizeof(pipefs_nfsdir)-1] != '\0')
156                 errx(1, "pipefs_nfsdir path name too long");
157
158         if ((progname = strrchr(argv[0], '/')))
159                 progname++;
160         else
161                 progname = argv[0];
162
163         initerr(progname, verbosity, fg);
164 #ifdef HAVE_AUTHGSS_SET_DEBUG_LEVEL
165         authgss_set_debug_level(rpc_verbosity);
166 #else
167         if (rpc_verbosity > 0)
168                 printerr(0, "Warning: rpcsec_gss library does not "
169                             "support setting debug level\n");
170 #endif
171
172         if (gssd_check_mechs() != 0)
173                 errx(1, "Problem with gssapi library");
174
175         if (!fg && daemon(0, 0) < 0)
176                 errx(1, "fork");
177
178         signal(SIGINT, sig_die);
179         signal(SIGTERM, sig_die);
180         signal(SIGHUP, sig_hup);
181
182         gssd_run();
183         printerr(0, "gssd_run returned!\n");
184         abort();
185 }