Remove a duplicate retval check
[sfrench/samba-autobuild/.git] / source3 / libsmb / clikrb5.c
index 9cd5cd3310909da2c7c6b53e0a51c62bb3ebe5cd..f940081072ae3cc183ccb585ff09cb43c8ceed7b 100644 (file)
 
 #ifdef HAVE_KRB5
 
-#ifdef HAVE_KRB5_KEYBLOCK_KEYVALUE /* Heimdal */
-#define KRB5_KEY_TYPE(k)       ((k)->keytype) 
-#define KRB5_KEY_LENGTH(k)     ((k)->keyvalue.length)
-#define KRB5_KEY_DATA(k)       ((k)->keyvalue.data)
-#define KRB5_KEY_DATA_CAST     void
-#else /* MIT */
-#define        KRB5_KEY_TYPE(k)        ((k)->enctype)
-#define KRB5_KEY_LENGTH(k)     ((k)->length)
-#define KRB5_KEY_DATA(k)       ((k)->contents)
-#define KRB5_KEY_DATA_CAST     krb5_octet
-#endif /* HAVE_KRB5_KEYBLOCK_KEYVALUE */
-
 #define GSSAPI_CHECKSUM      0x8003             /* Checksum type value for Kerberos */
 #define GSSAPI_BNDLENGTH     16                 /* Bind Length (rfc-1964 pg.3) */
 #define GSSAPI_CHECKSUM_SIZE (12+GSSAPI_BNDLENGTH)
 
-#if defined(TKT_FLG_OK_AS_DELEGATE ) && defined(HAVE_KRB5_FWD_TGT_CREDS) && defined(HAVE_KRB5_AUTH_CON_SET_REQ_CKSUMTYPE)
+#if defined(TKT_FLG_OK_AS_DELEGATE ) && defined(HAVE_KRB5_FWD_TGT_CREDS) && defined(HAVE_KRB5_AUTH_CON_SET_REQ_CKSUMTYPE) && defined(KRB5_AUTH_CONTEXT_USE_SUBKEY)
 static krb5_error_code ads_krb5_get_fwd_ticket( krb5_context context,
                                          krb5_auth_context *auth_context,
                                          krb5_creds *credsp,
@@ -723,7 +711,7 @@ static krb5_error_code ads_krb5_mk_req(krb5_context context,
                *expire_time = (time_t)credsp->times.endtime;
        }
 
-#if defined(TKT_FLG_OK_AS_DELEGATE ) && defined(HAVE_KRB5_FWD_TGT_CREDS) && defined(HAVE_KRB5_AUTH_CON_SET_REQ_CKSUMTYPE)
+#if defined(TKT_FLG_OK_AS_DELEGATE ) && defined(HAVE_KRB5_FWD_TGT_CREDS) && defined(HAVE_KRB5_AUTH_CON_SET_REQ_CKSUMTYPE) && defined(KRB5_AUTH_CONTEXT_USE_SUBKEY)
        if( credsp->ticket_flags & TKT_FLG_OK_AS_DELEGATE ) {
                /* Fetch a forwarded TGT from the KDC so that we can hand off a 2nd ticket
                 as part of the kerberos exchange. */
@@ -761,16 +749,10 @@ static krb5_error_code ads_krb5_mk_req(krb5_context context,
                                                ccache,
                                                &in_data );
                if (retval) {
-                       DEBUG( 1, ("ads_krb5_get_fwd_ticket failed (%s)\n", error_message( retval ) ) );
-                       goto cleanup_creds;
-               }
-
-               if (retval) {
-                       DEBUG( 1, ("krb5_auth_con_set_req_cksumtype failed (%s)\n",
-                               error_message( retval ) ) );
+                       DEBUG( 1, ("ads_krb5_get_fwd_ticket failed (%s)\n",
+                                  error_message( retval ) ) );
                        goto cleanup_creds;
                }
-
        }
 #endif
 
@@ -1057,6 +1039,7 @@ get_key_from_keytab(krb5_context context,
        krb5_error_code ret;
        krb5_keytab keytab;
        char *name = NULL;
+       krb5_keyblock *keyp;
 
        /* We have to open a new keytab handle here, as MIT does
           an implicit open/getnext/close on krb5_kt_get_entry. We
@@ -1089,14 +1072,9 @@ get_key_from_keytab(krb5_context context,
                goto out;
        }
 
-#ifdef HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK /* Heimdal */
-       ret = krb5_copy_keyblock(context, &entry.keyblock, out_key);
-#elif defined(HAVE_KRB5_KEYTAB_ENTRY_KEY) /* MIT */
-       ret = krb5_copy_keyblock(context, &entry.key, out_key);
-#else
-#error UNKNOWN_KRB5_KEYTAB_ENTRY_FORMAT
-#endif
+       keyp = KRB5_KT_KEY(&entry);
 
+       ret = krb5_copy_keyblock(context, keyp, out_key);
        if (ret) {
                DEBUG(0,("get_key_from_keytab: failed to copy key: %s\n", error_message(ret)));
                goto out;
@@ -1584,15 +1562,9 @@ done:
 #endif /* HAVE_KRB5_GET_INIT_CREDS_OPT_FREE */
 }
 
- krb5_enctype smb_get_enctype_from_kt_entry(const krb5_keytab_entry *kt_entry)
+ krb5_enctype smb_get_enctype_from_kt_entry(krb5_keytab_entry *kt_entry)
 {
-#ifdef HAVE_KRB5_KEYTAB_ENTRY_KEY              /* MIT */
-       return kt_entry->key.enctype;
-#elif defined(HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK) /* Heimdal */
-       return kt_entry->keyblock.keytype;
-#else
-#error UNKNOWN_KRB5_KEYTAB_ENTRY_KEYBLOCK_FORMAT
-#endif
+       return KRB5_KEY_TYPE(KRB5_KT_KEY(kt_entry));
 }
 
 
@@ -1813,7 +1785,7 @@ krb5_error_code smb_krb5_keytab_name(TALLOC_CTX *mem_ctx,
        return ret;
 }
 
-#if defined(TKT_FLG_OK_AS_DELEGATE ) && defined(HAVE_KRB5_FWD_TGT_CREDS) && defined(HAVE_KRB5_AUTH_CON_SET_REQ_CKSUMTYPE)
+#if defined(TKT_FLG_OK_AS_DELEGATE ) && defined(HAVE_KRB5_FWD_TGT_CREDS) && defined(HAVE_KRB5_AUTH_CON_SET_REQ_CKSUMTYPE) && defined(KRB5_AUTH_CONTEXT_USE_SUBKEY)
 /**************************************************************
 Routine: ads_krb5_get_fwd_ticket
  Description:
@@ -1877,7 +1849,7 @@ static krb5_error_code ads_krb5_get_fwd_ticket( krb5_context context,
           (APPLICATION 22) so that we can pack it on the end of the structure.
        */
 
-       pChksum = SMB_MALLOC(GSSAPI_CHECKSUM_SIZE + fwdData.length );
+       pChksum = (char *)SMB_MALLOC(GSSAPI_CHECKSUM_SIZE + fwdData.length );
        if (!pChksum) {
                retval = ENOMEM;
                goto out;
@@ -1910,7 +1882,7 @@ static krb5_error_code ads_krb5_get_fwd_ticket( krb5_context context,
        }
 
        /* We now have a service ticket, now turn it into an AP-REQ. */
-       authenticator->length = ntohs(fwdData.length + GSSAPI_CHECKSUM_SIZE);
+       authenticator->length = fwdData.length + GSSAPI_CHECKSUM_SIZE;
 
        /* Caller should call free() when they're done with this. */
        authenticator->data = (char *)pChksum;