]> andersk Git - moira.git/blobdiff - server/mr_sauth.c
startmoira now sends a zephyr to -c moira -i startmoira when moirad
[moira.git] / server / mr_sauth.c
index f3e08a21c9ef10219f6f9282cf1d136ca26ff1c6..dcb45b23efa123a203c8010f8ab97eae9e5ffc34 100644 (file)
@@ -15,17 +15,17 @@ static char *rcsid_sms_sauth_c = "$Header$";
 
 #include <mit-copyright.h>
 #include <strings.h>
-#include "sms_server.h"
+#include "mr_server.h"
+#include <ctype.h>
 #include <krb_et.h>
 
 extern char buf1[];
 extern char *whoami;
-extern char *malloc();
 
 char *kname_unparse();
 
 /*
- * Handle a SMS_AUTH RPC request.
+ * Handle a MOIRA_AUTH RPC request.
  *
  * argv[0] is a kerberos authenticator.  Decompose it, and if
  * successful, store the name the user authenticated to in 
@@ -39,20 +39,32 @@ do_auth(cl)
        KTEXT_ST auth;
        AUTH_DAT ad;
        int status, ok;
-       char buf[REALM_SZ+INST_SZ+ANAME_SZ];
-       
-       auth.length = cl->args->sms_argl[0];
-       bcopy(cl->args->sms_argv[0], (char *)auth.dat, auth.length);
+       char buf[REALM_SZ+INST_SZ+ANAME_SZ], hostbuf[BUFSIZ], *host, *p;
+       extern int errno;
+
+       auth.length = cl->args->mr_argl[0];
+       bcopy(cl->args->mr_argv[0], (char *)auth.dat, auth.length);
        auth.mbz = 0;
-       
-       if ((status = krb_rd_req (&auth, "sms", "sms", cl->haddr.sin_addr,
+       if (gethostname(hostbuf, sizeof(hostbuf)) < 0)
+         com_err(whoami, errno, "Unable to get local hostname");
+       host = canonicalize_hostname(strsave(hostbuf));
+       for (p = host; *p && *p != '.'; p++)
+         if (isupper(*p))
+           *p = tolower(*p);
+       *p = 0;
+
+       if ((status = krb_rd_req (&auth, MOIRA_SNAME, host, cl->haddr.sin_addr,
+                                &ad, "")) != 0 &&
+           /* for backwards compatability with old clients */
+           (status = krb_rd_req (&auth, "sms", "sms", cl->haddr.sin_addr,
                                 &ad, "")) != 0) {
                status += ERROR_TABLE_BASE_krb;
-               cl->reply.sms_status = status;
+               cl->reply.mr_status = status;
                if (log_flags & LOG_RES)
                        com_err(whoami, status, "(authentication failed)");
                return;
        }
+       free(host);
 
        bcopy(ad.pname, cl->kname.name, ANAME_SZ);
        bcopy(ad.pinst, cl->kname.inst, INST_SZ);
@@ -64,11 +76,11 @@ do_auth(cl)
        else
          ok = 0;
        /* this is in a separate function because it accesses the database */
-       set_krb_mapping(cl->clname, ad.pname, ok,
-                       &cl->client_id, &cl->users_id);
+       status = set_krb_mapping(cl->clname, ad.pname, ok,
+                                &cl->client_id, &cl->users_id);
 
-       if (cl->args->sms_version_no == SMS_VERSION_2) {
-           bcopy(cl->args->sms_argv[1], cl->entity, 8);
+       if (cl->args->mr_version_no == MR_VERSION_2) {
+           strncpy(cl->entity, cl->args->mr_argv[1], 8);
            cl->entity[8] = 0;
        } else {
            strcpy(cl->entity, "???");
@@ -78,8 +90,10 @@ do_auth(cl)
        if (log_flags & LOG_RES)
            com_err(whoami, 0, "Auth to %s using %s, uid %d cid %d",
                    cl->clname, cl->entity, cl->users_id, cl->client_id);
-       if (cl->users_id == 0)
-         cl->reply.sms_status = SMS_USER_AUTH;
+       if (status != MR_SUCCESS)
+         cl->reply.mr_status = status;
+       else if (cl->users_id == 0)
+         cl->reply.mr_status = MR_USER_AUTH;
 }
 
 
This page took 0.034669 seconds and 4 git commands to generate.