diff -Naur server/mysql.c server_postfix/mysql.c --- server/mysql.c 2008-02-21 15:40:04.000000000 +0100 +++ server_postfix/mysql.c 2008-02-22 17:15:23.000000000 +0100 @@ -138,6 +138,7 @@ char * query ; int affected ; + /* the bind part */ query = ( char * ) malloc ( sizeof ( char ) * 160 ) ; memset ( query, '\0', sizeof ( char ) * 160 ) ; conn = mysql_init ( NULL ) ; @@ -160,6 +161,28 @@ affected = mysql_affected_rows ( conn ) ; + mysql_close ( conn ) ; + + /* the postfix part */ + memset ( query, '\0', sizeof ( char ) * 160 ) ; + conn = mysql_init ( NULL ) ; + + if ( ! mysql_real_connect ( conn, auth_db.host, auth_db.user, auth_db.password, auth_db.postfix_db, 0, NULL, 0 ) ) + { + log_message ( "Can't connect to database : %s\n", mysql_error ( conn ) ) ; + exit ( 0 ) ; + } + + sprintf ( query, "update `network_table` set `ip` = '127.0.0.1' where `hostname` = '%.50s'", hostname ) ; + + if ( mysql_real_query ( conn, query, sizeof ( char ) * strnlen ( query, 160 ) ) ) + { + log_message ( "Can't reset postfix conf : %s\n", mysql_error ( conn ) ) ; + free ( query ) ; + mysql_close ( conn ) ; + return 0 ; + } + free ( query ) ; mysql_close ( conn ) ; @@ -209,7 +232,8 @@ } /* Called when all the authentication process has gone well. - * Update the A data from bind to the ip of the client */ + * Update the A data from bind to the ip of the client + * and update the mynetworks value of postfix */ int update_host ( char * hostname, char * ip ) { @@ -217,6 +241,7 @@ char * query ; int i ; + /* the bind part */ query = ( char * ) malloc ( sizeof ( char ) * 140 ) ; memset ( query, '\0', sizeof ( char ) * 140 ) ; @@ -238,7 +263,30 @@ return 0 ; } + mysql_close ( conn ) ; + + /* the postfix part */ + memset ( query, '\0', sizeof ( char ) * 140 ) ; + + conn = mysql_init ( NULL ) ; + + if ( ! mysql_real_connect ( conn, auth_db.host, auth_db.user, auth_db.password, auth_db.postfix_db, 0, NULL, 0 ) ) + { + log_message ( "Can't connect to database : %s\n", mysql_error ( conn ) ) ; + exit ( 0 ) ; + } + + sprintf ( query, "update network_table set `ip` = '%.20s' where `hostname` = '%.50s'", ip, hostname ) ; + + if ( mysql_real_query ( conn, query, sizeof ( char ) * strnlen ( query, 140 ) ) ) + { + log_message ( "Can't update postfix conf : %s", mysql_error ( conn ) ) ; + free ( query ) ; + mysql_close ( conn ) ; + return 0 ; + } + /* reset timeout counter and bring thread in awaken state */ for ( i = 0 ; i < list->count ; i++ ) if ( strncmp ( hostname, (list->sessions[i]).hostname, 50 ) == 0 ) { diff -Naur server/parse_config.c server_postfix/parse_config.c --- server/parse_config.c 2008-02-21 15:50:58.000000000 +0100 +++ server_postfix/parse_config.c 2008-02-22 17:15:23.000000000 +0100 @@ -30,14 +30,16 @@ int i, j ; memset ( &auth_db, '\0', sizeof ( auth_db_t ) ) ; - auth_db.host = ( char * ) malloc ( sizeof ( char ) * 50 ) ; - auth_db.user = ( char * ) malloc ( sizeof ( char ) * 20 ) ; - auth_db.password = ( char * ) malloc ( sizeof ( char ) * 20 ) ; - auth_db.db = ( char * ) malloc ( sizeof ( char ) * 20 ) ; - memset ( auth_db.host, '\0', sizeof ( char ) * 50 ) ; - memset ( auth_db.user, '\0', sizeof ( char ) * 20 ) ; - memset ( auth_db.password, '\0', sizeof ( char ) * 20 ) ; - memset ( auth_db.db, '\0', sizeof ( char ) * 20 ) ; + auth_db.host = ( char * ) malloc ( sizeof ( char ) * 50 ) ; + auth_db.user = ( char * ) malloc ( sizeof ( char ) * 20 ) ; + auth_db.password = ( char * ) malloc ( sizeof ( char ) * 20 ) ; + auth_db.db = ( char * ) malloc ( sizeof ( char ) * 20 ) ; + auth_db.postfix_db = ( char * ) malloc ( sizeof ( char ) * 20 ) ; + memset ( auth_db.host, '\0', sizeof ( char ) * 50 ) ; + memset ( auth_db.user, '\0', sizeof ( char ) * 20 ) ; + memset ( auth_db.password, '\0', sizeof ( char ) * 20 ) ; + memset ( auth_db.db, '\0', sizeof ( char ) * 20 ) ; + memset ( auth_db.postfix_db, '\0', sizeof ( char ) * 20 ) ; opterr = 0 ; /* ensure that arguments have a decent length */ @@ -46,7 +48,7 @@ for ( j=51 ; j < ( int ) strnlen ( argv[i], 60 ) ; j++ ) argv[i][j] = '\0' ; - while ( ( argument = getopt ( argc, argv, "DP:h:u:p:d:" ) ) != -1 ) + while ( ( argument = getopt ( argc, argv, "DP:h:u:p:d:m:" ) ) != -1 ) { switch ( argument ) { @@ -99,8 +101,17 @@ strncpy ( auth_db.db, optarg, 20 ) ; break; + case 'm': + if ( strnlen ( optarg, 30 ) > 20 ) + { + printf ( "database name is too long ( up to 20 characters )" ) ; + exit ( 1 ) ; + } + strncpy ( auth_db.postfix_db, optarg, 20 ) ; + break; + case '?': - if (optopt == 'h' || optopt == 'u' || optopt == 'p' || optopt == 'd' ) + if (optopt == 'h' || optopt == 'u' || optopt == 'p' || optopt == 'd' || optopt == 'm' ) { log_message ( "Option -%c requires an argument.\n", optopt ) ; usage ( argv ) ; @@ -122,10 +133,11 @@ } } - if ( strncmp ( auth_db.host, "", 50 ) == 0 - || strncmp ( auth_db.user, "", 20 ) == 0 - || strncmp ( auth_db.password, "", 20 ) == 0 - || strncmp ( auth_db.db, "", 20 ) == 0 + if ( strncmp ( auth_db.host, "", 50 ) == 0 + || strncmp ( auth_db.user, "", 20 ) == 0 + || strncmp ( auth_db.password, "", 20 ) == 0 + || strncmp ( auth_db.db, "", 20 ) == 0 + || strncmp ( auth_db.postfix_db, "", 20 ) == 0 ) parse_config_file() ; @@ -142,13 +154,13 @@ char * line = NULL ; size_t length = 0 ; regex_t regex ; - size_t nmatch = 3 ; + size_t nmatch = 3 ; regmatch_t pmatch[3] ; int i, type_length, value_length ; char * type ; char * value ; - if ( regcomp ( ®ex, "(host|user|password|database|port) *= *(.*?)\n", REG_EXTENDED ) ) + if ( regcomp ( ®ex, "(host|user|password|^database|postfix_database|port) *= *(.*?)\n", REG_EXTENDED ) ) { log_message ( "error in regcomp while parsing conf file\n" ) ; exit ( 1 ) ; @@ -191,7 +203,7 @@ for ( i=0 ; i