]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/gssd/gssd.c
Must still use knowledge of the glue context for pre-1.4 versions of MIT krb5
[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 pipefsdir[PATH_MAX] = GSSD_PIPEFS_DIR;
57 char keytabfile[PATH_MAX] = GSSD_DEFAULT_KEYTAB_FILE;
58
59 void
60 sig_die(int signal)
61 {
62         /* destroy krb5 machine creds */
63         gssd_destroy_krb5_machine_creds();
64         printerr(1, "exiting on signal %d\n", signal);
65         exit(1);
66 }
67
68 void
69 sig_hup(int signal)
70 {
71         /* don't exit on SIGHUP */
72         printerr(1, "Received SIGHUP... Ignoring.\n");
73         return;
74 }
75
76 static void
77 usage(char *progname)
78 {
79         fprintf(stderr, "usage: %s [-f] [-v] [-r] [-p pipefsdir] [-k keytab]\n",
80                 progname);
81         exit(1);
82 }
83
84 int
85 main(int argc, char *argv[])
86 {
87         int fg = 0;
88         int verbosity = 0;
89         int rpc_verbosity = 0;
90         int opt;
91         extern char *optarg;
92         char *progname;
93
94         while ((opt = getopt(argc, argv, "fvrmp:k:")) != -1) {
95                 switch (opt) {
96                         case 'f':
97                                 fg = 1;
98                                 break;
99                         case 'm':
100                                 /* Accept but ignore this. Now the default. */
101                                 break;
102                         case 'v':
103                                 verbosity++;
104                                 break;
105                         case 'r':
106                                 rpc_verbosity++;
107                                 break;
108                         case 'p':
109                                 strncpy(pipefsdir, optarg, sizeof(pipefsdir));
110                                 if (pipefsdir[sizeof(pipefsdir)-1] != '\0')
111                                         errx(1, "pipefs path name too long");
112                                 break;
113                         case 'k':
114                                 strncpy(keytabfile, optarg, sizeof(keytabfile));
115                                 if (keytabfile[sizeof(keytabfile)-1] != '\0')
116                                         errx(1, "keytab path name too long");
117                                 break;
118                         default:
119                                 usage(argv[0]);
120                                 break;
121                 }
122         }
123         strncat(pipefsdir + strlen(pipefsdir), "/" GSSD_SERVICE_NAME,
124                 sizeof(pipefsdir)-strlen(pipefsdir));
125         if (pipefsdir[sizeof(pipefsdir)-1] != '\0')
126                 errx(1, "pipefs path name too long");
127
128         if ((progname = strrchr(argv[0], '/')))
129                 progname++;
130         else
131                 progname = argv[0];
132
133         initerr(progname, verbosity, fg);
134 #ifdef HAVE_AUTHGSS_SET_DEBUG_LEVEL
135         authgss_set_debug_level(rpc_verbosity);
136 #else
137         if (rpc_verbosity > 0)
138                 printerr(0, "Warning: rpcsec_gss library does not "
139                             "support setting debug level\n");
140 #endif
141
142         if (!fg && daemon(0, 0) < 0)
143                 errx(1, "fork");
144
145         signal(SIGINT, sig_die);
146         signal(SIGTERM, sig_die);
147         signal(SIGHUP, sig_hup);
148
149         /* Process keytab file and get machine credentials */
150         gssd_refresh_krb5_machine_creds();
151
152         gssd_run();
153         printerr(0, "gssd_run returned!\n");
154         abort();
155 }