From nsayer@quack.kfu.com  Wed Jul 18 11:04:22 2001
Return-Path: <nsayer@quack.kfu.com>
Received: from quack.kfu.com (quack.kfu.com [205.178.90.194])
	by hub.freebsd.org (Postfix) with ESMTP id 81D2837B401
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 18 Jul 2001 11:04:22 -0700 (PDT)
	(envelope-from nsayer@quack.kfu.com)
Received: from medusa.kfu.com (medusa.kfu.com [3ffe:1200:301b:0:290:27ff:fed1:576b])
	by quack.kfu.com (8.11.3/8.11.3) with ESMTP id f6II4GJ97068
	(using TLSv1/SSLv3 with cipher EDH-RSA-DES-CBC3-SHA (168 bits) verified OK)
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 18 Jul 2001 11:04:22 -0700 (PDT)
	(envelope-from nsayer@quack.kfu.com)
Received: (from nsayer@localhost)
	by medusa.kfu.com (8.11.4/8.11.3) id f6II4GD23140;
	Wed, 18 Jul 2001 11:04:16 -0700 (PDT)
	(envelope-from nsayer)
Message-Id: <200107181804.f6II4GD23140@medusa.kfu.com>
Date: Wed, 18 Jul 2001 11:04:16 -0700 (PDT)
From: nsayer@quack.kfu.com
Reply-To: nsayer@quack.kfu.com
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: cyrus-sasl port pwcheck should allow PAM
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         29068
>Category:       ports
>Synopsis:       cyrus-sasl port pwcheck should allow PAM
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    nsayer
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 18 11:10:01 PDT 2001
>Closed-Date:    Sat Jan 19 19:16:09 PST 2002
>Last-Modified:  Sat Jan 19 19:16:32 PST 2002
>Originator:     Nick Sayer
>Release:        FreeBSD 4.3-RELEASE i386
>Organization:
just me
>Environment:
System: FreeBSD medusa.kfu.com 4.3-RELEASE FreeBSD 4.3-RELEASE #6: Sat Apr 21 08:52:25 PDT 2001 nsayer@medusa.kfu.com:/usr/obj/usr/src/sys/MEDUSA i386


cyrus-sasl port (SASL v1.5.x).

>Description:

cyrus imap can't typically use PAM directly since it doesn't run as
root. It must use pwcheck, but pwcheck doesn't normally use PAM.

>How-To-Repeat:

>Fix:

After applying this patch, cyrus-sasl can be built with
PWCHECK_USE_PAM=1 to generate a pam-aware pwcheck.

--- Makefile	2001/05/21 20:30:49	1.24
+++ Makefile	2001/07/18 18:00:12
@@ -113,6 +113,11 @@
 pre-configure:
 	@(cd ${WRKSRC} && ${AUTOHEADER})
 
+post-configure:
+.if defined(PWCHECK_USE_PAM)
+	cd ${WRKSRC} && ${PATCH} < ${FILESDIR}/special-pwcheck-ptch
+.endif
+
 # Create Cyrus user and group
 pre-install:
 	@${SH} ${PKGINSTALL} ${PKGNAME} PRE-INSTALL

--- /dev/null	Wed Jul 18 10:59:10 2001
+++ files/special-pwcheck-ptch	Wed Jul 18 10:55:57 2001
@@ -0,0 +1,137 @@
+--- pwcheck/Makefile.orig	Wed Jul 18 10:52:38 2001
++++ pwcheck/Makefile	Wed Jul 18 10:53:53 2001
+@@ -113,7 +113,7 @@
+ PLAIN_LIBS = -lcrypt -lpam
+ PURECOV = 
+ PURIFY = 
+-PWCHECKMETH = getpwnam
++PWCHECKMETH = pam
+ RANLIB = ranlib
+ SASL_DB_BACKEND = db_ndbm.lo
+ SASL_DB_LIB = 
+@@ -131,9 +131,9 @@
+ sbin_PROGRAMS = pwcheck
+ 
+ pwcheck_SOURCES = pwcheck.c
+-EXTRA_pwcheck_SOURCES = pwcheck_getpwnam.c pwcheck_getspnam.c
+-pwcheck_DEPENDECIES = pwcheck_getpwnam.lo
+-pwcheck_LDADD = pwcheck_getpwnam.lo -lcrypt 
++EXTRA_pwcheck_SOURCES = pwcheck_getpwnam.c pwcheck_getspnam.c pwcheck_pam.c
++pwcheck_DEPENDECIES = pwcheck_pam.lo
++pwcheck_LDADD = pwcheck_pam.lo -lpam
+ mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
+ CONFIG_HEADER = ../config.h
+ CONFIG_CLEAN_FILES = 
+@@ -145,7 +145,7 @@
+ LDFLAGS = -L/usr/local/lib -R/usr/local/lib -L/usr/lib -R/usr/lib 
+ LIBS = 
+ pwcheck_OBJECTS =  pwcheck.o
+-pwcheck_DEPENDENCIES =  pwcheck_getpwnam.lo
++pwcheck_DEPENDENCIES =  pwcheck_pam.lo
+ pwcheck_LDFLAGS = 
+ CFLAGS = -Wall -W -O -pipe 
+ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+--- /dev/null	Wed Jul 18 10:54:31 2001
++++ pwcheck/pwcheck_pam.c	Wed Jul 18 10:39:15 2001
+@@ -0,0 +1,101 @@
++
++#include <security/pam_appl.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++
++/* Static variables used to communicate between the conversation function
++ * and the server_login function
++ */
++static char *PAM_username;
++static char *PAM_password;
++
++/* PAM conversation function
++ */
++static int PAM_conv (int num_msg,
++                     const struct pam_message **msg,
++                     struct pam_response **resp,
++                     void *appdata_ptr) {
++  int replies = 0;
++  struct pam_response *reply = NULL;
++
++  #define COPY_STRING(s) (s) ? strdup(s) : NULL
++
++  reply = malloc(sizeof(struct pam_response) * num_msg);
++  if (!reply) return PAM_CONV_ERR;
++
++  for (replies = 0; replies < num_msg; replies++) {
++    switch (msg[replies]->msg_style) {
++      case PAM_PROMPT_ECHO_ON:
++        reply[replies].resp_retcode = PAM_SUCCESS;
++        reply[replies].resp = COPY_STRING(PAM_username);
++          /* PAM frees resp */
++        break;
++      case PAM_PROMPT_ECHO_OFF:
++        reply[replies].resp_retcode = PAM_SUCCESS;
++        reply[replies].resp = COPY_STRING(PAM_password);
++          /* PAM frees resp */
++        break;
++      case PAM_TEXT_INFO:
++        /* fall through */
++      case PAM_ERROR_MSG:
++        /* ignore it, but pam still wants a NULL response... */
++        reply[replies].resp_retcode = PAM_SUCCESS;
++        reply[replies].resp = NULL;
++        break;
++      default:
++        /* Must be an error of some sort... */
++        free (reply);
++        return PAM_CONV_ERR;
++    }
++  }
++  *resp = reply;
++  return PAM_SUCCESS;
++}
++
++static struct pam_conv PAM_conversation = {
++    PAM_conv,
++    NULL
++};
++
++/* Server log in
++ * Accepts: user name string
++ *          password string
++ * Returns: "OK" if password validated, error message otherwise
++ */ 
++ 
++char *pwcheck(char *username, char *password)
++{
++  pam_handle_t *pamh;
++  int pam_error;
++
++  /* PAM only handles authentication, not user information. */
++  if ( !(username && password && strlen(username) && strlen(password)) )
++      return "Incorrect username";
++
++  /* validate password */
++
++  PAM_password = password;
++  PAM_username = username;
++  fprintf(stderr, "checking %s\n", username);
++  pam_error = pam_start("cyrus", username, &PAM_conversation, &pamh);
++  if (pam_error == PAM_SUCCESS) 
++    pam_error = pam_authenticate(pamh, 0);
++    
++  if (pam_error == PAM_SUCCESS) 
++    pam_error = pam_acct_mgmt(pamh, 0);
++
++  if ( pam_error == PAM_SUCCESS) 
++    fprintf(stderr, "\tauthenticated %s\n", username);
++  else
++    fprintf(stderr, "\tfailed to authenticate %s\n", username);
++  
++  if(pam_end(pamh, pam_error) != PAM_SUCCESS) {
++    pamh = NULL;
++    fprintf(stderr, "pwcheck: failed to release authenticator\n");
++    exit(1);
++  }
++  return ( pam_error == PAM_SUCCESS ? "OK" : "Incorrect passwd" );
++}
++
++
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports->hetzels@westbend.net 
Responsible-Changed-By: nsayer 
Responsible-Changed-When: Wed Jul 18 11:15:44 PDT 2001 
Responsible-Changed-Why:  
Over to the port maintainer 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=29068 
Responsible-Changed-From-To: hetzels@westbend.net->nsayer 
Responsible-Changed-By: ru 
Responsible-Changed-When: Mon Aug 20 09:42:33 PDT 2001 
Responsible-Changed-Why:  
This doesn't seem to work and results in a dead PR. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=29068 

From: "Scot W. Hetzel" <hetzels@westbend.net>
To: "FreeBSD-GNATS" <FreeBSD-gnats-submit@FreeBSD.ORG>,
	<nsayer@quack.kfu.com>
Cc:  
Subject: Re: ports/29068: cyrus-sasl port pwcheck should allow PAM
Date: Sat, 19 Jan 2002 17:07:45 -0600

 PR 29068 can be closed as I have added a pwcheck_pam daemon to the
 cyrus-sasl port with PR 34068.
 
 Scot
 
State-Changed-From-To: open->closed 
State-Changed-By: nsayer 
State-Changed-When: Sat Jan 19 19:16:09 PST 2002 
State-Changed-Why:  
See PR 34068, which is probably a better solution to this same issue. 


http://www.FreeBSD.org/cgi/query-pr.cgi?pr=29068 
>Unformatted:
