[asterisk-commits] bbryant: trunk r118161 - in /trunk: include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 23 16:19:42 CDT 2008


Author: bbryant
Date: Fri May 23 16:19:42 2008
New Revision: 118161

URL: http://svn.digium.com/view/asterisk?view=rev&rev=118161
Log:
Add new functionality to http server that requires manager authentication for any path that includes a directory named 'private'. This patch also 
requires manager authentication for any POST's being sent to the server as well to help secure uploads.

Modified:
    trunk/include/asterisk/manager.h
    trunk/main/http.c
    trunk/main/manager.c

Modified: trunk/include/asterisk/manager.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/manager.h?view=diff&rev=118161&r1=118160&r2=118161
==============================================================================
--- trunk/include/asterisk/manager.h (original)
+++ trunk/include/asterisk/manager.h Fri May 23 16:19:42 2008
@@ -203,6 +203,9 @@
 
 void __attribute__ ((format (printf, 2, 3))) astman_append(struct mansession *s, const char *fmt, ...);
 
+/*! \brief Determinie if a manager session ident is authenticated */
+int astman_is_authed(uint32_t ident);
+
 /*! \brief Called by Asterisk initialization */
 int init_manager(void);
 

Modified: trunk/main/http.c
URL: http://svn.digium.com/view/asterisk/trunk/main/http.c?view=diff&rev=118161&r1=118160&r2=118161
==============================================================================
--- trunk/main/http.c (original)
+++ trunk/main/http.c Fri May 23 16:19:42 2008
@@ -131,6 +131,18 @@
 	return wkspace;
 }
 
+static uint32_t manid_from_vars(struct ast_variable *sid) {
+	uint32_t mngid;
+
+	while (sid && strcmp(sid->name, "mansession_id"))
+		sid = sid->next;
+	
+	if (!sid || sscanf(sid->value, "%x", &mngid) != 1)
+		return 0;
+	
+	return mngid;
+}
+
 static struct ast_str *static_callback(struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *vars, struct ast_variable *headers, int *status, char **title, int *contentlength)
 {
 	char *path;
@@ -178,9 +190,13 @@
 
 	if (S_ISDIR(st.st_mode)) {
 		goto out404;
-	}
+	}	
 
 	if ((fd = open(path, O_RDONLY)) < 0) {
+		goto out403;
+	}
+
+	if (strstr(path, "/private/") && !astman_is_authed(manid_from_vars(vars))) {
 		goto out403;
 	}
 
@@ -514,7 +530,11 @@
 		}
 	}
 
-	if (urih) {
+	if (method == AST_HTTP_POST && !astman_is_authed(manid_from_vars(vars))) {
+		out = ast_http_error((*status = 403),
+			      (*title = ast_strdup("Access Denied")),
+			      NULL, "Sorry, I cannot let you do that, Dave.");
+	} else if (urih) {
 		*static_content = urih->static_content;
 		out = urih->callback(ser, urih, uri, method, vars, headers, status, title, contentlength);
 		AST_RWLIST_UNLOCK(&uris);

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?view=diff&rev=118161&r1=118160&r2=118161
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Fri May 23 16:19:42 2008
@@ -3292,7 +3292,7 @@
  * the value of the mansession_id cookie (0 is not valid and means
  * a session on the AMI socket).
  */
-static struct mansession *find_session(uint32_t ident)
+static struct mansession *find_session(uint32_t ident, int incinuse)
 {
 	struct mansession *s;
 
@@ -3303,7 +3303,7 @@
 	AST_LIST_TRAVERSE(&sessions, s, list) {
 		ast_mutex_lock(&s->__lock);
 		if (s->managerid == ident && !s->needdestroy) {
-			ast_atomic_fetchadd_int(&s->inuse, 1);
+			ast_atomic_fetchadd_int(&s->inuse, incinuse ? 1 : 0);
 			break;
 		}
 		ast_mutex_unlock(&s->__lock);
@@ -3311,6 +3311,21 @@
 	AST_LIST_UNLOCK(&sessions);
 
 	return s;
+}
+
+int astman_is_authed(uint32_t ident) 
+{
+	int authed;
+	struct mansession *s;
+
+	if (!(s = find_session(ident, 0)))
+		return 0;
+
+	authed = (s->authenticated != 0);
+
+	ast_mutex_unlock(&s->__lock);
+
+	return authed;
 }
 
 int astman_verify_session_readpermissions(uint32_t ident, int perm)
@@ -3603,7 +3618,7 @@
 		}
 	}
 
-	if (!(s = find_session(ident))) {
+	if (!(s = find_session(ident, 1))) {
 		/* Create new session.
 		 * While it is not in the list we don't need any locking
 		 */




More information about the asterisk-commits mailing list