/*
Verify that this user/password is valid per a database.
Return 1 if verified, 0 otherwise.
-
+
Format of connection string (look like internet URL):
db://user:password@hostname/table?name&passwd
'default authentication = db <string>'
28-nov-1998 Added code for NULL database %)
14-dec-1999 Add code for MySQL and also more check
-
+
FUTURE:
Make *_db_verify() the functions is reenterable
More security for connection to database
Separate debug logging
Perfomance testing on 10000 records in Oracle database
(in guide sayd about 3 auth/sec on Ultra 2 - hmm)
-
+
-------------------------------------------------------
fil@artelecom.ru http://twister.pp.ru
-
+
****************************************************************************
PART II
I am added some extra extension. Like MySQL and PostgreSQL database support
- And change most of lines for use dynamic memory allocation. db_accounting
+ And change most of lines for use dynamic memory allocation. db_accounting
added by me.
-
+
devrim(devrim@gazi.edu.tr)
*/
-#if defined(DB)
-#include <stdio.h>
+
#include "tac_plus.h"
+
+#ifdef DB
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "db.h"
+#include "report.h"
+#include "do_acct.h"
+#include "main.h"
+#include "do_author.h" /* for "struct identity" */
+#include "utils.h"
+
+
+#ifdef DB_MYSQL
+#include "db_mysql.h"
+#endif
+#ifdef DB_NULL
+#include "db_null.h"
+#endif
+#ifdef DB_PGSQL
+#include "db_pgsql.h"
+#endif
+
+
+static int check_db_type TAC_ARGS((char *db_type));
+
+
/* The databases recognized by this function */
#define DEFINED_DB {"null","mysql","pgsql"}
-char *find_attr_value();
+int db_verify TAC_ARGS((const char *user, const char *users_passwd, const char *str_conn));
int
db_verify(user, users_passwd, str_conn)
-char *user, *users_passwd; /* Username and gived password */
-char *str_conn; /* String connection to database */
+const char *user; /* username ... */
+const char *users_passwd; /* ... and given password */
+const char *str_conn; /* string connection to database */
{
char *buffer;
char *db_pref, *db_user, *db_password;
if (debug & DEBUG_PASSWD_FLAG)
report(LOG_DEBUG, "verify %s by database at %s", user, str_conn);
- buffer = db_pref = (char *)malloc( strlen(str_conn) + 1 );
- if( buffer == NULL ){
- report(LOG_DEBUG, "Error allocation memory");
- return(0);
- }
+ buffer = db_pref = (char *) tac_malloc( strlen(str_conn) + 1 );
strcpy( buffer, str_conn );
free(buffer);
return(0);
}
- *db_user = '\0';
+ *db_user = '\0';
/* For recognize db authentication database */
-
+
if (check_db_type(db_pref)) {
report(LOG_DEBUG, "%s DB authentication scheme didn't recognize by tac_plus",db_pref);
free(buffer);
}
*db_password = '\0';
db_password++;
-
+
db_hostname = (char *)strstr( db_password, "@" );
if( db_hostname == NULL ){
if (debug & DEBUG_PASSWD_FLAG)
}
*db_hostname = '\0';
db_hostname++;
-
+
db_name = (char *)strstr( db_hostname, "/" );
if( db_name == NULL ){
if (debug & DEBUG_PASSWD_FLAG)
report(LOG_DEBUG, "Error parse db_name");
free(buffer);
return(0);
- }
+ }
*db_name = '\0';
db_name++;
-
+
db_table = (char *)strstr( db_name, "/" );
if( db_table == NULL ){
if (debug & DEBUG_PASSWD_FLAG)
report(LOG_DEBUG, "Error parse db_table");
free(buffer);
return(0);
- }
+ }
*db_table = '\0';
db_table++;
-
+
dbfield_name = (char *)strstr( db_table, "?" );
if( dbfield_name == NULL){
if (debug & DEBUG_PASSWD_FLAG)
}
*dbfield_passwd = '\0';
dbfield_passwd++;
-
+
/* Parse database connection string */
if (debug & DEBUG_PASSWD_FLAG)
}
+int db_acct TAC_ARGS((struct acct_rec *rec));
+
/* Db accounting routine */
int
db_acct(rec)
char *a_username,*s_name,*c_name,*elapsed_time,*bytes_in,*bytes_out;
int ret;
- buffer = db_pref = (char *)malloc( strlen(session.db_acct) + 1 );
-
- if( buffer == NULL ){
- report(LOG_DEBUG, "Error allocation memory");
- return(0);
- }
+ buffer = db_pref = (char *) tac_malloc( strlen(session.db_acct) + 1 );
strcpy( buffer, session.db_acct);
free(buffer);
return(0);
}
- *db_user = '\0';
+ *db_user = '\0';
/* For recognize db accouting database */
-
+
if( check_db_type(db_pref) ) {
report(LOG_DEBUG, "%s DB accounting scheme didn't recognize by tac_plus",db_pref);
free(buffer);
}
*db_password = '\0';
db_password++;
-
+
db_hostname = (char *)strstr( db_password, "@" );
if( db_hostname == NULL ){
if (debug & DEBUG_PASSWD_FLAG)
}
*db_hostname = '\0';
db_hostname++;
-
+
db_name = (char *)strstr( db_hostname, "/" );
if( db_name == NULL ){
if (debug & DEBUG_PASSWD_FLAG)
report(LOG_DEBUG, "Error parse db_name");
free(buffer);
return(0);
- }
+ }
*db_name = '\0';
db_name++;
-
+
db_table = (char *)strstr( db_name, "/" );
if( db_table == NULL ){
if (debug & DEBUG_PASSWD_FLAG)
report(LOG_DEBUG, "Error parse db_table");
free(buffer);
return(0);
- }
+ }
*db_table = '\0';
db_table++;
/* Find some attributes for accounting */
a_username=rec->identity->username;
if (a_username==NULL ) {
- if (debug & DEBUG_PASSWD_FLAG)
+ if (debug & DEBUG_PASSWD_FLAG)
report(LOG_DEBUG,"db_acct: Can't find username!");
free(buffer);
return(0);
}
s_name=rec->identity->NAS_name;
if (s_name==NULL) {
- if (debug & DEBUG_PASSWD_FLAG)
+ if (debug & DEBUG_PASSWD_FLAG)
report(LOG_DEBUG,"db_acct: Can't find NAS name!");
free(buffer);
return(0);
}
c_name=find_attr_value("addr", rec->args, rec->num_args);
if (c_name==NULL) {
- if (debug & DEBUG_PASSWD_FLAG)
+ if (debug & DEBUG_PASSWD_FLAG)
report(LOG_DEBUG,"db_acct: Can't find client adress!");
- /* Can't find client adress so give NAC_address attribute value */
+ /* Can't find client adress so give NAC_address attribute value */
c_name=rec->identity->NAC_address;
}
elapsed_time=find_attr_value("elapsed_time", rec->args, rec->num_args);
if (elapsed_time==NULL) {
- if (debug & DEBUG_PASSWD_FLAG)
+ if (debug & DEBUG_PASSWD_FLAG)
report(LOG_DEBUG,"db_acct: Can't get elapsed time!");
free(buffer);
return(0);
}
+static int check_db_type TAC_ARGS((char *db_type));
+
/* For checking DB type */
-int
+static int
check_db_type(db_type)
char *db_type;
{
}
return ret;
}
+
+#else /* DB */
+
+TAC_SOURCEFILE_EMPTY
+
#endif /* DB */