You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by pq...@apache.org on 2009/02/16 09:29:32 UTC

svn commit: r744859 - in /labs/orthrus/trunk: include/orthrus.h include/private/context.h src/ui/pam/pam_orthrus.c src/userdb.c

Author: pquerna
Date: Mon Feb 16 08:29:32 2009
New Revision: 744859

URL: http://svn.apache.org/viewvc?rev=744859&view=rev
Log:
Change the userdb interface to have a more open/close style, to make locking easier, and update the pam module accordingly.

Modified:
    labs/orthrus/trunk/include/orthrus.h
    labs/orthrus/trunk/include/private/context.h
    labs/orthrus/trunk/src/ui/pam/pam_orthrus.c
    labs/orthrus/trunk/src/userdb.c

Modified: labs/orthrus/trunk/include/orthrus.h
URL: http://svn.apache.org/viewvc/labs/orthrus/trunk/include/orthrus.h?rev=744859&r1=744858&r2=744859&view=diff
==============================================================================
--- labs/orthrus/trunk/include/orthrus.h (original)
+++ labs/orthrus/trunk/include/orthrus.h Mon Feb 16 08:29:32 2009
@@ -53,7 +53,8 @@
 
   
 /* User DB Interfaces. */
-orthrus_error_t* orthrus_userdb_set(orthrus_t *ort, const char *path);
+orthrus_error_t* orthrus_userdb_open(orthrus_t *ort, const char *path);
+orthrus_error_t* orthrus_userdb_close(orthrus_t *ort);
 
 orthrus_error_t* orthrus_userdb_get_challenge(orthrus_t *ort,
                                               const char *username,

Modified: labs/orthrus/trunk/include/private/context.h
URL: http://svn.apache.org/viewvc/labs/orthrus/trunk/include/private/context.h?rev=744859&r1=744858&r2=744859&view=diff
==============================================================================
--- labs/orthrus/trunk/include/private/context.h (original)
+++ labs/orthrus/trunk/include/private/context.h Mon Feb 16 08:29:32 2009
@@ -18,14 +18,15 @@
 #define _APACHE_ORTHRUS_PRIVATE_CONTEXT_H_
 
 #include "orthrus.h"
+#include <apr_file_io.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-
 struct orthrus_t {
   apr_pool_t *pool;
+  apr_file_t *userdb;
 };
 
 

Modified: labs/orthrus/trunk/src/ui/pam/pam_orthrus.c
URL: http://svn.apache.org/viewvc/labs/orthrus/trunk/src/ui/pam/pam_orthrus.c?rev=744859&r1=744858&r2=744859&view=diff
==============================================================================
--- labs/orthrus/trunk/src/ui/pam/pam_orthrus.c (original)
+++ labs/orthrus/trunk/src/ui/pam/pam_orthrus.c Mon Feb 16 08:29:32 2009
@@ -133,7 +133,7 @@
   }
 
   /* TODO: Get params from PAM  and make a compile time default */
-  err = orthrus_userdb_set(ort, ortuserdb);
+  err = orthrus_userdb_open(ort, ortuserdb);
   if (err) {
     ORT_LOG_ERR("pam_orthrus: Failed to open userdb at '%s': %s (%d)", ortuserdb, err->msg, err->err);
 		return (PAM_SYSTEM_ERR);
@@ -141,9 +141,16 @@
 
   err = orthrus_userdb_get_challenge(ort, pwd->pw_name, &challenge, pool);
   if (err) {
+    orthrus_userdb_close(ort);
 		return (PAM_SYSTEM_ERR);
   }
 
+  err = orthrus_userdb_close(ort);
+  if (err) {
+    ORT_LOG_ERR("pam_orthrus: Failed to close userdb at '%s': %s (%d)", ortuserdb, err->msg, err->err);
+		return (PAM_SYSTEM_ERR);
+  }
+  
   /* TODO: Figure out prompting in the 'new' OpenPAM */
 	/* get password */
   password_prompt = apr_psprintf(pool, "%s\nPassword:", challenge);
@@ -192,6 +199,12 @@
 		return (PAM_AUTH_ERR);
   }
   
+  err = orthrus_userdb_open(ort, ortuserdb);
+  if (err) {
+    ORT_LOG_ERR("pam_orthrus: Failed to open userdb at '%s' to verify: %s (%d)", ortuserdb, err->msg, err->err);
+		return (PAM_SYSTEM_ERR);
+  }
+
 	/* compare passwords */
   err = orthrus_userdb_verify(ort, pwd->pw_name,
                               challenge, password, pool);
@@ -202,6 +215,8 @@
 		pam_err = PAM_SUCCESS;
   }
 
+  orthrus_userdb_close(ort);
+
   apr_pool_destroy(pool);
   apr_terminate();
 #ifndef OPENPAM

Modified: labs/orthrus/trunk/src/userdb.c
URL: http://svn.apache.org/viewvc/labs/orthrus/trunk/src/userdb.c?rev=744859&r1=744858&r2=744859&view=diff
==============================================================================
--- labs/orthrus/trunk/src/userdb.c (original)
+++ labs/orthrus/trunk/src/userdb.c Mon Feb 16 08:29:32 2009
@@ -17,9 +17,29 @@
 #include "orthrus.h"
 #include "private/context.h"
 
-orthrus_error_t* orthrus_userdb_set(orthrus_t *ort, const char *path)
+orthrus_error_t* orthrus_userdb_close(orthrus_t *ort)
 {
-  return orthrus_error_create(APR_ENOTIMPL, "userdb functionality is not complete");
+  if (ort->userdb) {
+    apr_file_close(ort->userdb);
+    ort->userdb = NULL;
+  }
+}
+
+orthrus_error_t* orthrus_userdb_open(orthrus_t *ort, const char *path)
+{
+  apr_status_t rv;
+
+  if (ort->userdb) {
+    orthrus_userdb_close(ort);
+  }
+  
+  rv = apr_file_open(&ort->userdb, path, APR_READ|APR_WRITE|APR_CREATE|APR_BINARY,
+                     APR_UREAD|APR_UWRITE, ort->pool);
+  if (rv) {
+    return orthrus_error_createf(rv, "Unable to open %s", path);
+  }
+
+  return ORTHRUS_SUCCESS;
 }
 
 orthrus_error_t* orthrus_userdb_get_challenge(orthrus_t *ort,



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org