]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/gssd/gssd.c
configure changed to corrently report the default for --enable-mount
[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 int  use_memcache = 0;
61 int  root_uses_machine_creds = 1;
62
63 void
64 sig_die(int signal)
65 {
66         /* destroy krb5 machine creds */
67         if (root_uses_machine_creds)
68                 gssd_destroy_krb5_machine_creds();
69         printerr(1, "exiting on signal %d\n", signal);
70         exit(1);
71 }
72
73 void
74 sig_hup(int signal)
75 {
76         /* don't exit on SIGHUP */
77         printerr(1, "Received SIGHUP... Ignoring.\n");
78         return;
79 }
80
81 static void
82 usage(char *progname)
83 {
84         fprintf(stderr, "usage: %s [-f] [-n] [-v] [-r] [-p pipefsdir] [-k keytab] [-d ccachedir]\n",
85                 progname);
86         exit(1);
87 }
88
89 int
90 main(int argc, char *argv[])
91 {
92         int fg = 0;
93         int verbosity = 0;
94         int rpc_verbosity = 0;
95         int opt;
96         extern char *optarg;
97         char *progname;
98
99         while ((opt = getopt(argc, argv, "fvrmnMp:k:d:")) != -1) {
100                 switch (opt) {
101                         case 'f':
102                                 fg = 1;
103                                 break;
104                         case 'm':
105                                 /* Accept but ignore this. Now the default. */
106                                 break;
107                         case 'M':
108                                 use_memcache = 1;
109                                 break;
110                         case 'n':
111                                 root_uses_machine_creds = 0;
112                                 break;
113                         case 'v':
114                                 verbosity++;
115                                 break;
116                         case 'r':
117                                 rpc_verbosity++;
118                                 break;
119                         case 'p':
120                                 strncpy(pipefs_dir, optarg, sizeof(pipefs_dir));
121                                 if (pipefs_dir[sizeof(pipefs_dir)-1] != '\0')
122                                         errx(1, "pipefs path name too long");
123                                 break;
124                         case 'k':
125                                 strncpy(keytabfile, optarg, sizeof(keytabfile));
126                                 if (keytabfile[sizeof(keytabfile)-1] != '\0')
127                                         errx(1, "keytab path name too long");
128                                 break;
129                         case 'd':
130                                 strncpy(ccachedir, optarg, sizeof(ccachedir));
131                                 if (ccachedir[sizeof(ccachedir)-1] != '\0')
132                                         errx(1, "ccachedir path name too long");
133                                 break;
134                         default:
135                                 usage(argv[0]);
136                                 break;
137                 }
138         }
139         snprintf(pipefs_nfsdir, sizeof(pipefs_nfsdir), "%s/%s",
140                  pipefs_dir, GSSD_SERVICE_NAME);
141         if (pipefs_nfsdir[sizeof(pipefs_nfsdir)-1] != '\0')
142                 errx(1, "pipefs_nfsdir path name too long");
143
144         if ((progname = strrchr(argv[0], '/')))
145                 progname++;
146         else
147                 progname = argv[0];
148
149         initerr(progname, verbosity, fg);
150 #ifdef HAVE_AUTHGSS_SET_DEBUG_LEVEL
151         authgss_set_debug_level(rpc_verbosity);
152 #else
153         if (rpc_verbosity > 0)
154                 printerr(0, "Warning: rpcsec_gss library does not "
155                             "support setting debug level\n");
156 #endif
157
158         if (gssd_check_mechs() != 0)
159                 errx(1, "Problem with gssapi library");
160
161         if (!fg && daemon(0, 0) < 0)
162                 errx(1, "fork");
163
164         signal(SIGINT, sig_die);
165         signal(SIGTERM, sig_die);
166         signal(SIGHUP, sig_hup);
167
168         gssd_run();
169         printerr(0, "gssd_run returned!\n");
170         abort();
171 }