]> andersk Git - moira.git/blobdiff - server/mr_sauth.c
Change SNET_STATUS_PRIVATE to SNET_STATUS_PRIVATE_10MBPS and
[moira.git] / server / mr_sauth.c
index d57cd62466414b778e2cdc9752f3fecfd12dc077..52431de14caffeaea99655e48f9c6c61cef48c6f 100644 (file)
@@ -1,30 +1,31 @@
-/*
- *     $Source$
- *     $Author$
- *     $Header$
+/* $Id$
+ *
+ * Handle server side of authentication
  *
- *     Copyright (C) 1987 by the Massachusetts Institute of Technology
- *     For copying and distribution information, please see the file
- *     <mit-copyright.h>.
+ * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
  *
  */
 
-#ifndef lint
-static char *rcsid_sms_sauth_c = "$Header$";
-#endif lint
-
 #include <mit-copyright.h>
-#include <string.h>
 #include "mr_server.h"
-#include <ctype.h>
-#include <krb_et.h>
-#include <moira.h>
-#include <time.h>
+
+#include <sys/types.h>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+RCSID("$Header$");
 
 extern char *whoami, *host;
+extern int proxy_acl;
 
-/* from libmoira */
-char *kname_unparse(char *, char *, char *);
+static int set_client(client *cl, char *kname,
+                     char *name, char *inst, char *realm);
 
 typedef struct _replay_cache {
   KTEXT_ST auth;
@@ -46,28 +47,26 @@ void do_auth(client *cl)
 {
   KTEXT_ST auth;
   AUTH_DAT ad;
-  int status, ok;
-  extern int errno;
+  int status;
   replay_cache *rc, *rcnew;
   time_t now;
 
-  auth.length = cl->args->mr_argl[0];
-  memcpy(auth.dat, cl->args->mr_argv[0], auth.length);
+  auth.length = cl->req.mr_argl[0];
+  memcpy(auth.dat, cl->req.mr_argv[0], auth.length);
   auth.mbz = 0;
 
-  if ((status = krb_rd_req (&auth, MOIRA_SNAME, host,
-                           cl->haddr.sin_addr.s_addr, &ad, "")))
+  if ((status = krb_rd_req(&auth, MOIRA_SNAME, host,
+                          cl->haddr.sin_addr.s_addr, &ad, "")))
     {
       status += ERROR_TABLE_BASE_krb;
-      cl->reply.mr_status = status;
-      if (log_flags & LOG_RES)
-       com_err(whoami, status, " (authentication failed)");
+      client_reply(cl, status);
+      com_err(whoami, status, " (authentication failed)");
       return;
     }
 
   if (!rcache)
     {
-      rcache = malloc(sizeof(replay_cache));
+      rcache = xmalloc(sizeof(replay_cache));
       memset(rcache, 0, sizeof(replay_cache));
     }
 
@@ -82,14 +81,14 @@ void do_auth(client *cl)
                  inet_ntoa(cl->haddr.sin_addr),
                  kname_unparse(ad.pname, ad.pinst, ad.prealm));
          com_err(whoami, KE_RD_AP_REPEAT, " (authentication failed)");
-         cl->reply.mr_status = KE_RD_AP_REPEAT;
+         client_reply(cl, KE_RD_AP_REPEAT);
          return;
        }
     }
 
   /* add new entry */
   time(&now);
-  rcnew = malloc(sizeof(replay_cache));
+  rcnew = xmalloc(sizeof(replay_cache));
   memcpy(&(rcnew->auth), &auth, sizeof(KTEXT_ST));
   rcnew->expires = now + 2 * CLOCK_SKEW;
   rcnew->next = rcache->next;
@@ -108,35 +107,78 @@ void do_auth(client *cl)
        rc = rc->next;
     }
 
-  memcpy(cl->kname.name, ad.pname, ANAME_SZ);
-  memcpy(cl->kname.inst, ad.pinst, INST_SZ);
-  memcpy(cl->kname.realm, ad.prealm, REALM_SZ);
-  strcpy(cl->clname, kname_unparse(ad.pname, ad.pinst, ad.prealm));
+  status = set_client(cl, kname_unparse(ad.pname, ad.pinst, ad.prealm),
+                     ad.pname, ad.pinst, ad.prealm);
 
-  if (ad.pinst[0] == 0 && !strcmp(ad.prealm, krb_realm))
-    ok = 1;
+  strncpy(cl->entity, cl->req.mr_argv[1], sizeof(cl->entity) - 1);
+  cl->entity[sizeof(cl->entity) - 1] = 0;
+
+  memset(&ad, 0, sizeof(ad));  /* Clean up session key, etc. */
+
+  com_err(whoami, 0, "Auth to %s using %s, uid %d cid %d",
+         cl->clname, cl->entity, cl->users_id, cl->client_id);
+
+  if (status != MR_SUCCESS || cl->users_id != 0)
+    client_reply(cl, status);
   else
-    ok = 0;
-  /* this is in a separate function because it accesses the database */
-  status = set_krb_mapping(cl->clname, ad.pname, ok,
-                          &cl->client_id, &cl->users_id);
+    client_reply(cl, MR_USER_AUTH);
+}
+
+void do_proxy(client *cl)
+{
+  char name[ANAME_SZ], inst[INST_SZ], realm[REALM_SZ];
+  char kname[MAX_K_NAME_SZ];
 
-  if (cl->args->mr_version_no == MR_VERSION_2)
+  if (cl->proxy_id)
     {
-      strncpy(cl->entity, cl->args->mr_argv[1], 8);
-      cl->entity[8] = 0;
+      com_err(whoami, MR_PERM, "Cannot re-proxy");
+      client_reply(cl, MR_PERM);
+      return;
+    }
+
+  if (kname_parse(name, inst, realm, cl->req.mr_argv[0]) != KSUCCESS)
+    {
+      com_err(whoami, KE_KNAME_FMT, "while parsing proxy name %s",
+             cl->req.mr_argv);
+      client_reply(cl, KE_KNAME_FMT);
+      return;
     }
-  else
-    strcpy(cl->entity, "???");
-  memset(&ad, 0, sizeof(ad));  /* Clean up session key, etc. */
 
-  if (log_flags & LOG_RES)
+  if (!*realm)
+    {
+      strcpy(realm, krb_realm);
+      sprintf(kname, "%s@%s", cl->req.mr_argv[0], realm);
+    }
+  else
+    strcpy(kname, cl->req.mr_argv[0]);
+    
+  if (find_member("LIST", proxy_acl, cl))
+    {
+      cl->proxy_id = cl->client_id;
+      set_client(cl, kname, name, inst, realm);
+      com_err(whoami, 0, "Proxy authentication as %s (uid %d cid %d) via %s",
+             kname, cl->users_id, cl->client_id, cl->req.mr_argv[1]);
+      client_reply(cl, MR_SUCCESS);
+    }
+  else
     {
-      com_err(whoami, 0, "Auth to %s using %s, uid %d cid %d",
-             cl->clname, cl->entity, cl->users_id, cl->client_id);
+      com_err(whoami, MR_PERM, "Proxy authentication denied");
+      client_reply(cl, MR_PERM);
     }
-  if (status != MR_SUCCESS)
-    cl->reply.mr_status = status;
-  else if (cl->users_id == 0)
-    cl->reply.mr_status = MR_USER_AUTH;
+}
+
+static int set_client(client *cl, char *kname,
+                     char *name, char *inst, char *realm)
+{
+  int ok;
+
+  strncpy(cl->clname, kname, sizeof(cl->clname));
+  cl->clname[sizeof(cl->clname) - 1] = '\0';
+
+  if (inst[0] == 0 && !strcmp(realm, krb_realm))
+    ok = 1;
+  else
+    ok = 0;
+  /* this is in a separate function because it accesses the database */
+  return set_krb_mapping(cl->clname, name, ok, &cl->client_id, &cl->users_id);
 }
This page took 0.099225 seconds and 4 git commands to generate.