[asterisk-commits] bweschke: branch bweschke/polycom_acd_on_1.4 r96271 - in /team/bweschke/polyc...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 3 14:04:08 CST 2008


Author: bweschke
Date: Thu Jan  3 14:04:08 2008
New Revision: 96271

URL: http://svn.digium.com/view/asterisk?view=rev&rev=96271
Log:
 Another progress commit. Auth through agents.conf on an agent login via SIP SUBSCRIBE seems to be functional.


Modified:
    team/bweschke/polycom_acd_on_1.4/channels/chan_agent.c
    team/bweschke/polycom_acd_on_1.4/channels/chan_sip.c
    team/bweschke/polycom_acd_on_1.4/include/asterisk/channel.h
    team/bweschke/polycom_acd_on_1.4/main/channel.c

Modified: team/bweschke/polycom_acd_on_1.4/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/polycom_acd_on_1.4/channels/chan_agent.c?view=diff&rev=96271&r1=96270&r2=96271
==============================================================================
--- team/bweschke/polycom_acd_on_1.4/channels/chan_agent.c (original)
+++ team/bweschke/polycom_acd_on_1.4/channels/chan_agent.c Thu Jan  3 14:04:08 2008
@@ -235,6 +235,7 @@
 } while(0)
 
 /*--- Forward declarations */
+const char *agent_getsecret(const char *agentid);
 static struct ast_channel *agent_request(const char *type, int format, void *data, int *cause);
 static int agent_devicestate(void *data);
 static void agent_logoff_maintenance(struct agent_pvt *p, char *loginchan, long logintime, const char *uniqueid, char *logcommand);
@@ -1815,6 +1816,25 @@
 	agent_logoff_cmd, "Sets an agent offline",
 	agent_logoff_usage, complete_agent_logoff_cmd },
 };
+
+/*! 
+ * \brief Get the agent secret for external methods / params that need it.
+ * 
+ * \param agentid
+ */
+const char *agent_getsecret(const char *agentid) 
+{
+	struct agent_pvt *p;
+	char *secret = NULL;
+
+	AST_LIST_LOCK(&agents);
+	AST_LIST_TRAVERSE(&agents, p, list) {
+		if (!strcmp(p->agent, agentid) && !p->pending)
+			secret = p->password;
+	}
+	AST_LIST_UNLOCK(&agents);
+	return secret;
+}
 
 /*!
  * \brief Log in agent application.
@@ -2680,6 +2700,8 @@
 	/* Dialplan Functions */
 	ast_custom_function_register(&agent_function);
 
+	ast_install_ast_agent_functions(agent_getsecret);
+
 	return 0;
 }
 
@@ -2694,6 +2716,7 @@
 static int unload_module(void)
 {
 	struct agent_pvt *p;
+	ast_uninstall_agent_functions();
 	/* First, take us out of the channel loop */
 	ast_channel_unregister(&agent_tech);
 	/* Unregister dialplan functions */

Modified: team/bweschke/polycom_acd_on_1.4/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/polycom_acd_on_1.4/channels/chan_sip.c?view=diff&rev=96271&r1=96270&r2=96271
==============================================================================
--- team/bweschke/polycom_acd_on_1.4/channels/chan_sip.c (original)
+++ team/bweschke/polycom_acd_on_1.4/channels/chan_sip.c Thu Jan  3 14:04:08 2008
@@ -9257,6 +9257,7 @@
 	struct ast_variable *tmpvar = NULL, *v = NULL;
 	char *uri2 = ast_strdupa(uri);
 	int checkauthret = -1;
+	char *agentsecret = NULL;	
 
 	/* Terminate URI */
 	t = uri2;
@@ -9469,14 +9470,21 @@
 				ast_string_field_free(p, peermd5secret);
 			}
 
-
+			ast_log(LOG_DEBUG, "check auth start secret: %s md5secret: %s\n", p->peersecret, p->peermd5secret);
 			checkauthret = check_auth(p, req, peer->name, p->peersecret, p->peermd5secret, sipmethod, uri2, reliable, ast_test_flag(req, SIP_PKT_IGNORE));
+			ast_log(LOG_DEBUG, "check auth end. result: %d\n", checkauthret);
 			if (checkauthret == AUTH_USERNAME_MISMATCH && peer->agentlogin) {
-				checkauthret = check_auth(p, req, p->digestname, "12345", NULL, sipmethod, uri2, reliable, ast_test_flag(req, SIP_PKT_IGNORE));
+				if (ast_agent_getsecret(p->digestname))
+					agentsecret = ast_strdupa(ast_agent_getsecret(p->digestname));
+				else
+					goto agentauthwrong;	
+				checkauthret = check_auth(p, req, p->digestname, agentsecret, NULL, sipmethod, uri2, reliable, ast_test_flag(req, SIP_PKT_IGNORE));
 				if (!checkauthret)
 					ast_log(LOG_DEBUG, "auth'd correctly with %s on peer %s\n", p->digestname, peer->name);
-				else
+				else {
+					agentauthwrong:
 					ast_log(LOG_DEBUG, "not auth'd correctly with %s on peer %s\n", p->digestname, peer->name);
+				}
 			}
 			res = checkauthret;
 			if (checkauthret == AUTH_SUCCESSFUL) {

Modified: team/bweschke/polycom_acd_on_1.4/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/bweschke/polycom_acd_on_1.4/include/asterisk/channel.h?view=diff&rev=96271&r1=96270&r2=96271
==============================================================================
--- team/bweschke/polycom_acd_on_1.4/include/asterisk/channel.h (original)
+++ team/bweschke/polycom_acd_on_1.4/include/asterisk/channel.h Thu Jan  3 14:04:08 2008
@@ -1395,6 +1395,9 @@
  */
 char *ast_channel_reason2str(int reason);
 
+void ast_install_ast_agent_functions(const char *(*agent_getsecret_ptr)(const char *));
+void ast_uninstall_agent_functions(void);
+const char *ast_agent_getsecret(const char *agentid);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: team/bweschke/polycom_acd_on_1.4/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/polycom_acd_on_1.4/main/channel.c?view=diff&rev=96271&r1=96270&r2=96271
==============================================================================
--- team/bweschke/polycom_acd_on_1.4/main/channel.c (original)
+++ team/bweschke/polycom_acd_on_1.4/main/channel.c Thu Jan  3 14:04:08 2008
@@ -4621,6 +4621,29 @@
 	return group;
 }
 
+static const char *(*ast_agent_getsecret_ptr)(const char *) = NULL;
+
+void ast_install_ast_agent_functions(const char *(*agent_getsecret_ptr)(const char *))
+{
+	ast_agent_getsecret_ptr = agent_getsecret_ptr;
+}
+
+void ast_uninstall_agent_functions(void)
+{
+	ast_agent_getsecret_ptr = NULL;
+}
+
+const char *ast_agent_getsecret(const char *agentid)
+{
+	if (ast_agent_getsecret_ptr)
+		return ast_agent_getsecret_ptr(agentid);
+
+	if (option_verbose > 2)
+		ast_log(LOG_WARNING, "Agent lookup requested on agent ID %s but no chan_agent is loaded\n", agentid);
+	return 0;
+
+}
+
 static int (*ast_moh_start_ptr)(struct ast_channel *, const char *, const char *) = NULL;
 static void (*ast_moh_stop_ptr)(struct ast_channel *) = NULL;
 static void (*ast_moh_cleanup_ptr)(struct ast_channel *) = NULL;




More information about the asterisk-commits mailing list