[Cherokee-commits] [2338] cherokee/trunk:

SVN at cherokee-project.com SVN at cherokee-project.com
Thu Nov 6 13:28:19 CET 2008


Revision: 2338
          http://svn.cherokee-project.com/changeset/2338
Author:   alo
Date:     2008-11-06 13:28:19 +0100 (Thu, 06 Nov 2008)

Log Message:
-----------


Modified Paths:
--------------
    cherokee/trunk/ChangeLog
    cherokee/trunk/cherokee/validator_file.c
    cherokee/trunk/cherokee/validator_file.h
    cherokee/trunk/cherokee/validator_htdigest.c
    cherokee/trunk/cherokee/validator_htpasswd.c
    cherokee/trunk/cherokee/validator_plain.c

Modified: cherokee/trunk/ChangeLog
===================================================================
--- cherokee/trunk/ChangeLog	2008-11-06 11:47:06 UTC (rev 2337)
+++ cherokee/trunk/ChangeLog	2008-11-06 12:28:19 UTC (rev 2338)
@@ -1,5 +1,11 @@
 2008-11-06  Alvaro Lopez Ortega  <alvaro at octality.com>
 
+	* cherokee/validator_htpasswd.c, cherokee/validator_plain.c,
+	cherokee/validator_file.c, cherokee/validator_file.h,
+	cherokee/validator_htdigest.c: Adds support for relative paths (in
+	addition to the full paths previously supported) to the file based
+	validators.
+
 	* cherokee/validator_htpasswd.c, cherokee/validator_htpasswd.h,
 	cherokee/Makefile.am, cherokee/validator_plain.c,
 	cherokee/validator_plain.h, cherokee/validator_file.c,

Modified: cherokee/trunk/cherokee/validator_file.c
===================================================================
--- cherokee/trunk/cherokee/validator_file.c	2008-11-06 11:47:06 UTC (rev 2337)
+++ cherokee/trunk/cherokee/validator_file.c	2008-11-06 12:28:19 UTC (rev 2338)
@@ -24,6 +24,7 @@
 
 #include "common-internal.h"
 #include "validator_file.h"
+#include "connection-protected.h"
 
 /* Properties
  */
@@ -68,8 +69,8 @@
 	if (ret == ret_ok) {
 		if (equal_buf_str (&subconf->val, "full")) {
 			props->password_path_type = val_path_full;
-		} else if (equal_buf_str (&subconf->val, "home")) {
-			props->password_path_type = val_path_home;
+		} else if (equal_buf_str (&subconf->val, "local_dir")) {
+			props->password_path_type = val_path_local_dir;
 		} else {
 			PRINT_ERROR ("ERROR: Unknown path type '%s'\n", subconf->val.buf);
 			return ret_error;
@@ -105,3 +106,35 @@
 	return cherokee_validator_free_base (VALIDATOR(validator));
 }
 
+
+/* Utilities
+ */
+
+ret_t
+cherokee_validator_file_get_full_path (cherokee_validator_file_t  *validator,
+				       cherokee_connection_t      *conn,
+				       cherokee_buffer_t         **ret_buf,
+				       cherokee_buffer_t          *tmp)
+{
+	cherokee_validator_file_props_t *props = VAL_VFILE_PROP(validator);
+
+	switch (props->password_path_type) {
+	case val_path_full:
+		*ret_buf = &props->password_file;
+		return ret_ok;
+
+	case val_path_local_dir:
+		cherokee_buffer_clean (tmp);
+		cherokee_buffer_add_buffer (tmp, &conn->local_directory);
+		cherokee_buffer_add_char   (tmp, '/');
+		cherokee_buffer_add_buffer (tmp, &props->password_file);
+		
+		*ret_buf = tmp;
+		return ret_ok;
+
+	default:
+		SHOULDNT_HAPPEN;
+	}
+
+	return ret_error;
+}

Modified: cherokee/trunk/cherokee/validator_file.h
===================================================================
--- cherokee/trunk/cherokee/validator_file.h	2008-11-06 11:47:06 UTC (rev 2337)
+++ cherokee/trunk/cherokee/validator_file.h	2008-11-06 12:28:19 UTC (rev 2338)
@@ -30,7 +30,7 @@
 
 typedef enum {
 	val_path_full,
-	val_path_home
+	val_path_local_dir
 } cherokee_validator_path_t;
 
 typedef struct {
@@ -69,4 +69,13 @@
 
 ret_t cherokee_validator_file_props_free_base  (cherokee_validator_file_props_t *props);
 
+
+/* Utilities
+ */
+
+ret_t cherokee_validator_file_get_full_path    (cherokee_validator_file_t  *validator,
+						cherokee_connection_t      *conn,
+						cherokee_buffer_t         **ret_buf,
+						cherokee_buffer_t          *tmp);
+
 #endif /* CHEROKEE_VALIDATOR_FILE_H */

Modified: cherokee/trunk/cherokee/validator_htdigest.c
===================================================================
--- cherokee/trunk/cherokee/validator_htdigest.c	2008-11-06 11:47:06 UTC (rev 2337)
+++ cherokee/trunk/cherokee/validator_htdigest.c	2008-11-06 12:28:19 UTC (rev 2338)
@@ -26,8 +26,8 @@
 #include "validator_htdigest.h"
 #include "plugin_loader.h"
 #include "connection-protected.h"
+#include "thread.h"
 
-
 /* Plug-in initialization
  */
 PLUGIN_INFO_VALIDATOR_EASIEST_INIT (htdigest, http_auth_basic | http_auth_digest);
@@ -226,10 +226,12 @@
 
 
 ret_t 
-cherokee_validator_htdigest_check (cherokee_validator_htdigest_t *htdigest, cherokee_connection_t *conn)
+cherokee_validator_htdigest_check (cherokee_validator_htdigest_t *htdigest,
+				   cherokee_connection_t         *conn)
 {
-	ret_t             ret;
-	cherokee_buffer_t file = CHEROKEE_BUF_INIT;
+	ret_t              ret;
+	cherokee_buffer_t *fpass;
+	cherokee_buffer_t  file = CHEROKEE_BUF_INIT;
 	
 	/* Ensure that we have all what we need
 	 */
@@ -237,12 +239,18 @@
 	    cherokee_buffer_is_empty (&conn->validator->user)) 
 		return ret_error;
 
-	if (cherokee_buffer_is_empty (&VAL_VFILE_PROP(htdigest)->password_file))
-		return ret_error;
+	/* Get the full path to the file
+	 */
+	ret = cherokee_validator_file_get_full_path (VFILE(htdigest), conn, &fpass,
+						     &CONN_THREAD(conn)->tmp_buf1);
+	if (ret != ret_ok) {
+		ret = ret_error;
+		goto out;
+	}
 
 	/* Read the whole file
 	 */
-	ret = cherokee_buffer_read_file (&file, VAL_VFILE_PROP(htdigest)->password_file.buf);
+	ret = cherokee_buffer_read_file (&file, fpass->buf);
 	if (ret != ret_ok) {
 		ret = ret_error;
 		goto out;

Modified: cherokee/trunk/cherokee/validator_htpasswd.c
===================================================================
--- cherokee/trunk/cherokee/validator_htpasswd.c	2008-11-06 11:47:06 UTC (rev 2337)
+++ cherokee/trunk/cherokee/validator_htpasswd.c	2008-11-06 12:28:19 UTC (rev 2338)
@@ -234,50 +234,69 @@
 
 
 static ret_t
-request_isnt_passwd_file (cherokee_validator_htpasswd_t *htpasswd, cherokee_connection_t *conn)
+request_isnt_passwd_file (cherokee_validator_htpasswd_t *htpasswd,
+			  cherokee_connection_t         *conn, 
+			  cherokee_buffer_t             *full_path)
 {
-	ret_t              ret;
-	cherokee_buffer_t *pfile;
+	char    *p;
+	cuint_t  re;
+	cuint_t  len;
 
-	pfile = &VAL_VFILE_PROP(htpasswd)->password_file;
+	/* Sanity check */
+	if (cherokee_buffer_is_empty (full_path))
+		return ret_error;
 
-	if (conn->request.len > 0)
-		cherokee_buffer_add (&conn->local_directory, conn->request.buf+1, conn->request.len-1);  /* 1: add    */
+	/* Look for the file name */
+	p = strrchr (full_path->buf, '/');
+	if (p == NULL)
+		return ret_error;
 
-	ret = ret_ok;
+	len = (full_path->buf + full_path->len) - p;
 
-	if (pfile->len == conn->local_directory.len) {
-		ret = (strncmp (pfile->buf, 
-				conn->local_directory.buf, 
-				conn->local_directory.len) == 0) ? ret_error : ret_ok;
-	}
+	/* Check whether the request ends like that */
+	if (conn->request.len < len)
+		return ret_ok;
 
-	if (conn->request.len > 0)
-		cherokee_buffer_drop_ending (&conn->local_directory, conn->request.len-1);              /* 1: remove */
+	re = strncmp (conn->request.buf + (conn->request.len - len), p, len);
+	if (re == 0)
+		return ret_error;
 
-	return ret;
+	return ret_ok;
 }
 
 
 ret_t 
-cherokee_validator_htpasswd_check (cherokee_validator_htpasswd_t *htpasswd, cherokee_connection_t *conn)
+cherokee_validator_htpasswd_check (cherokee_validator_htpasswd_t *htpasswd,
+				   cherokee_connection_t         *conn)
 {
-	FILE *f;
-	int   len;
-	char *cryp;
-	int   cryp_len;
-	ret_t ret;
-	ret_t ret_auth;
+	FILE              *f;
+	int                len;
+	char              *cryp;
+	int                cryp_len;
+	ret_t              ret;
+	ret_t              ret_auth;
+	cherokee_buffer_t *fpass;
 	CHEROKEE_TEMP(line, 128);
 
-	/* Sanity check
+	/* Sanity checks
 	 */
-	if ((conn->validator == NULL) || cherokee_buffer_is_empty (&conn->validator->user))
+	if ((conn->validator == NULL) ||
+	    cherokee_buffer_is_empty (&conn->validator->user))
+	{
 		return ret_error;
+	}
 
+	/* Get the full path to the file
+	 */
+	ret = cherokee_validator_file_get_full_path (VFILE(htpasswd), conn, &fpass,
+						     &CONN_THREAD(conn)->tmp_buf1);
+	if (ret != ret_ok) {
+		return ret_error;
+	}
+
 	/* 1.- Check the login/passwd
 	 */	  
-	f = fopen (VAL_VFILE_PROP(htpasswd)->password_file.buf, "r");
+	f = fopen (fpass->buf, "r");
 	if (f == NULL) {
 		return ret_error;
 	}
@@ -351,7 +370,7 @@
 	/* 2.- Security check:
 	 * Is the client trying to download the passwd file?
 	 */
-	ret = request_isnt_passwd_file (htpasswd, conn);	
+	ret = request_isnt_passwd_file (htpasswd, conn, fpass);	
 	if (ret != ret_ok)
 		return ret;
 

Modified: cherokee/trunk/cherokee/validator_plain.c
===================================================================
--- cherokee/trunk/cherokee/validator_plain.c	2008-11-06 11:47:06 UTC (rev 2337)
+++ cherokee/trunk/cherokee/validator_plain.c	2008-11-06 12:28:19 UTC (rev 2338)
@@ -24,6 +24,7 @@
 
 #include "common-internal.h"
 #include "validator_plain.h"
+#include "thread.h"
 
 #include "connection.h"
 #include "connection-protected.h"
@@ -106,21 +107,32 @@
 	ret_t              ret;
 	const char        *p;
 	const char        *end;
+	cherokee_buffer_t *fpass;
 	cherokee_buffer_t  file  = CHEROKEE_BUF_INIT;
 	cherokee_buffer_t  buser = CHEROKEE_BUF_INIT;
 	cherokee_buffer_t  bpass = CHEROKEE_BUF_INIT;
 
+	/* Sanity check */
 	if (unlikely ((conn->validator == NULL) || 
 	    cherokee_buffer_is_empty(&conn->validator->user))) {
 		return ret_error;
 	}
 
-	ret = cherokee_buffer_read_file (&file, VAL_VFILE_PROP(plain)->password_file.buf);
+	/* Get the full path to the file */
+	ret = cherokee_validator_file_get_full_path (VFILE(plain), conn, &fpass,
+						     &CONN_THREAD(conn)->tmp_buf1);
 	if (ret != ret_ok) {
 		ret = ret_error;
 		goto out;
 	}
 
+	/* Read its contents */
+	ret = cherokee_buffer_read_file (&file, fpass->buf);
+	if (ret != ret_ok) {
+		ret = ret_error;
+		goto out;
+	}
+
 	if (! cherokee_buffer_is_ending(&file, '\n'))
 		cherokee_buffer_add_str (&file, "\n");
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.octality.com/pipermail/cherokee-commits/attachments/20081106/e6fefdf1/attachment.htm 


More information about the Cherokee-commits mailing list