nfs-ganesha 1.4

gssd.c

Go to the documentation of this file.
00001 /*
00002   gssd.c
00003 
00004   Copyright (c) 2000 The Regents of the University of Michigan.
00005   All rights reserved.
00006 
00007   Copyright (c) 2000 Dug Song <dugsong@UMICH.EDU>.
00008   Copyright (c) 2002 Andy Adamson <andros@UMICH.EDU>.
00009   Copyright (c) 2002 Marius Aamodt Eriksen <marius@UMICH.EDU>.
00010   All rights reserved, all wrongs reversed.
00011 
00012   Redistribution and use in source and binary forms, with or without
00013   modification, are permitted provided that the following conditions
00014   are met:
00015 
00016   1. Redistributions of source code must retain the above copyright
00017      notice, this list of conditions and the following disclaimer.
00018   2. Redistributions in binary form must reproduce the above copyright
00019      notice, this list of conditions and the following disclaimer in the
00020      documentation and/or other materials provided with the distribution.
00021   3. Neither the name of the University nor the names of its
00022      contributors may be used to endorse or promote products derived
00023      from this software without specific prior written permission.
00024 
00025   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
00026   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00027   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028   DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00029   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00030   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00031   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
00032   BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 
00037 */
00038 
00039 #ifdef HAVE_CONFIG_H
00040 #include <config.h>
00041 #endif  /* HAVE_CONFIG_H */
00042 
00043 #include <sys/param.h>
00044 #include <sys/socket.h>
00045 #include <rpc/rpc.h>
00046 
00047 #include <unistd.h>
00048 #include <err.h>
00049 #include <stdio.h>
00050 #include <stdlib.h>
00051 #include <string.h>
00052 #include <signal.h>
00053 #include "gssd.h"
00054 #include "err_util.h"
00055 #include "gss_util.h"
00056 #include "krb5_util.h"
00057 
00058 char pipefs_dir[PATH_MAX] = GSSD_PIPEFS_DIR;
00059 char keytabfile[PATH_MAX] = GSSD_DEFAULT_KEYTAB_FILE;
00060 char ccachedir[PATH_MAX] = GSSD_DEFAULT_CRED_DIR;
00061 char *ccachesearch[GSSD_MAX_CCACHE_SEARCH + 1];
00062 int  use_memcache = 0;
00063 int  root_uses_machine_creds = 1;
00064 unsigned int  context_timeout = 0;
00065 char *preferred_realm = NULL;
00066 
00067 /* Encryption types supported by the kernel rpcsec_gss code */
00068 int num_krb5_enctypes = 0;
00069 krb5_enctype *krb5_enctypes = NULL;
00070 
00071 #if !defined(NFS_GANESHA)
00072 
00073 void
00074 sig_die(int signal)
00075 {
00076         /* destroy krb5 machine creds */
00077         if (root_uses_machine_creds)
00078                 gssd_destroy_krb5_machine_creds();
00079         printerr(1, "exiting on signal %d\n", signal);
00080         exit(1);
00081 }
00082 
00083 void
00084 sig_hup(int signal)
00085 {
00086         /* don't exit on SIGHUP */
00087         printerr(1, "Received SIGHUP(%d)... Ignoring.\n", signal);
00088         return;
00089 }
00090 
00091 static void
00092 usage(char *progname)
00093 {
00094         fprintf(stderr, "usage: %s [-f] [-M] [-n] [-v] [-r] [-p pipefsdir] [-k keytab] [-d ccachedir] [-t timeout] [-R preferred realm]\n",
00095                 progname);
00096         exit(1);
00097 }
00098 
00099 int
00100 main(int argc, char *argv[])
00101 {
00102         int fg = 0;
00103         int verbosity = 0;
00104         int rpc_verbosity = 0;
00105         int opt;
00106         int i;
00107         extern char *optarg;
00108         char *progname;
00109 
00110         memset(ccachesearch, 0, sizeof(ccachesearch));
00111         while ((opt = getopt(argc, argv, "fvrmnMp:k:d:t:R:")) != -1) {
00112                 switch (opt) {
00113                         case 'f':
00114                                 fg = 1;
00115                                 break;
00116                         case 'm':
00117                                 /* Accept but ignore this. Now the default. */
00118                                 break;
00119                         case 'M':
00120                                 use_memcache = 1;
00121                                 break;
00122                         case 'n':
00123                                 root_uses_machine_creds = 0;
00124                                 break;
00125                         case 'v':
00126                                 verbosity++;
00127                                 break;
00128                         case 'r':
00129                                 rpc_verbosity++;
00130                                 break;
00131                         case 'p':
00132                                 strncpy(pipefs_dir, optarg, sizeof(pipefs_dir));
00133                                 if (pipefs_dir[sizeof(pipefs_dir)-1] != '\0')
00134                                         errx(1, "pipefs path name too long");
00135                                 break;
00136                         case 'k':
00137                                 strncpy(keytabfile, optarg, sizeof(keytabfile));
00138                                 if (keytabfile[sizeof(keytabfile)-1] != '\0')
00139                                         errx(1, "keytab path name too long");
00140                                 break;
00141                         case 'd':
00142                                 strncpy(ccachedir, optarg, sizeof(ccachedir));
00143                                 if (ccachedir[sizeof(ccachedir)-1] != '\0')
00144                                         errx(1, "ccachedir path name too long");
00145                                 break;
00146                         case 't':
00147                                 context_timeout = atoi(optarg);
00148                                 break;
00149                         case 'R':
00150                                 preferred_realm = strdup(optarg);
00151                                 break;
00152                         default:
00153                                 usage(argv[0]);
00154                                 break;
00155                 }
00156         }
00157 
00158         i = 0;
00159         ccachesearch[i++] = strtok(ccachedir, ":");
00160         do {
00161                 ccachesearch[i++] = strtok(NULL, ":");
00162         } while (ccachesearch[i-1] != NULL && i < GSSD_MAX_CCACHE_SEARCH);
00163 
00164         if (preferred_realm == NULL)
00165                 gssd_k5_get_default_realm(&preferred_realm);
00166 
00167         if ((progname = strrchr(argv[0], '/')))
00168                 progname++;
00169         else
00170                 progname = argv[0];
00171 
00172         initerr(progname, verbosity, fg);
00173 #ifdef HAVE_AUTHGSS_SET_DEBUG_LEVEL
00174         if (verbosity && rpc_verbosity == 0)
00175                 rpc_verbosity = verbosity;
00176         authgss_set_debug_level(rpc_verbosity);
00177 #else
00178         if (rpc_verbosity > 0)
00179                 printerr(0, "Warning: rpcsec_gss library does not "
00180                             "support setting debug level\n");
00181 #endif
00182 
00183         if (gssd_check_mechs() != 0)
00184                 errx(1, "Problem with gssapi library");
00185 
00186         if (!fg && daemon(0, 0) < 0)
00187                 errx(1, "fork");
00188 
00189         signal(SIGINT, sig_die);
00190         signal(SIGTERM, sig_die);
00191         signal(SIGHUP, sig_hup);
00192 
00193         gssd_run();
00194         printerr(0, "gssd_run returned!\n");
00195         abort();
00196 }
00197 
00198 #endif /* ! NFS_GANESHA */