2013-01-06 22:16:21 +01:00
|
|
|
/*
|
|
|
|
* mydomains.c, SJ
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <piler.h>
|
|
|
|
|
|
|
|
|
2017-08-08 15:34:45 +02:00
|
|
|
void load_mydomains(struct session_data *sdata, struct data *data, struct config *cfg){
|
2013-07-12 22:54:45 +02:00
|
|
|
int rc;
|
2013-01-06 22:16:21 +01:00
|
|
|
char s[SMALLBUFSIZE];
|
2017-08-11 18:18:45 +02:00
|
|
|
struct sql sql;
|
2013-01-06 22:16:21 +01:00
|
|
|
|
2013-05-05 11:57:14 +02:00
|
|
|
memset(s, 0, sizeof(s));
|
2013-01-06 22:16:21 +01:00
|
|
|
|
|
|
|
|
2017-08-11 18:18:45 +02:00
|
|
|
if(prepare_sql_statement(sdata, &sql, SQL_PREPARED_STMT_GET_DOMAINS) == ERR) return;
|
2013-01-06 22:16:21 +01:00
|
|
|
|
|
|
|
|
2017-08-11 18:18:45 +02:00
|
|
|
p_bind_init(&sql);
|
2013-05-05 11:57:14 +02:00
|
|
|
|
2017-08-11 18:18:45 +02:00
|
|
|
if(p_exec_stmt(sdata, &sql) == OK){
|
2013-05-05 11:57:14 +02:00
|
|
|
|
2017-08-11 18:18:45 +02:00
|
|
|
p_bind_init(&sql);
|
2013-05-05 11:57:14 +02:00
|
|
|
|
2017-08-11 18:18:45 +02:00
|
|
|
sql.sql[sql.pos] = &s[0]; sql.type[sql.pos] = TYPE_STRING; sql.len[sql.pos] = sizeof(s)-2; sql.pos++;
|
2013-05-05 11:57:14 +02:00
|
|
|
|
2017-08-11 18:18:45 +02:00
|
|
|
p_store_results(&sql);
|
2013-05-05 11:57:14 +02:00
|
|
|
|
2017-08-11 18:18:45 +02:00
|
|
|
while(p_fetch_results(&sql) == OK){
|
2015-12-18 22:38:52 +01:00
|
|
|
rc = addnode(data->mydomains, s);
|
2013-05-05 11:57:14 +02:00
|
|
|
|
2015-12-18 22:38:52 +01:00
|
|
|
if(rc == 0) syslog(LOG_PRIORITY, "failed to append mydomain: '%s'", s);
|
|
|
|
else if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "added mydomain: '%s'", s);
|
2013-08-14 14:24:30 +02:00
|
|
|
|
2015-12-18 22:38:52 +01:00
|
|
|
memset(s, 0, sizeof(s));
|
|
|
|
}
|
2013-01-06 22:16:21 +01:00
|
|
|
|
2017-08-11 18:18:45 +02:00
|
|
|
p_free_results(&sql);
|
2013-01-06 22:16:21 +01:00
|
|
|
}
|
|
|
|
|
2017-08-11 18:18:45 +02:00
|
|
|
close_prepared_statement(&sql);
|
2013-07-12 22:54:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-08 15:34:45 +02:00
|
|
|
int is_email_address_on_my_domains(char *email, struct data *data){
|
2013-07-12 22:54:45 +02:00
|
|
|
int rc=0;
|
|
|
|
char *q, *s;
|
|
|
|
|
|
|
|
if(email == NULL) return rc;
|
|
|
|
|
|
|
|
q = strchr(email, '@');
|
|
|
|
if(!q || strlen(q) < 3) return rc;
|
|
|
|
|
|
|
|
s = strrchr(q+1, ' ');
|
|
|
|
|
|
|
|
if(s) *s = '\0';
|
2013-05-05 11:57:14 +02:00
|
|
|
|
2013-08-14 14:24:30 +02:00
|
|
|
if(findnode(data->mydomains, q+1)) rc = 1;
|
2013-07-12 22:54:45 +02:00
|
|
|
|
|
|
|
if(s) *s = ' ';
|
|
|
|
|
|
|
|
return rc;
|
2013-01-06 22:16:21 +01:00
|
|
|
}
|