From ad2c8750819f7e236c0baaf7edf2affd50c9d0a0 Mon Sep 17 00:00:00 2001 From: David Troy Date: Sat, 1 Apr 2006 16:56:25 +0000 Subject: git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/branches/1.20pre@34 f02b47b9-160a-0410-81a6-dc3441afb0ec --- src/proxyfunc.c | 336 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 336 insertions(+) create mode 100644 src/proxyfunc.c (limited to 'src/proxyfunc.c') diff --git a/src/proxyfunc.c b/src/proxyfunc.c new file mode 100644 index 0000000..51ed5c6 --- /dev/null +++ b/src/proxyfunc.c @@ -0,0 +1,336 @@ +#include "astmanproxy.h" + +extern struct mansession *sessions; +extern struct iohandler *iohandlers; +extern pthread_mutex_t serverlock; +extern pthread_mutex_t userslock; + +void *ProxyListIOHandlers(struct mansession *s) { + struct message m; + struct iohandler *i; + + memset(&m, 0, sizeof(struct message)); + AddHeader(&m, "ProxyResponse: Success"); + + i = iohandlers; + while (i && (m.hdrcount < MAX_HEADERS - 1) ) { + if (i->read) + AddHeader(&m, "InputHandler: %s", i->formatname); + if (i->write) + AddHeader(&m, "OutputHandler: %s", i->formatname); + i = i->next; + } + + s->output->write(s, &m); + return 0; +} + +void *ProxyListSessions(struct mansession *s) { + struct message m; + struct mansession *c; + char iabuf[INET_ADDRSTRLEN]; + + memset(&m, 0, sizeof(struct message)); + AddHeader(&m, "ProxyResponse: Success"); + + c = sessions; + while (c && (m.hdrcount < MAX_HEADERS - 1) ) { + if (!c->server) { + AddHeader(&m, "ProxyClientSession: %s", ast_inet_ntoa(iabuf, sizeof(iabuf), c->sin.sin_addr), c->actionid); + AddHeader(&m, "ProxyClientInputHandler: %s", c->input->formatname); + AddHeader(&m, "ProxyClientOutputHandler: %s", c->output->formatname); + } else + AddHeader(&m, "ProxyServerSession: %s", ast_inet_ntoa(iabuf, sizeof(iabuf), c->sin.sin_addr)); + c = c->next; + } + s->output->write(s, &m); + return 0; +} + +void *ProxySetOutputFormat(struct mansession *s, struct message *m) { + struct message mo; + char *value; + + value = astman_get_header(m, "OutputFormat"); + SetIOHandlers(s, s->input->formatname, value); + /* TODO: this is retarded */ + + memset(&mo, 0, sizeof(struct message)); + AddHeader(&mo, "ProxyResponse: Success"); + AddHeader(&mo, "OutputFormat: %s", s->output->formatname ); + + s->output->write(s, &mo); + + return 0; +} + +void *ProxySetAutoFilter(struct mansession *s, struct message *m) { + struct message mo; + char *value; + int i; + + value = astman_get_header(m, "AutoFilter"); + if ( !strcasecmp(value, "on") ) + i = 1; + else + i = 0; + pthread_mutex_lock(&s->lock); + s->autofilter = i; + pthread_mutex_unlock(&s->lock); + + memset(&mo, 0, sizeof(struct message)); + AddHeader(&mo, "ProxyResponse: Success"); + AddHeader(&mo, "AutoFilter: %d", s->autofilter); + + s->output->write(s, &mo); + + return 0; +} + +void *ProxyLogin(struct mansession *s, char *user, char *secret) { + struct message m; + struct proxy_user *pu; + + memset(&m, 0, sizeof(struct message)); + if( debug ) + debugmsg("Login attempt as: %s/%s", user, secret); + + pthread_mutex_lock(&userslock); + pu = pc.userlist; + while( pu ) { + if ( !strcmp(user, pu->username) && !strcmp(secret, pu->secret) ) { + AddHeader(&m, "Response: Success"); + AddHeader(&m, "Message: Authentication accepted"); + s->output->write(s, &m); + s->authenticated = 1; + strcpy(s->user.channel, pu->channel); + strcpy(s->user.icontext, pu->icontext); + strcpy(s->user.ocontext, pu->ocontext); + if( debug ) + debugmsg("Login as: %s", user); + break; + } + pu = pu->next; + } + pthread_mutex_unlock(&userslock); + + if( !pu ) { + AddHeader(&m, "Response: Error"); + AddHeader(&m, "Message: Authentication failed"); + s->output->write(s, &m); + s->authenticated = 0; + if( debug ) + debugmsg("Login failed as: %s/%s", user, secret); + } + + return 0; +} + +void *ProxyLogoff(struct mansession *s) { + struct message m; + + memset(&m, 0, sizeof(struct message)); + AddHeader(&m, "Goodbye: Y'all come back now, y'hear?"); + + s->output->write(s, &m); + + destroy_session(s); + if (debug) + debugmsg("Client logged off - exiting thread"); + pthread_exit(NULL); + return 0; +} + +int ProxyAddServer(struct mansession *s, struct message *m) { + struct message mo; + struct ast_server *srv; + int res = 0; + + /* malloc ourselves a server credentials structure */ + srv = malloc(sizeof(struct ast_server)); + if ( !srv ) { + fprintf(stderr, "Failed to allocate server credentials: %s\n", strerror(errno)); + exit(1); + } + memset(srv, 0, sizeof (struct ast_server) ); + + + /* TODO: Disallow adding of duplicate servers? Or not, I suppose that could be useful (events on/off) */ + memset(srv, 0, sizeof(struct ast_server) ); + memset(&mo, 0, sizeof(struct message)); + strcpy(srv->ast_host, astman_get_header(m, "Server")); + strcpy(srv->ast_user, astman_get_header(m, "Username")); + strcpy(srv->ast_pass, astman_get_header(m, "Secret")); + strcpy(srv->ast_port, astman_get_header(m, "Port")); + strcpy(srv->ast_events, astman_get_header(m, "Events")); + + if (*srv->ast_host && *srv->ast_user && *srv->ast_pass && *srv->ast_port && *srv->ast_events) { + pthread_mutex_lock(&serverlock); + srv->next = pc.serverlist; + pc.serverlist = srv; + pthread_mutex_unlock(&serverlock); + res = StartServer(srv); + } else + res = 1; + + if (res) { + AddHeader(&mo, "ProxyResponse: Failure"); + AddHeader(&mo, "Message: Could not add %s", srv->ast_host); + } else { + AddHeader(&mo, "ProxyResponse: Success"); + AddHeader(&mo, "Message: Added %s", srv->ast_host); + } + + s->output->write(s, &mo); + return 0; +} + +int ProxyDropServer(struct mansession *s, struct message *m) { + struct message mo; + struct mansession *srv; + char *value; + int res; + + memset(&mo, 0, sizeof(struct message)); + value = astman_get_header(m, "Server"); + srv = sessions; + while (*value && srv) { + if (srv->server && !strcmp(srv->server->ast_host, value)) + break; + srv = srv->next; + } + + if (srv) { + destroy_session(srv); + debugmsg("Dropping Server %s", value); + AddHeader(&mo, "ProxyResponse: Success"); + AddHeader(&mo, "Message: Dropped %s", value); + res = 0; + } else { + debugmsg("Failed to Drop Server %s -- not found", value); + AddHeader(&mo, "ProxyResponse: Failure"); + AddHeader(&mo, "Message: Cannot Drop Server %s, Does Not Exist", value); + res = 1; + } + + s->output->write(s, &mo); + return res; +} + +void *ProxyListServers(struct mansession *s) { + struct message m; + struct mansession *c; + char iabuf[INET_ADDRSTRLEN]; + + memset(&m, 0, sizeof(struct message)); + AddHeader(&m, "ProxyResponse: Success"); + + c = sessions; + while (c) { + if (c->server) { + AddHeader(&m, "ProxyListServer I: %s H: %s U: %s P: %s E: %s ", + ast_inet_ntoa(iabuf, sizeof(iabuf), c->sin.sin_addr), + c->server->ast_host, c->server->ast_user, + c->server->ast_port, c->server->ast_events); + } + + c = c->next; + } + s->output->write(s, &m); + return 0; +} + + +void *proxyaction_do(char *proxyaction, struct message *m, struct mansession *s) +{ + if (!strcasecmp(proxyaction,"SetOutputFormat")) + ProxySetOutputFormat(s, m); + else if (!strcasecmp(proxyaction,"SetAutoFilter")) + ProxySetAutoFilter(s, m); + else if (!strcasecmp(proxyaction,"ListSessions")) + ProxyListSessions(s); + else if (!strcasecmp(proxyaction,"AddServer")) + ProxyAddServer(s, m); + else if (!strcasecmp(proxyaction,"DropServer")) + ProxyDropServer(s, m); + else if (!strcasecmp(proxyaction,"ListServers")) + ProxyListServers(s); + else if (!strcasecmp(proxyaction,"ListIOHandlers")) + ProxyListIOHandlers(s); + else if (!strcasecmp(proxyaction,"Logoff")) + ProxyLogoff(s); + else + proxyerror_do(s, "Invalid Proxy Action"); + + return 0; +} + +int proxyerror_do(struct mansession *s, char *err) +{ + struct message mo; + + memset(&mo, 0, sizeof(struct message)); + AddHeader(&mo, "ProxyResponse: Error"); + AddHeader(&mo, "Message: %s", err); + + s->output->write(s, &mo); + + return 0; +} + +int ValidateAction(struct message *m, struct mansession *s, int inbound) { + char *channel, *channel1, *channel2; + char *context; + char *uchannel; + char *ucontext; + + if( !s->authenticated ) + return 0; + + if( inbound ) + ucontext = s->user.icontext; + else + ucontext = s->user.ocontext; + uchannel = s->user.channel; + + channel = astman_get_header(m, "Channel"); + if( channel[0] != '\0' && uchannel[0] != '\0' ) + if( strncasecmp( channel, uchannel, strlen(uchannel) ) ) { + if( debug ) + debugmsg("Message filtered (chan): %s != %s", channel, uchannel); + return 0; + } + + channel1 = astman_get_header(m, "Channel1"); + channel2 = astman_get_header(m, "Channel2"); + if( (channel1[0] != '\0' || channel2[0] != '\0') && uchannel[0] != '\0' ) + if( !(strncasecmp( channel1, uchannel, strlen(uchannel) ) == 0 || + strncasecmp( channel2, uchannel, strlen(uchannel) ) == 0) ) { + if( debug ) + debugmsg("Message filtered (chan): %s/%s != %s", channel1, channel2, uchannel); + return 0; + } + + context = astman_get_header(m, "Context"); + if( context[0] != '\0' && ucontext[0] != '\0' ) + if( strcasecmp( context, ucontext ) ) { + if( debug ) + debugmsg("Message filtered (ctxt): %s != %s", context, ucontext); + return 0; + } + + return 1; +} + +void *SendError(struct mansession *s) { + struct message m; + + memset(&m, 0, sizeof(struct message)); + AddHeader(&m, "Response: Error"); + AddHeader(&m, "Message: Action Filtered"); + + s->output->write(s, &m); + + return 0; +} + -- cgit From aa8304c0664b780dd47cb2a662664f897a8e7c34 Mon Sep 17 00:00:00 2001 From: David Troy Date: Sat, 1 Apr 2006 17:07:59 +0000 Subject: git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/branches/1.20pre@39 f02b47b9-160a-0410-81a6-dc3441afb0ec --- src/proxyfunc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/proxyfunc.c') diff --git a/src/proxyfunc.c b/src/proxyfunc.c index 51ed5c6..99d6dbc 100644 --- a/src/proxyfunc.c +++ b/src/proxyfunc.c @@ -115,9 +115,7 @@ void *ProxyLogin(struct mansession *s, char *user, char *secret) { pthread_mutex_unlock(&userslock); if( !pu ) { - AddHeader(&m, "Response: Error"); - AddHeader(&m, "Message: Authentication failed"); - s->output->write(s, &m); + SendError(s, "Authentication failed"); s->authenticated = 0; if( debug ) debugmsg("Login failed as: %s/%s", user, secret); @@ -322,12 +320,12 @@ int ValidateAction(struct message *m, struct mansession *s, int inbound) { return 1; } -void *SendError(struct mansession *s) { +void *SendError(struct mansession *s, char *errmsg) { struct message m; memset(&m, 0, sizeof(struct message)); AddHeader(&m, "Response: Error"); - AddHeader(&m, "Message: Action Filtered"); + AddHeader(&m, "Message: %s", errmsg); s->output->write(s, &m); -- cgit From a2957dba6e5f8c607a13a66b2489c0c2f41d31f5 Mon Sep 17 00:00:00 2001 From: David Troy Date: Sat, 1 Apr 2006 17:22:35 +0000 Subject: git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/branches/1.20pre@44 f02b47b9-160a-0410-81a6-dc3441afb0ec --- src/proxyfunc.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/proxyfunc.c') diff --git a/src/proxyfunc.c b/src/proxyfunc.c index 99d6dbc..31094f8 100644 --- a/src/proxyfunc.c +++ b/src/proxyfunc.c @@ -332,3 +332,34 @@ void *SendError(struct mansession *s, char *errmsg) { return 0; } +/*! If you are calling ast_carefulwrite, it is assumed that you are calling + it on a file descriptor that _DOES_ have NONBLOCK set. This way, + there is only one system call made to do a write, unless we actually + have a need to wait. This way, we get better performance. */ +int ast_carefulwrite(int fd, char *s, int len, int timeoutms) +{ + /* Try to write string, but wait no more than ms milliseconds + before timing out */ + int res=0; + struct pollfd fds[1]; + while(len) { + res = m_send(fd, s, len); + if ((res < 0) && (errno != EAGAIN)) { + return -1; + } + if (res < 0) res = 0; + len -= res; + s += res; + res = 0; + if (len) { + fds[0].fd = get_real_fd(fd); + fds[0].events = POLLOUT; + /* Wait until writable again */ + res = poll(fds, 1, timeoutms); + if (res < 1) + return -1; + } + } + return res; +} + -- cgit From cf834d379b5a6a7393d0c25386c55959f5df4550 Mon Sep 17 00:00:00 2001 From: David Troy Date: Sat, 1 Apr 2006 18:07:37 +0000 Subject: git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/branches/1.20pre@52 f02b47b9-160a-0410-81a6-dc3441afb0ec --- src/proxyfunc.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/proxyfunc.c') diff --git a/src/proxyfunc.c b/src/proxyfunc.c index 31094f8..ed4770e 100644 --- a/src/proxyfunc.c +++ b/src/proxyfunc.c @@ -64,6 +64,25 @@ void *ProxySetOutputFormat(struct mansession *s, struct message *m) { return 0; } +int ProxyChallenge(struct mansession *s, struct message *m) { + struct message mo; + + if ( strcasecmp("MD5", astman_get_header(m, "AuthType")) ) { + SendError(s, "Must specify AuthType"); + return 1; + } + + if (!*s->challenge) + snprintf(s->challenge, sizeof(s->challenge), "%d", rand()); + + memset(&mo, 0, sizeof(struct message)); + AddHeader(&mo, "Response: Success"); + AddHeader(&mo, "Challenge: %d", s->challenge); + + s->output->write(s, &mo); + return 0; +} + void *ProxySetAutoFilter(struct mansession *s, struct message *m) { struct message mo; char *value; -- cgit From e7575b72bd6cd202c6a9b93369d86bf7c7974938 Mon Sep 17 00:00:00 2001 From: David Troy Date: Sat, 1 Apr 2006 18:52:17 +0000 Subject: git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/branches/1.20pre@53 f02b47b9-160a-0410-81a6-dc3441afb0ec --- src/proxyfunc.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/proxyfunc.c') diff --git a/src/proxyfunc.c b/src/proxyfunc.c index ed4770e..54b7789 100644 --- a/src/proxyfunc.c +++ b/src/proxyfunc.c @@ -106,11 +106,16 @@ void *ProxySetAutoFilter(struct mansession *s, struct message *m) { return 0; } -void *ProxyLogin(struct mansession *s, char *user, char *secret) { - struct message m; +void *ProxyLogin(struct mansession *s, struct message *m) { + struct message mo; struct proxy_user *pu; + char *user, *secret, *md5key; - memset(&m, 0, sizeof(struct message)); + user = astman_get_header(m, "Username"); + secret = astman_get_header(m, "Secret"); + md5key = astman_get_header(m, "Key"); + + memset(&mo, 0, sizeof(struct message)); if( debug ) debugmsg("Login attempt as: %s/%s", user, secret); @@ -118,9 +123,9 @@ void *ProxyLogin(struct mansession *s, char *user, char *secret) { pu = pc.userlist; while( pu ) { if ( !strcmp(user, pu->username) && !strcmp(secret, pu->secret) ) { - AddHeader(&m, "Response: Success"); - AddHeader(&m, "Message: Authentication accepted"); - s->output->write(s, &m); + AddHeader(&mo, "Response: Success"); + AddHeader(&mo, "Message: Authentication accepted"); + s->output->write(s, &mo); s->authenticated = 1; strcpy(s->user.channel, pu->channel); strcpy(s->user.icontext, pu->icontext); -- cgit From fe3ac9141e8cc4caf966b64d8c370f818436d79f Mon Sep 17 00:00:00 2001 From: David Troy Date: Sat, 1 Apr 2006 19:14:17 +0000 Subject: git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/branches/1.20pre@54 f02b47b9-160a-0410-81a6-dc3441afb0ec --- src/proxyfunc.c | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'src/proxyfunc.c') diff --git a/src/proxyfunc.c b/src/proxyfunc.c index 54b7789..95257c2 100644 --- a/src/proxyfunc.c +++ b/src/proxyfunc.c @@ -1,4 +1,5 @@ #include "astmanproxy.h" +#include "md5.h" extern struct mansession *sessions; extern struct iohandler *iohandlers; @@ -106,6 +107,28 @@ void *ProxySetAutoFilter(struct mansession *s, struct message *m) { return 0; } +int AuthMD5(char *key, char *challenge, char *password) { + int x; + int len=0; + char md5key[256] = ""; + struct MD5Context md5; + unsigned char digest[16]; + + if (!*challenge || !*password || !*key) + return 1; + + MD5Init(&md5); + MD5Update(&md5, (unsigned char *) challenge, strlen(challenge)); + MD5Update(&md5, (unsigned char *) password, strlen(password)); + MD5Final(digest, &md5); + for (x=0;x<16;x++) + len += sprintf(md5key + len, "%2.2x", digest[x]); + if (!strcmp(md5key, key)) + return 0; + + return 1; +} + void *ProxyLogin(struct mansession *s, struct message *m) { struct message mo; struct proxy_user *pu; @@ -122,17 +145,20 @@ void *ProxyLogin(struct mansession *s, struct message *m) { pthread_mutex_lock(&userslock); pu = pc.userlist; while( pu ) { - if ( !strcmp(user, pu->username) && !strcmp(secret, pu->secret) ) { - AddHeader(&mo, "Response: Success"); - AddHeader(&mo, "Message: Authentication accepted"); - s->output->write(s, &mo); - s->authenticated = 1; - strcpy(s->user.channel, pu->channel); - strcpy(s->user.icontext, pu->icontext); - strcpy(s->user.ocontext, pu->ocontext); - if( debug ) - debugmsg("Login as: %s", user); - break; + if ( !strcmp(user, pu->username) ) { + if (!AuthMD5(md5key, s->challenge, pu->secret) || + !strcmp(secret, pu->secret) ) { + AddHeader(&mo, "Response: Success"); + AddHeader(&mo, "Message: Authentication accepted"); + s->output->write(s, &mo); + s->authenticated = 1; + strcpy(s->user.channel, pu->channel); + strcpy(s->user.icontext, pu->icontext); + strcpy(s->user.ocontext, pu->ocontext); + if( debug ) + debugmsg("Login as: %s", user); + break; + } } pu = pu->next; } -- cgit From 0785a24392bc993ceb36b9450b4ca720caf25531 Mon Sep 17 00:00:00 2001 From: David Troy Date: Sat, 1 Apr 2006 19:58:09 +0000 Subject: git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/branches/1.20pre@55 f02b47b9-160a-0410-81a6-dc3441afb0ec --- src/proxyfunc.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/proxyfunc.c') diff --git a/src/proxyfunc.c b/src/proxyfunc.c index 95257c2..2992267 100644 --- a/src/proxyfunc.c +++ b/src/proxyfunc.c @@ -78,7 +78,7 @@ int ProxyChallenge(struct mansession *s, struct message *m) { memset(&mo, 0, sizeof(struct message)); AddHeader(&mo, "Response: Success"); - AddHeader(&mo, "Challenge: %d", s->challenge); + AddHeader(&mo, "Challenge: %s", s->challenge); s->output->write(s, &mo); return 0; @@ -114,29 +114,35 @@ int AuthMD5(char *key, char *challenge, char *password) { struct MD5Context md5; unsigned char digest[16]; - if (!*challenge || !*password || !*key) + if (!*key || !*challenge || !*password ) return 1; + if (debug) + debugmsg("MD5 password=%s, challenge=%s", password, challenge); + MD5Init(&md5); MD5Update(&md5, (unsigned char *) challenge, strlen(challenge)); MD5Update(&md5, (unsigned char *) password, strlen(password)); MD5Final(digest, &md5); for (x=0;x<16;x++) len += sprintf(md5key + len, "%2.2x", digest[x]); + if( debug ) { + debugmsg("MD5 computed=%s, received=%s", md5key, key); + } if (!strcmp(md5key, key)) return 0; - - return 1; + else + return 1; } void *ProxyLogin(struct mansession *s, struct message *m) { struct message mo; struct proxy_user *pu; - char *user, *secret, *md5key; + char *user, *secret, *key; user = astman_get_header(m, "Username"); secret = astman_get_header(m, "Secret"); - md5key = astman_get_header(m, "Key"); + key = astman_get_header(m, "Key"); memset(&mo, 0, sizeof(struct message)); if( debug ) @@ -146,7 +152,7 @@ void *ProxyLogin(struct mansession *s, struct message *m) { pu = pc.userlist; while( pu ) { if ( !strcmp(user, pu->username) ) { - if (!AuthMD5(md5key, s->challenge, pu->secret) || + if (!AuthMD5(key, s->challenge, pu->secret) || !strcmp(secret, pu->secret) ) { AddHeader(&mo, "Response: Success"); AddHeader(&mo, "Message: Authentication accepted"); -- cgit From 55a533edf2e466a34179e12bf36e239902aad5fc Mon Sep 17 00:00:00 2001 From: David Troy Date: Sun, 2 Apr 2006 16:24:56 +0000 Subject: git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/branches/1.20pre@57 f02b47b9-160a-0410-81a6-dc3441afb0ec --- src/proxyfunc.c | 32 -------------------------------- 1 file changed, 32 deletions(-) (limited to 'src/proxyfunc.c') diff --git a/src/proxyfunc.c b/src/proxyfunc.c index 2992267..54df298 100644 --- a/src/proxyfunc.c +++ b/src/proxyfunc.c @@ -387,35 +387,3 @@ void *SendError(struct mansession *s, char *errmsg) { return 0; } - -/*! If you are calling ast_carefulwrite, it is assumed that you are calling - it on a file descriptor that _DOES_ have NONBLOCK set. This way, - there is only one system call made to do a write, unless we actually - have a need to wait. This way, we get better performance. */ -int ast_carefulwrite(int fd, char *s, int len, int timeoutms) -{ - /* Try to write string, but wait no more than ms milliseconds - before timing out */ - int res=0; - struct pollfd fds[1]; - while(len) { - res = m_send(fd, s, len); - if ((res < 0) && (errno != EAGAIN)) { - return -1; - } - if (res < 0) res = 0; - len -= res; - s += res; - res = 0; - if (len) { - fds[0].fd = get_real_fd(fd); - fds[0].events = POLLOUT; - /* Wait until writable again */ - res = poll(fds, 1, timeoutms); - if (res < 1) - return -1; - } - } - return res; -} - -- cgit From 08a84749d9c92829d580c508f3b0256f7b188321 Mon Sep 17 00:00:00 2001 From: David Troy Date: Tue, 4 Apr 2006 22:33:15 +0000 Subject: git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/branches/1.20pre@83 f02b47b9-160a-0410-81a6-dc3441afb0ec --- src/proxyfunc.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/proxyfunc.c') diff --git a/src/proxyfunc.c b/src/proxyfunc.c index 54df298..d1d5f38 100644 --- a/src/proxyfunc.c +++ b/src/proxyfunc.c @@ -54,7 +54,6 @@ void *ProxySetOutputFormat(struct mansession *s, struct message *m) { value = astman_get_header(m, "OutputFormat"); SetIOHandlers(s, s->input->formatname, value); - /* TODO: this is retarded */ memset(&mo, 0, sizeof(struct message)); AddHeader(&mo, "ProxyResponse: Success"); @@ -206,10 +205,7 @@ int ProxyAddServer(struct mansession *s, struct message *m) { fprintf(stderr, "Failed to allocate server credentials: %s\n", strerror(errno)); exit(1); } - memset(srv, 0, sizeof (struct ast_server) ); - - /* TODO: Disallow adding of duplicate servers? Or not, I suppose that could be useful (events on/off) */ memset(srv, 0, sizeof(struct ast_server) ); memset(&mo, 0, sizeof(struct message)); strcpy(srv->ast_host, astman_get_header(m, "Server")); -- cgit From 27aa7a3382cf0ed4973fa7e207d4ffc9733f69d5 Mon Sep 17 00:00:00 2001 From: David Troy Date: Fri, 7 Apr 2006 20:55:51 +0000 Subject: git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/branches/1.20pre@94 f02b47b9-160a-0410-81a6-dc3441afb0ec --- src/proxyfunc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/proxyfunc.c') diff --git a/src/proxyfunc.c b/src/proxyfunc.c index d1d5f38..434baff 100644 --- a/src/proxyfunc.c +++ b/src/proxyfunc.c @@ -156,10 +156,12 @@ void *ProxyLogin(struct mansession *s, struct message *m) { AddHeader(&mo, "Response: Success"); AddHeader(&mo, "Message: Authentication accepted"); s->output->write(s, &mo); - s->authenticated = 1; + pthread_mutex_lock(&s->lock); + s->authenticated = 1; strcpy(s->user.channel, pu->channel); strcpy(s->user.icontext, pu->icontext); strcpy(s->user.ocontext, pu->ocontext); + pthread_mutex_unlock(&s->lock); if( debug ) debugmsg("Login as: %s", user); break; @@ -171,11 +173,14 @@ void *ProxyLogin(struct mansession *s, struct message *m) { if( !pu ) { SendError(s, "Authentication failed"); + pthread_mutex_lock(&s->lock); s->authenticated = 0; + pthread_mutex_unlock(&s->lock); if( debug ) debugmsg("Login failed as: %s/%s", user, secret); } + return 0; } @@ -334,7 +339,7 @@ int ValidateAction(struct message *m, struct mansession *s, int inbound) { char *uchannel; char *ucontext; - if( !s->authenticated ) + if( pc.authrequired && !s->authenticated ) return 0; if( inbound ) -- cgit