head	1.6;
access;
symbols
	RELEASE_4_3_0:1.4
	RELEASE_4_2_0:1.3;
locks; strict;
comment	@# @;


1.6
date	2001.07.24.17.14.44;	author nectar;	state dead;
branches;
next	1.5;

1.5
date	2001.06.11.18.38.46;	author nectar;	state Exp;
branches;
next	1.4;

1.4
date	2001.01.24.20.36.33;	author nectar;	state Exp;
branches;
next	1.3;

1.3
date	2000.11.06.20.00.02;	author nectar;	state Exp;
branches;
next	1.2;

1.2
date	2000.11.06.19.56.21;	author nectar;	state Exp;
branches;
next	1.1;

1.1
date	2000.11.06.19.01.43;	author nectar;	state Exp;
branches;
next	;


desc
@@


1.6
log
@Update pam_krb5 1.0 -> 1.0.1.
Change MASTER_SITES.

NB: This  versioning is  bogus.  Unfortunately,  there is  no official
release of  pam_krb5 yet,  but it has  substantially changed.   I made
this release based on what is in CVS.
@
text
@--- compat_heimdal.c.orig	Mon Jun 11 13:29:54 2001
+++ compat_heimdal.c	Mon Jun 11 13:32:00 2001
@@@@ -0,0 +1,125 @@@@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <krb5.h>
+#include <security/pam_appl.h>
+#include <security/pam_modules.h>
+#include "pam_krb5.h"
+
+const char *
+compat_princ_component(krb5_context context, krb5_principal princ, int n)
+{
+	return princ->name.name_string.val[n];
+}
+
+void
+compat_free_data_contents(krb5_context context, krb5_data *data)
+{
+	krb5_xfree(data->data);
+}
+
+static krb5_error_code
+heimdal_pam_prompter(krb5_context context, void *data, const char *name,
+    const char *banner, int num_prompts, krb5_prompt prompts[])
+{
+    int		pam_prompts = num_prompts;
+    int		pamret, i;
+
+    struct pam_message	*msg;
+    struct pam_response	*resp = NULL;
+    struct pam_conv	*conv;
+    pam_handle_t	*pamh = (pam_handle_t *) data;
+
+    if ((pamret = pam_get_item(pamh, PAM_CONV, (const void **) &conv)) != 0)
+	return KRB5KRB_ERR_GENERIC;
+
+    if (banner)
+	pam_prompts++;
+
+    msg = calloc(sizeof(struct pam_message) * pam_prompts, 1);
+    if (!msg)
+	return ENOMEM;
+
+    /* Now use pam_prompts as an index */
+    pam_prompts = 0;
+
+    if (banner) {
+	msg[pam_prompts].msg = malloc(strlen(banner) + 1);
+	if (!msg[pam_prompts].msg)
+	    goto cleanup;
+	strcpy((char *) msg[pam_prompts].msg, banner);
+	msg[pam_prompts].msg_style = PAM_TEXT_INFO;
+	pam_prompts++;
+    }
+
+    for (i = 0; i < num_prompts; i++) {
+	msg[pam_prompts].msg = malloc(strlen(prompts[i].prompt) + 3);
+	if (!msg[pam_prompts].msg)
+	    goto cleanup;
+	sprintf((char *) msg[pam_prompts].msg, "%s: ", prompts[i].prompt);
+	msg[pam_prompts].msg_style = prompts[i].hidden ? PAM_PROMPT_ECHO_OFF
+						       : PAM_PROMPT_ECHO_ON;
+	pam_prompts++;
+    }
+
+    if ((pamret = conv->conv(pam_prompts, (const struct pam_message **) &msg, 
+      &resp, conv->appdata_ptr)) != 0) 
+	goto cleanup;
+
+    if (!resp)
+	goto cleanup;
+
+    /* Reuse pam_prompts as a starting index */
+    pam_prompts = 0;
+    if (banner)
+	pam_prompts++;
+
+    for (i = 0; i < num_prompts; i++, pam_prompts++) {
+	register int len;
+	if (!resp[pam_prompts].resp) {
+	    pamret = PAM_AUTH_ERR;
+	    goto cleanup;
+	}
+	len = strlen(resp[pam_prompts].resp); /* Help out the compiler */
+	if (len > prompts[i].reply->length) {
+	    pamret = PAM_AUTH_ERR;
+	    goto cleanup;
+	}
+	memcpy(prompts[i].reply->data, resp[pam_prompts].resp, len);
+	prompts[i].reply->length = len;
+    }
+
+cleanup:
+    /* pam_prompts is correct at this point */
+
+    for (i = 0; i < pam_prompts; i++) {
+	if (msg[i].msg)
+	    free((char *) msg[i].msg);
+    }
+    free(msg);
+
+    if (resp) {
+	for (i = 0; i < pam_prompts; i++) {
+	    /*
+	     * Note that PAM is underspecified wrt free()'ing resp[i].resp.
+	     * It's not clear if I should free it, or if the application
+	     * has to. Therefore most (all?) apps won't free() it, and I
+	     * can't either, as I am not sure it was malloc()'d. All PAM
+	     * implementations I've seen leak memory here. Not so bad, IFF
+	     * you fork/exec for each PAM authentication (as is typical).
+	     */
+#if 0
+	    if (resp[i].resp)
+		free(resp[i].resp);
+#endif /* 0 */
+	}
+	/* This does not lose resp[i].resp if the application saved a copy. */
+	free(resp);
+    }
+
+    return (pamret ? KRB5KRB_ERR_GENERIC : 0);
+}
+
+krb5_prompter_fct pam_prompter = heimdal_pam_prompter;
@


1.5
log
@Update for heimdal-0.3f interface changes.
@
text
@@


1.4
log
@Bug fixes and paranoia:

compat_heimdal.c:
   = Stop shooting at feet when freeing a particular chunk of memory.
     Found by complaints from free(), and pinpointed with MALLOC_OPTIONS=A.
pam_krb5_auth.c:
   = In addition to dropping and restoring uid when delving in /tmp,
     drop and restore gid.
   = Explicitly set permissions on the credentials cache for good measure.

The following was
Obtained from:	Sam Hartman <hartmans@@mit.edu> via bugs.debian.org

support.c:
   = verify_krb_v5_tgt: Do a little more to prevent KDC spoofing.
     Allow for a key separate from the host key to use only for PAM.
@
text
@d1 3
a3 3
--- compat_heimdal.c.orig	Wed Jan 24 12:40:26 2001
+++ compat_heimdal.c	Wed Jan 24 12:50:52 2001
@@@@ -0,0 +1,133 @@@@
a25 8
+krb5_error_code
+compat_cc_next_cred(krb5_context context, const krb5_ccache id, 
+    krb5_cc_cursor *cursor, krb5_creds *creds)
+{
+	return krb5_cc_next_cred(context, id, creds, cursor);
+}
+
+
d27 2
a28 2
+heimdal_pam_prompter(krb5_context context, void *data, const char *banner, int 
+  num_prompts, krb5_prompt prompts[])
@


1.3
log
@(forced commit)

Double oops.  I initially added a version of this port that was a bit
dated.  The last commit brings it up to date: in particular, MIT Kerberos
support was broken in theory (though not in practice).
@
text
@d1 2
a2 2
--- compat_heimdal.c.orig	Mon Nov  6 13:27:02 2000
+++ compat_heimdal.c	Mon Nov  6 13:43:10 2000
d23 1
a23 1
+	krb5_xfree(data);
@


1.2
log
@Oops,
@
text
@@


1.1
log
@A Pluggable Authentication Module for Kerberos 5.
@
text
@d1 8
a8 3
--- compat_heimdal.c.orig	Mon Nov  6 10:21:49 2000
+++ compat_heimdal.c	Mon Nov  6 10:48:37 2000
@@@@ -0,0 +1,21 @@@@
d10 3
a12 1
+#include "krb5compat.h"
d32 105
@

