s4: import lorikeet-heimdal-200810271034
[samba.git] / source4 / heimdal / lib / krb5 / v4_glue.c
index baa4bd6892122c023229ecc33e23e97214685242..6911cb20f8f31bc0647c30243bbf2cc5932764da 100644 (file)
@@ -1,34 +1,34 @@
 /*
- * Copyright (c) 1997 - 2005 Kungliga Tekniska Högskolan
- * (Royal Institute of Technology, Stockholm, Sweden). 
- * All rights reserved. 
+ * Copyright (c) 1997 - 2005 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
  *
- * Redistribution and use in source and binary forms, with or without 
- * modification, are permitted provided that the following conditions 
- * are met: 
+ * 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. 
+ * 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. 
+ * 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. Neither the name of the Institute nor the names of its contributors 
- *    may be used to endorse or promote products derived from this software 
- *    without specific prior written permission. 
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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, 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. 
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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, 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.
  */
 
 #include "krb5_locl.h"
@@ -36,6 +36,8 @@ RCSID("$Id$");
 
 #include "krb5-v4compat.h"
 
+#ifndef HEIMDAL_SMALLER
+
 /*
  *
  */
@@ -63,22 +65,22 @@ _krb5_krb_time_to_life(time_t start, time_t end)
     int i;
     time_t life = end - start;
 
-    if (life > MAXTKTLIFETIME || life <= 0) 
+    if (life > MAXTKTLIFETIME || life <= 0)
        return 0;
-#if 0    
-    if (krb_no_long_lifetimes) 
+#if 0
+    if (krb_no_long_lifetimes)
        return (life + 5*60 - 1)/(5*60);
 #endif
-    
+
     if (end >= NEVERDATE)
        return TKTLIFENOEXPIRE;
-    if (life < _tkt_lifetimes[0]) 
+    if (life < _tkt_lifetimes[0])
        return (life + 5*60 - 1)/(5*60);
     for (i=0; i<TKTLIFENUMFIXED; i++)
        if (life <= _tkt_lifetimes[i])
            return i + TKTLIFEMINFIXED;
     return 0;
-    
+
 }
 
 time_t KRB5_LIB_FUNCTION
@@ -86,7 +88,7 @@ _krb5_krb_life_to_time(int start, int life_)
 {
     unsigned char life = (unsigned char) life_;
 
-#if 0    
+#if 0
     if (krb_no_long_lifetimes)
        return start + life*5*60;
 #endif
@@ -136,7 +138,7 @@ get_krb4_cc_name(const char *tkfile, char **cc)
 #define KRB5_TF_LCK_RETRY 1
 
 static krb5_error_code
-write_v4_cc(krb5_context context, const char *tkfile, 
+write_v4_cc(krb5_context context, const char *tkfile,
            krb5_storage *sp, int append)
 {
     krb5_error_code ret;
@@ -147,27 +149,28 @@ write_v4_cc(krb5_context context, const char *tkfile,
 
     ret = get_krb4_cc_name(tkfile, &path);
     if (ret) {
-       krb5_set_error_message(context, ret, 
-                             "krb5_krb_tf_setup: failed getting "
-                             "the krb4 credentials cache name"); 
+       krb5_set_error_message(context, ret,
+                              N_("Failed getting the krb4 credentials "
+                                "cache name", ""));
        return ret;
     }
 
     fd = open(path, O_WRONLY|O_CREAT, 0600);
     if (fd < 0) {
        ret = errno;
-       krb5_set_error_message(context, ret, 
-                             "krb5_krb_tf_setup: error opening file %s", 
-                             path);
+       krb5_set_error_message(context, ret,
+                              N_("Failed opening krb4 credential cache "
+                                "%s: %s", "path, error"),
+                              path, strerror(ret));
        free(path);
        return ret;
     }
     rk_cloexec(fd);
 
     if (fstat(fd, &sb) != 0 || !S_ISREG(sb.st_mode)) {
-       krb5_set_error_message(context, ret, 
-                             "krb5_krb_tf_setup: tktfile %s is not a file",
-                             path);
+       krb5_set_error_message(context, ret,
+                              N_("krb4 credential cache %s is not a file", ""),
+                              path);
        free(path);
        close(fd);
        return KRB5_FCC_PERM;
@@ -181,7 +184,7 @@ write_v4_cc(krb5_context context, const char *tkfile,
     }
     if (i == KRB5_TF_LCK_RETRY_COUNT) {
        krb5_set_error_message(context, KRB5_FCC_PERM,
-                              "krb5_krb_tf_setup: failed to lock %s",
+                              N_("Failed to lock credentail cache %s", ""),
                               path);
        free(path);
        close(fd);
@@ -193,7 +196,7 @@ write_v4_cc(krb5_context context, const char *tkfile,
        if (ret < 0) {
            flock(fd, LOCK_UN);
            krb5_set_error_message(context, KRB5_FCC_PERM,
-                                  "krb5_krb_tf_setup: failed to truncate %s",
+                                  N_("Failed to truncate krb4 cc %s", ""),
                                   path);
            free(path);
            close(fd);
@@ -229,8 +232,8 @@ write_v4_cc(krb5_context context, const char *tkfile,
  */
 
 krb5_error_code KRB5_LIB_FUNCTION
-_krb5_krb_tf_setup(krb5_context context, 
-                  struct credentials *v4creds, 
+_krb5_krb_tf_setup(krb5_context context,
+                  struct credentials *v4creds,
                   const char *tkfile,
                   int append)
 {
@@ -244,7 +247,7 @@ _krb5_krb_tf_setup(krb5_context context,
     krb5_storage_set_byteorder(sp, KRB5_STORAGE_BYTEORDER_HOST);
     krb5_storage_set_eof_code(sp, KRB5_CC_IO);
 
-    krb5_clear_error_string(context);
+    krb5_clear_error_message(context);
 
     if (!append) {
        RCHECK(ret, krb5_store_stringz(sp, v4creds->pname), error);
@@ -264,7 +267,7 @@ _krb5_krb_tf_setup(krb5_context context,
     RCHECK(ret, krb5_store_int32(sp, v4creds->kvno), error);
     RCHECK(ret, krb5_store_int32(sp, v4creds->ticket_st.length), error);
 
-    ret = krb5_storage_write(sp, v4creds->ticket_st.dat, 
+    ret = krb5_storage_write(sp, v4creds->ticket_st.dat,
                             v4creds->ticket_st.length);
     if (ret != v4creds->ticket_st.length) {
        ret = KRB5_CC_IO;
@@ -292,17 +295,18 @@ _krb5_krb_dest_tkt(krb5_context context, const char *tkfile)
 
     ret = get_krb4_cc_name(tkfile, &path);
     if (ret) {
-       krb5_set_error_message(context, ret, 
-                             "krb5_krb_tf_setup: failed getting "
-                             "the krb4 credentials cache name"); 
+       krb5_set_error_message(context, ret,
+                              N_("Failed getting the krb4 credentials "
+                                "cache name", ""));
        return ret;
     }
 
     if (unlink(path) < 0) {
        ret = errno;
-       krb5_set_error_message(context, ret, 
-                             "krb5_krb_dest_tkt failed removing the cache "
-                             "with error %s", strerror(ret));
+       krb5_set_error_message(context, ret,
+                              N_("Failed removing the cache %s "
+                                "with error %s", "path, error"),
+                              path, strerror(ret));
     }
     free(path);
 
@@ -340,7 +344,7 @@ static const char eightzeros[8] = "\x00\x00\x00\x00\x00\x00\x00\x00";
 static krb5_error_code
 storage_to_etext(krb5_context context,
                 krb5_storage *sp,
-                const krb5_keyblock *key, 
+                const krb5_keyblock *key,
                 krb5_data *enc_data)
 {
     krb5_error_code ret;
@@ -422,7 +426,7 @@ _krb5_krb_create_ticket(krb5_context context,
 
     sp = krb5_storage_emem();
     if (sp == NULL) {
-       krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
+       krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
        return ENOMEM;
     }
     krb5_storage_set_byteorder(sp, KRB5_STORAGE_BYTEORDER_BE);
@@ -433,7 +437,7 @@ _krb5_krb_create_ticket(krb5_context context,
 
     /* session key */
     ret = krb5_storage_write(sp,
-                            session->keyvalue.data, 
+                            session->keyvalue.data,
                             session->keyvalue.length);
     if (ret != session->keyvalue.length) {
        ret = KRB4ET_INTK_PROT;
@@ -449,7 +453,8 @@ _krb5_krb_create_ticket(krb5_context context,
  error:
     krb5_storage_free(sp);
     if (ret)
-       krb5_set_error_message(context, ret, "Failed to encode kerberos 4 ticket");
+       krb5_set_error_message(context, ret,
+                              N_("Failed to encode kerberos 4 ticket", ""));
 
     return ret;
 }
@@ -478,14 +483,14 @@ _krb5_krb_create_ciph(krb5_context context,
 
     sp = krb5_storage_emem();
     if (sp == NULL) {
-       krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
+       krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
        return ENOMEM;
     }
     krb5_storage_set_byteorder(sp, KRB5_STORAGE_BYTEORDER_BE);
 
     /* session key */
     ret = krb5_storage_write(sp,
-                            session->keyvalue.data, 
+                            session->keyvalue.data,
                             session->keyvalue.length);
     if (ret != session->keyvalue.length) {
        ret = KRB4ET_INTK_PROT;
@@ -508,7 +513,8 @@ _krb5_krb_create_ciph(krb5_context context,
  error:
     krb5_storage_free(sp);
     if (ret)
-       krb5_set_error_message(context, ret, "Failed to encode kerberos 4 ticket");
+       krb5_set_error_message(context, ret,
+                              N_("Failed to encode kerberos 4 ticket", ""));
 
     return ret;
 }
@@ -536,7 +542,7 @@ _krb5_krb_create_auth_reply(krb5_context context,
 
     sp = krb5_storage_emem();
     if (sp == NULL) {
-       krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
+       krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
        return ENOMEM;
     }
     krb5_storage_set_byteorder(sp, KRB5_STORAGE_BYTEORDER_BE);
@@ -560,7 +566,8 @@ _krb5_krb_create_auth_reply(krb5_context context,
  error:
     krb5_storage_free(sp);
     if (ret)
-       krb5_set_error_message(context, ret, "Failed to encode kerberos 4 ticket");
+       krb5_set_error_message(context, ret,
+                              N_("Failed to encode kerberos 4 ticket", ""));
        
     return ret;
 }
@@ -591,7 +598,7 @@ _krb5_krb_cr_err_reply(krb5_context context,
 
     sp = krb5_storage_emem();
     if (sp == NULL) {
-       krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
+       krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
        return ENOMEM;
     }
     krb5_storage_set_byteorder(sp, KRB5_STORAGE_BYTEORDER_BE);
@@ -770,7 +777,7 @@ _krb5_krb_rd_req(krb5_context context,
 
     sp = krb5_storage_from_data(authent);
     if (sp == NULL) {
-       krb5_set_error_message(context, ENOMEM, "alloc: out of memory");
+       krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
        return ENOMEM;
     }
 
@@ -778,28 +785,29 @@ _krb5_krb_rd_req(krb5_context context,
 
     ret = krb5_ret_int8(sp, &pvno);
     if (ret) {
-       krb5_set_error_message(context, ret, "Failed reading v4 pvno");
+       krb5_set_error_message(context, ret, N_("Failed reading v4 pvno", ""));
        goto error;
     }
 
     if (pvno != KRB_PROT_VERSION) {
        ret = KRB4ET_RD_AP_VERSION;
-       krb5_set_error_message(context, ret, "Failed v4 pvno not 4");
+       krb5_set_error_message(context, ret, N_("Failed v4 pvno not 4", ""));
        goto error;
     }
 
     ret = krb5_ret_int8(sp, &type);
     if (ret) {
-       krb5_set_error_message(context, ret, "Failed readin v4 type");
+       krb5_set_error_message(context, ret, N_("Failed readin v4 type", ""));
        goto error;
     }
 
     little_endian = type & 1;
     type &= ~1;
-    
+
     if(type != AUTH_MSG_APPL_REQUEST && type != AUTH_MSG_APPL_REQUEST_MUTUAL) {
        ret = KRB4ET_RD_AP_MSG_TYPE;
-       krb5_set_error_message(context, ret, "Not a valid v4 request type");
+       krb5_set_error_message(context, ret,
+                              N_("Not a valid v4 request type", ""));
        goto error;
     }
 
@@ -812,12 +820,12 @@ _krb5_krb_rd_req(krb5_context context,
     size = krb5_storage_read(sp, ticket.data, ticket.length);
     if (size != ticket.length) {
        ret = KRB4ET_INTK_PROT;
-       krb5_set_error_message(context, ret, "Failed reading v4 ticket");
+       krb5_set_error_message(context, ret, N_("Failed reading v4 ticket", ""));
        goto error;
     }
 
     /* Decrypt and take apart ticket */
-    ret = _krb5_krb_decomp_ticket(context, &ticket, key, local_realm, 
+    ret = _krb5_krb_decomp_ticket(context, &ticket, key, local_realm,
                                  &sname, &sinstance, ad);
     if (ret)
        goto error;
@@ -827,7 +835,8 @@ _krb5_krb_rd_req(krb5_context context,
     size = krb5_storage_read(sp, eaut.data, eaut.length);
     if (size != eaut.length) {
        ret = KRB4ET_INTK_PROT;
-       krb5_set_error_message(context, ret, "Failed reading v4 authenticator");
+       krb5_set_error_message(context, ret,
+                              N_("Failed reading v4 authenticator", ""));
        goto error;
     }
 
@@ -841,7 +850,7 @@ _krb5_krb_rd_req(krb5_context context,
     sp = krb5_storage_from_data(&aut);
     if (sp == NULL) {
        ret = ENOMEM;
-       krb5_set_error_message(context, ret, "alloc: out of memory");
+       krb5_set_error_message(context, ret, N_("malloc: out of memory", ""));
        goto error;
     }
 
@@ -862,13 +871,14 @@ _krb5_krb_rd_req(krb5_context context,
        strcmp(ad->pinst, r_instance) != 0 ||
        strcmp(ad->prealm, r_realm) != 0) {
        ret = KRB4ET_RD_AP_INCON;
-       krb5_set_error_message(context, ret, "v4 principal mismatch");
+       krb5_set_error_message(context, ret, N_("v4 principal mismatch", ""));
        goto error;
     }
-    
+
     if (from_addr && ad->address && from_addr != ad->address) {
        ret = KRB4ET_RD_AP_BADD;
-       krb5_set_error_message(context, ret, "v4 bad address in ticket");
+       krb5_set_error_message(context, ret,
+                              N_("v4 bad address in ticket", ""));
        goto error;
     }
 
@@ -876,23 +886,24 @@ _krb5_krb_rd_req(krb5_context context,
     delta_t = abs((int)(tv.tv_sec - r_time_sec));
     if (delta_t > CLOCK_SKEW) {
         ret = KRB4ET_RD_AP_TIME;
-       krb5_set_error_message(context, ret, "v4 clock skew");
+       krb5_set_error_message(context, ret, N_("v4 clock skew", ""));
        goto error;
     }
 
     /* Now check for expiration of ticket */
 
     tkt_age = tv.tv_sec - ad->time_sec;
-    
+
     if ((tkt_age < 0) && (-tkt_age > CLOCK_SKEW)) {
         ret = KRB4ET_RD_AP_NYV;
-       krb5_set_error_message(context, ret, "v4 clock skew for expiration");
+       krb5_set_error_message(context, ret,
+                              N_("v4 clock skew for expiration", ""));
        goto error;
     }
 
     if (tv.tv_sec > _krb5_krb_life_to_time(ad->time_sec, ad->life)) {
        ret = KRB4ET_RD_AP_EXP;
-       krb5_set_error_message(context, ret, "v4 ticket expired");
+       krb5_set_error_message(context, ret, N_("v4 ticket expired", ""));
        goto error;
     }
 
@@ -917,7 +928,7 @@ _krb5_krb_rd_req(krb5_context context,
        krb5_storage_free(sp);
 
     if (ret)
-       krb5_clear_error_string(context);
+       krb5_clear_error_message(context);
 
     return ret;
 }
@@ -938,3 +949,5 @@ _krb5_krb_free_auth_data(krb5_context context, struct _krb5_krb_auth_data *ad)
     krb5_free_keyblock_contents(context, &ad->session);
     memset(ad, 0, sizeof(*ad));
 }
+
+#endif /* HEIMDAL_SMALLER */