[asterisk-commits] mjordan: trunk r394881 - in /trunk: CHANGES main/manager.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jul 20 21:11:52 CDT 2013


Author: mjordan
Date: Sat Jul 20 21:11:49 2013
New Revision: 394881

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394881
Log:
Allow setting allowmultiplelogin on an account basis

This patch modifies manager to allow the allowmultiplelogin setting to be set
on an account by account basis. When set in the general context, it will act
as the default for the defined accounts. Setting it in the account will
override the general setting.

(closes issue ASTERISK-21324)
Reported by: vldmr
patches:
  asterisk-manager-per-user-allowmultiplelogin.patch uploaded by vldmr (License 6487)

Modified:
    trunk/CHANGES
    trunk/main/manager.c

Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=394881&r1=394880&r2=394881
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Sat Jul 20 21:11:49 2013
@@ -293,6 +293,10 @@
    "LocalTwo". This replaces the suffix of "1" and "2" for the two halves of
    the Local channel. This affects the LocalBridge, LocalOptimizationBegin,
    and LocalOptimizationEnd events.
+
+ * The option 'allowmultiplelogin' can now be set or overriden in a particular
+   account. When set in the general context, it will act as the default
+   setting for defined accounts.
 
 AGI (Asterisk Gateway Interface)
 ------------------

Modified: trunk/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/manager.c?view=diff&rev=394881&r1=394880&r2=394881
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Sat Jul 20 21:11:49 2013
@@ -1316,6 +1316,7 @@
 	int writeperm;			/*!< Authorization for writing */
 	int writetimeout;		/*!< Per user Timeout for ast_carefulwrite() */
 	int displayconnects;		/*!< XXX unused */
+	int allowmultiplelogin; /*!< Per user option*/
 	int keep;			/*!< mark entries created on a reload */
 	struct ao2_container *whitefilters; /*!< Manager event filters - white list */
 	struct ao2_container *blackfilters; /*!< Manager event filters - black list */
@@ -2072,19 +2073,21 @@
 
 	ast_cli(a->fd, "\n");
 	ast_cli(a->fd,
-		"       username: %s\n"
-		"         secret: %s\n"
-		"            ACL: %s\n"
-		"      read perm: %s\n"
-		"     write perm: %s\n"
-		"displayconnects: %s\n",
+		"          username: %s\n"
+		"            secret: %s\n"
+		"               ACL: %s\n"
+		"         read perm: %s\n"
+		"        write perm: %s\n"
+		"   displayconnects: %s\n"
+		"allowmultiplelogin: %s\n",
 		(user->username ? user->username : "(N/A)"),
 		(user->secret ? "<Set>" : "(N/A)"),
 		((user->acl && !ast_acl_list_is_empty(user->acl)) ? "yes" : "no"),
 		user_authority_to_str(user->readperm, &rauthority),
 		user_authority_to_str(user->writeperm, &wauthority),
-		(user->displayconnects ? "yes" : "no"));
-	ast_cli(a->fd, "      Variables: \n");
+		(user->displayconnects ? "yes" : "no"),
+		(user->allowmultiplelogin ? "yes" : "no"));
+	ast_cli(a->fd, "         Variables: \n");
 		for (v = user->chanvars ; v ; v = v->next) {
 			ast_cli(a->fd, "                 %s = %s\n", v->name, v->value);
 		}
@@ -5500,7 +5503,8 @@
 {
 	int ret = 0;
 	struct manager_action *act_found;
-	const char *user;
+	struct ast_manager_user *user = NULL;
+	const char *username;
 	const char *action;
 
 	action = __astman_get_header(m, "Action", GET_HEADER_SKIP_EMPTY);
@@ -5525,19 +5529,24 @@
 		return 0;
 	}
 
-	if (!allowmultiplelogin
-		&& !s->session->authenticated
+	if (!s->session->authenticated
 		&& (!strcasecmp(action, "Login")
 			|| !strcasecmp(action, "Challenge"))) {
-		user = astman_get_header(m, "Username");
-
-		if (!ast_strlen_zero(user) && check_manager_session_inuse(user)) {
-			report_session_limit(s);
-			sleep(1);
-			mansession_lock(s);
-			astman_send_error(s, m, "Login Already In Use");
-			mansession_unlock(s);
-			return -1;
+		username = astman_get_header(m, "Username");
+
+		if (!ast_strlen_zero(username) && check_manager_session_inuse(username)) {
+			AST_RWLIST_WRLOCK(&users);
+			user = get_manager_by_name_locked(username);
+			if (user && !user->allowmultiplelogin) {
+				AST_RWLIST_UNLOCK(&users);
+				report_session_limit(s);
+				sleep(1);
+				mansession_lock(s);
+				astman_send_error(s, m, "Login Already In Use");
+				mansession_unlock(s);
+				return -1;
+			}
+			AST_RWLIST_UNLOCK(&users);
 		}
 	}
 
@@ -8127,6 +8136,7 @@
 				const char *user_read = ast_variable_retrieve(ucfg, cat, "read");
 				const char *user_write = ast_variable_retrieve(ucfg, cat, "write");
 				const char *user_displayconnects = ast_variable_retrieve(ucfg, cat, "displayconnects");
+				const char *user_allowmultiplelogin = ast_variable_retrieve(ucfg, cat, "allowmultiplelogin");
 				const char *user_writetimeout = ast_variable_retrieve(ucfg, cat, "writetimeout");
 
 				/* Look for an existing entry,
@@ -8147,6 +8157,8 @@
 					user->writeperm = -1;
 					/* Default displayconnect from [general] */
 					user->displayconnects = displayconnects;
+					/* Default allowmultiplelogin from [general] */
+					user->allowmultiplelogin = allowmultiplelogin;
 					user->writetimeout = 100;
 				}
 
@@ -8162,6 +8174,9 @@
 				if (!user_displayconnects) {
 					user_displayconnects = ast_variable_retrieve(ucfg, "general", "displayconnects");
 				}
+				if (!user_allowmultiplelogin) {
+					user_allowmultiplelogin = ast_variable_retrieve(ucfg, "general", "allowmultiplelogin");
+				}
 				if (!user_writetimeout) {
 					user_writetimeout = ast_variable_retrieve(ucfg, "general", "writetimeout");
 				}
@@ -8181,6 +8196,9 @@
 				}
 				if (user_displayconnects) {
 					user->displayconnects = ast_true(user_displayconnects);
+				}
+				if (user_allowmultiplelogin) {
+					user->allowmultiplelogin = ast_true(user_allowmultiplelogin);
 				}
 				if (user_writetimeout) {
 					int value = atoi(user_writetimeout);
@@ -8217,6 +8235,8 @@
 			user->writeperm = 0;
 			/* Default displayconnect from [general] */
 			user->displayconnects = displayconnects;
+			/* Default allowmultiplelogin from [general] */
+			user->allowmultiplelogin = allowmultiplelogin;
 			user->writetimeout = 100;
 			user->whitefilters = ao2_container_alloc(1, NULL, NULL);
 			user->blackfilters = ao2_container_alloc(1, NULL, NULL);
@@ -8251,6 +8271,8 @@
 				user->writeperm = get_perm(var->value);
 			}  else if (!strcasecmp(var->name, "displayconnects") ) {
 				user->displayconnects = ast_true(var->value);
+			}  else if (!strcasecmp(var->name, "allowmultiplelogin") ) {
+				user->allowmultiplelogin = ast_true(var->value);
 			} else if (!strcasecmp(var->name, "writetimeout")) {
 				int value = atoi(var->value);
 				if (value < 100) {




More information about the asterisk-commits mailing list