]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/gssd/gssd.c
Merge branch 'sid'
[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 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif  /* HAVE_CONFIG_H */
42
43 #include <sys/param.h>
44 #include <sys/socket.h>
45 #include <rpc/rpc.h>
46
47 #include <unistd.h>
48 #include <err.h>
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <string.h>
52 #include <signal.h>
53 #include "gssd.h"
54 #include "err_util.h"
55 #include "gss_util.h"
56 #include "krb5_util.h"
57
58 char pipefs_dir[PATH_MAX] = GSSD_PIPEFS_DIR;
59 char keytabfile[PATH_MAX] = GSSD_DEFAULT_KEYTAB_FILE;
60 char ccachedir[PATH_MAX] = GSSD_DEFAULT_CRED_DIR ":" GSSD_USER_CRED_DIR;
61 char *ccachesearch[GSSD_MAX_CCACHE_SEARCH + 1];
62 int  use_memcache = 0;
63 int  root_uses_machine_creds = 1;
64 unsigned int  context_timeout = 0;
65 char *preferred_realm = NULL;
66
67 void
68 sig_die(int signal)
69 {
70         /* destroy krb5 machine creds */
71         if (root_uses_machine_creds)
72                 gssd_destroy_krb5_machine_creds();
73         printerr(1, "exiting on signal %d\n", signal);
74         exit(0);
75 }
76
77 void
78 sig_hup(int signal)
79 {
80         /* don't exit on SIGHUP */
81         printerr(1, "Received SIGHUP(%d)... Ignoring.\n", signal);
82         return;
83 }
84
85 static void
86 usage(char *progname)
87 {
88         fprintf(stderr, "usage: %s [-f] [-l] [-M] [-n] [-v] [-r] [-p pipefsdir] [-k keytab] [-d ccachedir] [-t timeout] [-R preferred realm] [-D]\n",
89                 progname);
90         exit(1);
91 }
92
93 int
94 main(int argc, char *argv[])
95 {
96         int fg = 0;
97         int verbosity = 0;
98         int rpc_verbosity = 0;
99         int opt;
100         int i;
101         extern char *optarg;
102         char *progname;
103
104         memset(ccachesearch, 0, sizeof(ccachesearch));
105         while ((opt = getopt(argc, argv, "DfvrlmnMp:k:d:t:R:")) != -1) {
106                 switch (opt) {
107                         case 'f':
108                                 fg = 1;
109                                 break;
110                         case 'm':
111                                 /* Accept but ignore this. Now the default. */
112                                 break;
113                         case 'M':
114                                 use_memcache = 1;
115                                 break;
116                         case 'n':
117                                 root_uses_machine_creds = 0;
118                                 break;
119                         case 'v':
120                                 verbosity++;
121                                 break;
122                         case 'r':
123                                 rpc_verbosity++;
124                                 break;
125                         case 'p':
126                                 strncpy(pipefs_dir, optarg, sizeof(pipefs_dir));
127                                 if (pipefs_dir[sizeof(pipefs_dir)-1] != '\0')
128                                         errx(1, "pipefs path name too long");
129                                 break;
130                         case 'k':
131                                 strncpy(keytabfile, optarg, sizeof(keytabfile));
132                                 if (keytabfile[sizeof(keytabfile)-1] != '\0')
133                                         errx(1, "keytab path name too long");
134                                 break;
135                         case 'd':
136                                 strncpy(ccachedir, optarg, sizeof(ccachedir));
137                                 if (ccachedir[sizeof(ccachedir)-1] != '\0')
138                                         errx(1, "ccachedir path name too long");
139                                 break;
140                         case 't':
141                                 context_timeout = atoi(optarg);
142                                 break;
143                         case 'R':
144                                 preferred_realm = strdup(optarg);
145                                 break;
146                         case 'l':
147 #ifdef HAVE_SET_ALLOWABLE_ENCTYPES
148                                 limit_to_legacy_enctypes = 1;
149 #else 
150                                 errx(1, "Encryption type limits not supported by Kerberos libraries.");
151 #endif
152                                 break;
153                         case 'D':
154                                 avoid_dns = 0;
155                                 break;
156                         default:
157                                 usage(argv[0]);
158                                 break;
159                 }
160         }
161
162         i = 0;
163         ccachesearch[i++] = strtok(ccachedir, ":");
164         do {
165                 ccachesearch[i++] = strtok(NULL, ":");
166         } while (ccachesearch[i-1] != NULL && i < GSSD_MAX_CCACHE_SEARCH);
167
168         if (preferred_realm == NULL)
169                 gssd_k5_get_default_realm(&preferred_realm);
170
171         if ((progname = strrchr(argv[0], '/')))
172                 progname++;
173         else
174                 progname = argv[0];
175
176         initerr(progname, verbosity, fg);
177 #ifdef HAVE_AUTHGSS_SET_DEBUG_LEVEL
178         if (verbosity && rpc_verbosity == 0)
179                 rpc_verbosity = verbosity;
180         authgss_set_debug_level(rpc_verbosity);
181 #else
182         if (rpc_verbosity > 0)
183                 printerr(0, "Warning: rpcsec_gss library does not "
184                             "support setting debug level\n");
185 #endif
186
187         if (gssd_check_mechs() != 0)
188                 errx(1, "Problem with gssapi library");
189
190         if (!fg && daemon(0, 0) < 0)
191                 errx(1, "fork");
192
193         signal(SIGINT, sig_die);
194         signal(SIGTERM, sig_die);
195         signal(SIGHUP, sig_hup);
196
197         gssd_run();
198         printerr(0, "gssd_run returned!\n");
199         abort();
200 }