Imported Upstream version 1.20.1
[platform/upstream/krb5.git] / src / ccapi / common / cci_cred_union.c
index 4c89816..424a93d 100644 (file)
 
 #include "cci_common.h"
 
-#ifdef TARGET_OS_MAC
-#pragma mark -
-#endif
-
-/* ------------------------------------------------------------------------ */
-
-static cc_uint32 cci_credentials_v4_release (cc_credentials_v4_t *io_v4creds)
-{
-    cc_int32 err = ccNoError;
-
-    if (!io_v4creds) { err = ccErrBadParam; }
-
-    if (!err) {
-        memset (io_v4creds, 0, sizeof (*io_v4creds));
-        free (io_v4creds);
-    }
-
-    return err;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static cc_uint32 cci_credentials_v4_read (cc_credentials_v4_t **out_v4creds,
-                                          k5_ipc_stream          io_stream)
-{
-    cc_int32 err = ccNoError;
-    cc_credentials_v4_t *v4creds = NULL;
-
-    if (!io_stream  ) { err = cci_check_error (ccErrBadParam); }
-    if (!out_v4creds) { err = cci_check_error (ccErrBadParam); }
-
-    if (!err) {
-        v4creds = malloc (sizeof (*v4creds));
-        if (!v4creds) { err = cci_check_error (ccErrNoMem); }
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_read_uint32 (io_stream, &v4creds->version);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_read (io_stream, v4creds->principal, cc_v4_name_size);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_read (io_stream, v4creds->principal_instance, cc_v4_instance_size);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_read (io_stream, v4creds->service, cc_v4_name_size);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_read (io_stream, v4creds->service_instance, cc_v4_instance_size);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_read (io_stream, v4creds->realm, cc_v4_realm_size);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_read (io_stream, v4creds->session_key, cc_v4_key_size);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_read_int32 (io_stream, &v4creds->kvno);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_read_int32 (io_stream, &v4creds->string_to_key_type);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_read_time (io_stream, &v4creds->issue_date);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_read_int32 (io_stream, &v4creds->lifetime);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_read_uint32 (io_stream, &v4creds->address);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_read_int32 (io_stream, &v4creds->ticket_size);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_read (io_stream, v4creds->ticket, cc_v4_ticket_size);
-    }
-
-    if (!err) {
-        *out_v4creds = v4creds;
-        v4creds = NULL;
-    }
-
-    free (v4creds);
-
-    return cci_check_error (err);
-}
-
-/* ------------------------------------------------------------------------ */
-
-static cc_uint32 cci_credentials_v4_write (cc_credentials_v4_t *in_v4creds,
-                                           k5_ipc_stream         io_stream)
-{
-    cc_int32 err = ccNoError;
-
-    if (!io_stream ) { err = cci_check_error (ccErrBadParam); }
-    if (!in_v4creds) { err = cci_check_error (ccErrBadParam); }
-
-    if (!err) {
-        err = krb5int_ipc_stream_write_uint32 (io_stream, in_v4creds->version);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_write (io_stream, in_v4creds->principal, cc_v4_name_size);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_write (io_stream, in_v4creds->principal_instance, cc_v4_instance_size);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_write (io_stream, in_v4creds->service, cc_v4_name_size);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_write (io_stream, in_v4creds->service_instance, cc_v4_instance_size);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_write (io_stream, in_v4creds->realm, cc_v4_realm_size);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_write (io_stream, in_v4creds->session_key, cc_v4_key_size);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_write_int32 (io_stream, in_v4creds->kvno);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_write_int32 (io_stream, in_v4creds->string_to_key_type);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_write_time (io_stream, in_v4creds->issue_date);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_write_int32 (io_stream, in_v4creds->lifetime);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_write_uint32 (io_stream, in_v4creds->address);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_write_int32 (io_stream, in_v4creds->ticket_size);
-    }
-
-    if (!err) {
-        err = krb5int_ipc_stream_write (io_stream, in_v4creds->ticket, cc_v4_ticket_size);
-    }
-
-    return cci_check_error (err);
-}
-
-#ifdef TARGET_OS_MAC
-#pragma mark -
-#endif
-
 /* ------------------------------------------------------------------------ */
 
 static cc_uint32 cci_cc_data_contents_release (cc_data *io_ccdata)
@@ -600,9 +425,7 @@ cc_uint32 cci_credentials_union_release (cc_credentials_union *io_cred_union)
     if (!io_cred_union) { err = ccErrBadParam; }
 
     if (!err) {
-        if (io_cred_union->version == cc_credentials_v4) {
-            cci_credentials_v4_release (io_cred_union->credentials.credentials_v4);
-        } else if (io_cred_union->version == cc_credentials_v5) {
+        if (io_cred_union->version == cc_credentials_v5) {
             cci_credentials_v5_release (io_cred_union->credentials.credentials_v5);
         }
         free (io_cred_union);
@@ -632,11 +455,7 @@ cc_uint32 cci_credentials_union_read (cc_credentials_union **out_credentials_uni
     }
 
     if (!err) {
-        if (credentials_union->version == cc_credentials_v4) {
-            err = cci_credentials_v4_read (&credentials_union->credentials.credentials_v4,
-                                           io_stream);
-
-        } else if (credentials_union->version == cc_credentials_v5) {
+        if (credentials_union->version == cc_credentials_v5) {
             err = cci_credentials_v5_read (&credentials_union->credentials.credentials_v5,
                                            io_stream);
 
@@ -671,11 +490,7 @@ cc_uint32 cci_credentials_union_write (const cc_credentials_union *in_credential
     }
 
     if (!err) {
-        if (in_credentials_union->version == cc_credentials_v4) {
-            err = cci_credentials_v4_write (in_credentials_union->credentials.credentials_v4,
-                                            io_stream);
-
-        } else if (in_credentials_union->version == cc_credentials_v5) {
+        if (in_credentials_union->version == cc_credentials_v5) {
             err = cci_credentials_v5_write (in_credentials_union->credentials.credentials_v5,
                                             io_stream);
 
@@ -714,11 +529,7 @@ cc_uint32 cci_cred_union_release (cred_union *io_cred_union)
     if (!io_cred_union) { err = ccErrBadParam; }
 
     if (!err) {
-        if (io_cred_union->cred_type == CC_CRED_V4) {
-            memset (io_cred_union->cred.pV4Cred, 0, sizeof (cc_credentials_v4_compat));
-            free (io_cred_union->cred.pV4Cred);
-
-        } else if (io_cred_union->cred_type == CC_CRED_V5) {
+        if (io_cred_union->cred_type == CC_CRED_V5) {
             free (io_cred_union->cred.pV5Cred->client);
             free (io_cred_union->cred.pV5Cred->server);
             cci_cc_data_contents_release (&io_cred_union->cred.pV5Cred->keyblock);
@@ -829,36 +640,7 @@ cc_uint32 cci_credentials_union_to_cred_union (const cc_credentials_union  *in_c
     }
 
     if (!err) {
-        if (in_credentials_union->version == cc_credentials_v4) {
-            cc_credentials_v4_compat *compat_v4creds = NULL;
-
-            compat_v4creds = malloc (sizeof (*compat_v4creds));
-            if (!compat_v4creds) { err = cci_check_error (ccErrNoMem); }
-
-            if (!err) {
-                cc_credentials_v4_t *v4creds = in_credentials_union->credentials.credentials_v4;
-
-                compat_cred_union->cred_type = CC_CRED_V4;
-                compat_cred_union->cred.pV4Cred = compat_v4creds;
-
-                compat_v4creds->kversion = v4creds->version;
-                strncpy (compat_v4creds->principal,          v4creds->principal,          KRB_NAME_SZ+1);
-                strncpy (compat_v4creds->principal_instance, v4creds->principal_instance, KRB_INSTANCE_SZ+1);
-                strncpy (compat_v4creds->service,            v4creds->service,            KRB_NAME_SZ+1);
-                strncpy (compat_v4creds->service_instance,   v4creds->service_instance,   KRB_INSTANCE_SZ+1);
-                strncpy (compat_v4creds->realm,              v4creds->realm,              KRB_REALM_SZ+1);
-                memcpy (compat_v4creds->session_key, v4creds->session_key, 8);
-                compat_v4creds->kvno       = v4creds->kvno;
-                compat_v4creds->str_to_key = v4creds->string_to_key_type;
-                compat_v4creds->issue_date = v4creds->issue_date;
-                compat_v4creds->lifetime   = v4creds->lifetime;
-                compat_v4creds->address    = v4creds->address;
-                compat_v4creds->ticket_sz  = v4creds->ticket_size;
-                memcpy (compat_v4creds->ticket, v4creds->ticket, MAX_V4_CRED_LEN);
-                compat_v4creds->oops = 0;
-            }
-
-        } else if (in_credentials_union->version == cc_credentials_v5) {
+        if (in_credentials_union->version == cc_credentials_v5) {
             cc_credentials_v5_t *v5creds = in_credentials_union->credentials.credentials_v5;
             cc_credentials_v5_compat *compat_v5creds = NULL;
 
@@ -951,36 +733,7 @@ cc_uint32 cci_cred_union_to_credentials_union (const cred_union      *in_cred_un
     }
 
     if (!err) {
-        if (in_cred_union->cred_type == CC_CRED_V4) {
-            cc_credentials_v4_compat *compat_v4creds = in_cred_union->cred.pV4Cred;
-            cc_credentials_v4_t *v4creds = NULL;
-
-            if (!err) {
-                v4creds = malloc (sizeof (*v4creds));
-                if (!v4creds) { err = cci_check_error (ccErrNoMem); }
-            }
-
-            if (!err) {
-                creds_union->version = cc_credentials_v4;
-                creds_union->credentials.credentials_v4 = v4creds;
-
-                v4creds->version = compat_v4creds->kversion;
-                strncpy (v4creds->principal,          compat_v4creds->principal,          KRB_NAME_SZ);
-                strncpy (v4creds->principal_instance, compat_v4creds->principal_instance, KRB_INSTANCE_SZ);
-                strncpy (v4creds->service,            compat_v4creds->service,            KRB_NAME_SZ);
-                strncpy (v4creds->service_instance,   compat_v4creds->service_instance,   KRB_INSTANCE_SZ);
-                strncpy (v4creds->realm,              compat_v4creds->realm,              KRB_REALM_SZ);
-                memcpy (v4creds->session_key, compat_v4creds->session_key, 8);
-                v4creds->kvno               = compat_v4creds->kvno;
-                v4creds->string_to_key_type = compat_v4creds->str_to_key;
-                v4creds->issue_date         = compat_v4creds->issue_date;
-                v4creds->lifetime           = compat_v4creds->lifetime;
-                v4creds->address            = compat_v4creds->address;
-                v4creds->ticket_size        = compat_v4creds->ticket_sz;
-                memcpy (v4creds->ticket, compat_v4creds->ticket, MAX_V4_CRED_LEN);
-            }
-
-        } else if (in_cred_union->cred_type == CC_CRED_V5) {
+        if (in_cred_union->cred_type == CC_CRED_V5) {
             cc_credentials_v5_compat *compat_v5creds = in_cred_union->cred.pV5Cred;
             cc_credentials_v5_t *v5creds = NULL;
 
@@ -1072,26 +825,7 @@ cc_uint32 cci_cred_union_compare_to_credentials_union (const cred_union
     if (!out_equal           ) { err = cci_check_error (ccErrBadParam); }
 
     if (!err) {
-        if (in_cred_union_compat->cred_type == CC_CRED_V4 &&
-            in_credentials_union->version == cc_credentials_v4) {
-            cc_credentials_v4_compat *old_creds_v4 = in_cred_union_compat->cred.pV4Cred;
-            cc_credentials_v4_t *new_creds_v4 = in_credentials_union->credentials.credentials_v4;
-
-            if (old_creds_v4 && new_creds_v4 &&
-                !strcmp (old_creds_v4->principal,
-                         new_creds_v4->principal) &&
-                !strcmp (old_creds_v4->principal_instance,
-                         new_creds_v4->principal_instance) &&
-                !strcmp (old_creds_v4->service,
-                         new_creds_v4->service) &&
-                !strcmp (old_creds_v4->service_instance,
-                         new_creds_v4->service_instance) &&
-                !strcmp (old_creds_v4->realm, new_creds_v4->realm) &&
-                (old_creds_v4->issue_date == (long) new_creds_v4->issue_date)) {
-                equal = 1;
-            }
-
-        } else if (in_cred_union_compat->cred_type == CC_CRED_V5 &&
+        if (in_cred_union_compat->cred_type == CC_CRED_V5 &&
                    in_credentials_union->version == cc_credentials_v5) {
             cc_credentials_v5_compat *old_creds_v5 = in_cred_union_compat->cred.pV5Cred;
             cc_credentials_v5_t *new_creds_v5 = in_credentials_union->credentials.credentials_v5;