Submitted By: Tushar Teredesai <tushar@linuxfromscratch.org>
Date: 2003-09-21
Initial Package Version: 1.1rc4
Origin: None.
Description: OpenOffice requires PAM headers in /usr/include/security; these headers
are not available in most of the LFS based systems. This patch removes the need for
PAM headers by removing the functions that use PAM. This patch is part
of the BLFS book.
diff -ur oo_1.1rc4_src.orig/sal/osl/unx/security.c oo_1.1rc4_src/sal/osl/unx/security.c
--- oo_1.1rc4_src.orig/sal/osl/unx/security.c	2003-04-11 09:23:49.000000000 -0500
+++ oo_1.1rc4_src/sal/osl/unx/security.c	2003-09-21 00:37:09.000000000 -0500
@@ -133,8 +133,6 @@
  *
  */
 
-#include <security/pam_appl.h>
-
 typedef struct {
 	char* name;
 	char* password;
@@ -143,10 +141,10 @@
 typedef struct {
 	int (*pam_start)(const char *service_name, const char *user,
 		     	     const struct pam_conv *pam_conversation,
-		     		 pam_handle_t **pamh);
-	int (*pam_end)          (pam_handle_t *pamh, int pam_status);
-	int (*pam_authenticate) (pam_handle_t *pamh, int flags);
-	int (*pam_acct_mgmt)    (pam_handle_t *pamh, int flags);
+		     		 void **pamh);
+	int (*pam_end)          (void *pamh, int pam_status);
+	int (*pam_authenticate) (void *pamh, int flags);
+	int (*pam_acct_mgmt)    (void *pamh, int flags);
 } sal_PamModule;
 
 /*
@@ -164,69 +162,7 @@
 osl_PamConversation (int num_msg, const struct pam_message **msgm,
                      struct pam_response **response, void *appdata_ptr)
 {
-	int	  		i;
-	sal_Bool	error;
-	sal_PamData         *pam_data;
-	struct pam_response *p_reply;
-
-	/* resource initialization */
-	pam_data = (sal_PamData*) appdata_ptr;
-	p_reply  = (struct pam_response *) calloc( num_msg, 
-											   sizeof(struct pam_response));
-	if ( p_reply == NULL || pam_data == NULL )
-	{
-		if ( p_reply != NULL )
-			free ( p_reply );
-		*response = NULL;
-		return PAM_CONV_ERR;
-	}
-
-	/* pseudo dialog */
-	error = sal_False;
-	for ( i = 0; i < num_msg ; i++ )
-	{
-		switch ( msgm[ i ]->msg_style )
-		{
-			case PAM_PROMPT_ECHO_OFF: 
-				p_reply[ i ].resp_retcode = 0;
-				p_reply[ i ].resp 		  = strdup( pam_data->password );
-			 	break;
-			case PAM_PROMPT_ECHO_ON:  
-				p_reply[ i ].resp_retcode = 0;
-				p_reply[ i ].resp 		= strdup( pam_data->name );
-				break;
-			case PAM_ERROR_MSG:
-			case PAM_TEXT_INFO:
- 			case PAM_BINARY_PROMPT:
-			case PAM_BINARY_MSG:
-				p_reply[ i ].resp_retcode 	= 0;
-				p_reply[ i ].resp 			= NULL;
-				break;
-			default:
-				error = sal_True; 
-				break;
-		}
-	}
-
-	/* free resources on error */
-	if ( error )
-	{
-		for ( i = 0; i < num_msg ; i++ )
-			if ( p_reply[ i ].resp )
-			{
-				memset ( p_reply[ i ].resp, 0, 
-						 strlen( p_reply[ i ].resp ) );  
-				free   ( p_reply[ i ].resp );
-			}
-		free ( p_reply );
-
-		*response = NULL;
-		return PAM_CONV_ERR;
-	}
-
-	/* well done */
-	*response = p_reply;
-	return PAM_SUCCESS;
+	return -1;
 }
 
 /*
@@ -239,45 +175,6 @@
 static sal_PamModule* osl_getPAM()
 {
 	static sal_PamModule *pam_module = NULL;
-	static sal_Bool load_once = sal_False;
-
-	if ( !load_once )
-	{
-		/* get library-handle. cannot use osl-module, since 
- 		   RTLD_GLOBAL is required for PAM-0.64 RH 5.2 
-		   (but not for PAM-0.66 RH 6.0) */
-		void *pam_hdl;
-		
-		pam_hdl = dlopen( "libpam.so", RTLD_GLOBAL | RTLD_LAZY );  
-		
-		if ( pam_hdl != NULL )
-			pam_module = (sal_PamModule*)calloc( 1, sizeof(sal_PamModule) );
-		
-		/* load functions */
-		if ( pam_module  != NULL )
-		{
-			pam_module->pam_acct_mgmt = (int (*)(pam_handle_t *, int)) dlsym ( pam_hdl, "pam_acct_mgmt" );
-			pam_module->pam_authenticate 
-									  = (int (*)(pam_handle_t *, int)) dlsym ( pam_hdl, "pam_authenticate" );
-			pam_module->pam_end       = (int (*)(pam_handle_t *, int)) dlsym ( pam_hdl, "pam_end" );
-			pam_module->pam_start     = (int (*)(const char *, const char *, const struct pam_conv *, pam_handle_t **)) dlsym ( pam_hdl, "pam_start" );
-
-			/* free resources, if not completely successful */
-			if (   (pam_module->pam_start 		 == NULL) 
-				|| (pam_module->pam_end 		 == NULL)  
-				|| (pam_module->pam_authenticate == NULL) 
-				|| (pam_module->pam_acct_mgmt 	 == NULL) )
-			{
-				free( pam_module );
-				pam_module = NULL;
-				dlclose( pam_hdl );
-			}
-		}
-
-		/* never try again */
-		load_once = sal_True;
-	}
-
 	return pam_module;	
 }
 
@@ -289,35 +186,6 @@
 osl_PamAuthentification( const sal_Char* name, const sal_Char* password )
 {
 	sal_Bool success = sal_False;
-
-	sal_PamModule* pam_module;
-
-	pam_module = osl_getPAM();
-	if ( pam_module != NULL )
-	{
-		pam_handle_t   *pam_handle = NULL;
-		struct pam_conv pam_conversation;
-		sal_PamData     pam_data;
-
-		int				return_value;
-
-		pam_data.name     = (char*) name;
-		pam_data.password = (char*) password; 
-	
-		pam_conversation.conv 		 = osl_PamConversation;
-		pam_conversation.appdata_ptr = (void*)(&pam_data); 
-
-  		return_value = pam_module->pam_start( "su", name, 
-			&pam_conversation, &pam_handle);
-		if (return_value == PAM_SUCCESS ) 
-			return_value = pam_module->pam_authenticate(pam_handle, 0);
-  		if (return_value == PAM_SUCCESS ) 
-			return_value = pam_module->pam_acct_mgmt(pam_handle, 0);
-		pam_module->pam_end( pam_handle, return_value );
-	
-		success = (sal_Bool)(return_value == PAM_SUCCESS);
-	}
-
   	return success;
 }
 
