]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blobdiff - server/main.c
r242@bucket (orig r238): kcr | 2007-12-28 00:47:31 -0500
[1ts-debian.git] / server / main.c
index 352c6079f0a8c08fff67eb7b93cff42d38d59787..36a9304947e93280998a1b38e633aaa942750657 100644 (file)
@@ -4,7 +4,7 @@
  *     Created by:     John T. Kohl
  *
  *     $Source: /afs/dev.mit.edu/source/repository/athena/lib/zephyr/server/main.c,v $
- *     $Author: zacheiss $
+ *     $Author$
  *
  *     Copyright (c) 1987,1988,1991 by the Massachusetts Institute of Technology.
  *     For copying and distribution information, see the file
@@ -19,7 +19,7 @@
 #ifndef lint
 #ifndef SABER
 static const char rcsid_main_c[] =
-    "$Id: main.c,v 1.69 2001/02/27 04:50:08 zacheiss Exp $";
+    "$Id$";
 #endif
 #endif
 
@@ -91,8 +91,10 @@ unsigned short hm_srv_port;          /* host manager server sending port */
 char *programname;                     /* set to the basename of argv[0] */
 char myname[MAXHOSTNAMELEN];           /* my host name */
 
-#ifndef HAVE_HESIOD
 char list_file[128];
+#ifdef HAVE_KRB5
+char keytab_file[128];
+static char tkt5_file[256];
 #endif
 #ifdef HAVE_KRB4
 char srvtab_file[128];
@@ -122,6 +124,25 @@ static int nofork;
 struct in_addr my_addr;
 char *bdump_version = "1.2";
 
+#ifdef HAVE_KRB5
+int bdump_auth_proto = 5;
+#else /* HAVE_KRB5 */
+#ifdef HAVE_KRB4
+int bdump_auth_proto = 4;
+#else /* HAVE_KRB4 */
+int bdump_auth_proto = 0;
+#endif /* HAVE_KRB4 */
+#endif /* HAVE_KRB5 */
+
+#ifdef HAVE_KRB5
+krb5_ccache Z_krb5_ccache;
+krb5_keyblock *__Zephyr_keyblock;
+#else
+#ifdef HAVE_KRB4
+C_Block __Zephyr_session;
+#endif
+#endif
+
 int
 main(argc, argv)
     int argc;
@@ -139,12 +160,14 @@ main(argc, argv)
     extern char *optarg;
     extern int optind;
 
-#ifndef HAVE_HESIOD
     sprintf(list_file, "%s/zephyr/%s", SYSCONFDIR, SERVER_LIST_FILE);
-#endif
 #ifdef HAVE_KRB4
     sprintf(srvtab_file, "%s/zephyr/%s", SYSCONFDIR, ZEPHYR_SRVTAB);
     sprintf(tkt_file, "%s/zephyr/%s", SYSCONFDIR, ZEPHYR_TKFILE);
+#endif
+#ifdef HAVE_KRB5
+    sprintf(keytab_file, "%s/zephyr/%s", SYSCONFDIR, ZEPHYR_KEYTAB);
+    sprintf(tkt5_file, "FILE:%s/zephyr/%s", SYSCONFDIR, ZEPHYR_TK5FILE);
 #endif
     sprintf(acl_dir, "%s/zephyr/%s", SYSCONFDIR, ZEPHYR_ACL_DIR);
     sprintf(subs_file, "%s/zephyr/%s", SYSCONFDIR, DEFAULT_SUBS_FILE);
@@ -154,7 +177,7 @@ main(argc, argv)
     programname = (programname) ? programname + 1 : argv[0];
 
     /* process arguments */
-    while ((optchar = getopt(argc, argv, "dsnv:f:k:")) != EOF) {
+    while ((optchar = getopt(argc, argv, "dsnv4f:k:")) != EOF) {
        switch(optchar) {
          case 'd':
            zdebug = 1;
@@ -179,6 +202,9 @@ main(argc, argv)
            init_from_dump = 0;
            dumpfile = optarg;
            break;
+       case '4':
+           bdump_auth_proto = 4;
+           break;
          case '?':
          default:
            usage();
@@ -297,9 +323,6 @@ main(argc, argv)
     /* Reinitialize t_local now that initialization is done. */
     gettimeofday(&t_local, NULL);
     uptime = NOW;
-#ifdef HAVE_KRB4
-    timer_set_rel(SWEEP_INTERVAL, sweep_ticket_hash_table, NULL);
-#endif
 
     realm_wakeup();
 #ifdef DEBUG_MALLOC
@@ -373,6 +396,7 @@ main(argc, argv)
 static int
 initialize()
 {
+    int zero = 0;
     if (do_net_setup())
        return(1);
 
@@ -385,6 +409,20 @@ initialize()
     
     ZSetServerState(1);
     ZInitialize();             /* set up the library */
+#ifdef HAVE_KRB5
+    krb5_cc_resolve(Z_krb5_ctx, tkt5_file, &Z_krb5_ccache);
+#ifdef HAVE_KRB5_CC_SET_DEFAULT_NAME
+    krb5_cc_set_default_name(Z_krb5_ctx, tkt5_file);
+#else
+    {
+       /* Hack to make krb5_cc_default do something reasonable */
+       char *env=(char *)malloc(strlen(tkt5_file)+12);
+       if (!env) return(1);
+       sprintf(env, "KRB5CCNAME=%s", tkt5_file);
+       putenv(env);
+    }
+#endif
+#endif
 #ifdef HAVE_KRB4
     /* Override what Zinitialize set for ZGetRealm() */
     if (*my_realm) 
@@ -451,6 +489,13 @@ do_net_setup()
     if (srv_socket < 0) {
        syslog(LOG_ERR, "client_sock failed: %m");
        return 1;
+    } else {
+#ifdef SO_BSDCOMPAT
+      int on = 1;
+
+      /* Prevent Linux from giving us socket errors we don't care about. */
+      setsockopt(srv_socket, SOL_SOCKET, SO_BSDCOMPAT, &on, sizeof(on));
+#endif
     }
     if (bind(srv_socket, (struct sockaddr *) &srv_addr,
             sizeof(srv_addr)) < 0) {
@@ -637,7 +682,7 @@ reap(sig)
 {
     int pid, i = 0;
     int oerrno = errno;
-    Realm *rlm;
+    ZRealm *rlm;
 #ifdef _POSIX_VERSION
     int waitb;
 #else