Imported Upstream version 1.7.6p1
[debian/sudo] / auth / dce.c
index 8d4115b38d3f39175263da92298292c0e5920dc0..3333a72036d2abcee68645c6de2960b4a55a49a1 100644 (file)
@@ -1,38 +1,25 @@
 /*
- * Copyright (c) 1996, 1998, 1999, 2001
- *     Todd C. Miller <Todd.Miller@courtesan.com>.  All rights reserved.
+ * Copyright (c) 1996, 1998-2005, 2010
+ *     Todd C. Miller <Todd.Miller@courtesan.com>
  *
- * This code is derived from software contributed by Jeff Earickson
- * of Colby College, Waterville, ME <jaearick@colby.edu>
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * 4. Products derived from this software may not be called "Sudo" nor
- *    may "Sudo" appear in their names without specific prior written
- *    permission from the author.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
  */
 /*
  *  The code below basically comes from the examples supplied on
@@ -46,7 +33,7 @@
  *  DCE 1.1).
  */
 
-#include "config.h"
+#include <config.h>
 
 #include <sys/types.h>
 #include <sys/param.h>
 #endif /* STDC_HEADERS */
 #ifdef HAVE_STRING_H
 # include <string.h>
-#else
-# ifdef HAVE_STRINGS_H
-#  include <strings.h>
-# endif
+#endif /* HAVE_STRING_H */
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
 #endif /* HAVE_STRING_H */
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #include "sudo.h"
 #include "sudo_auth.h"
 
-#ifndef lint
-static const char rcsid[] = "$Sudo: dce.c,v 1.8 2001/12/14 19:52:53 millert Exp $";
-#endif /* lint */
-
 static int check_dce_status __P((error_status_t, char *));
 
 int
@@ -107,7 +89,7 @@ dce_verify(pw, plain_pw, auth)
        sec_login_no_flags, &login_context, &status)) {
 
        if (check_dce_status(status, "sec_login_setup_identity(1):"))
-           return(AUTH_FAILURE);
+           return AUTH_FAILURE;
 
        password_rec.key.key_type = sec_passwd_plain;
        password_rec.key.tagged_union.plain = (idl_char *) plain_pw;
@@ -119,7 +101,7 @@ dce_verify(pw, plain_pw, auth)
            &reset_passwd, &auth_src, &status)) {
 
            if (check_dce_status(status, "sec_login_validate_identity(1):"))
-               return(AUTH_FAILURE);
+               return AUTH_FAILURE;
 
            /*
             * Certify that the DCE Security Server used to set
@@ -129,10 +111,10 @@ dce_verify(pw, plain_pw, auth)
            if (!sec_login_certify_identity(login_context, &status)) {
                (void) fprintf(stderr, "Whoa! Bogus authentication server!\n");
                (void) check_dce_status(status,"sec_login_certify_identity(1):");
-               return(AUTH_FAILURE);
+               return AUTH_FAILURE;
            }
            if (check_dce_status(status, "sec_login_certify_identity(2):"))
-               return(AUTH_FAILURE);
+               return AUTH_FAILURE;
 
            /*
             * Sets the network credentials to those specified
@@ -140,7 +122,7 @@ dce_verify(pw, plain_pw, auth)
             */
            sec_login_set_context(login_context, &status);
            if (check_dce_status(status, "sec_login_set_context:"))
-               return(AUTH_FAILURE);
+               return AUTH_FAILURE;
 
            /*
             * Oops, your credentials were no good. Possibly
@@ -150,13 +132,13 @@ dce_verify(pw, plain_pw, auth)
            if (auth_src != sec_login_auth_src_network) {
                    (void) fprintf(stderr,
                        "You have no network credentials.\n");
-                   return(AUTH_FAILURE);
+                   return AUTH_FAILURE;
            }
            /* Check if the password has aged and is thus no good */
            if (reset_passwd) {
                    (void) fprintf(stderr,
                        "Your DCE password needs resetting.\n");
-                   return(AUTH_FAILURE);
+                   return AUTH_FAILURE;
            }
 
            /*
@@ -168,7 +150,7 @@ dce_verify(pw, plain_pw, auth)
            sec_login_get_pwent(login_context, (sec_login_passwd_t) &temp_pw,
                &status);
            if (check_dce_status(status, "sec_login_get_pwent:"))
-               return(AUTH_FAILURE);
+               return AUTH_FAILURE;
 
            /*
             * If we get to here, then the pwent above properly fetched
@@ -190,17 +172,17 @@ dce_verify(pw, plain_pw, auth)
             * somewhere later in the program.
             */
            sec_login_purge_context(&login_context, &status);
-           return(AUTH_SUCCESS);
+           return AUTH_SUCCESS;
        } else {
            if(check_dce_status(status, "sec_login_validate_identity(2):"))
-               return(AUTH_FAILURE);
+               return AUTH_FAILURE;
            sec_login_purge_context(&login_context, &status);
            if(check_dce_status(status, "sec_login_purge_context:"))
-               return(AUTH_FAILURE);
+               return AUTH_FAILURE;
        }
     }
     (void) check_dce_status(status, "sec_login_setup_identity(2):");
-    return(AUTH_FAILURE);
+    return AUTH_FAILURE;
 }
 
 /* Returns 0 for DCE "ok" status, 1 otherwise */
@@ -213,8 +195,8 @@ check_dce_status(input_status, comment)
     unsigned char error_string[dce_c_error_string_len];
 
     if (input_status == rpc_s_ok)
-       return(0);
+       return 0;
     dce_error_inq_text(input_status, error_string, &error_stat);
     (void) fprintf(stderr, "%s %s\n", comment, error_string);
-    return(1);
+    return 1;
 }