Skip to content

Commit

Permalink
Fix white space
Browse files Browse the repository at this point in the history
  • Loading branch information
baimard committed Dec 10, 2020
1 parent 86c23b0 commit 11a0c14
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 45 deletions.
6 changes: 3 additions & 3 deletions pam_yubico.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ authorize_user_token (struct cfg *cfg,
int retval = AUTH_ERROR;
if (cfg->mysql_server)
{
#if HAVE_MYSQL
#ifdef HAVE_MYSQL
/* Administrator had configured the database and specified is name
as an argument for this module.
*/
DBG ("Using Mariadb or Mysql Database");
retval = check_user_token_mysql(cfg->mysql_server, cfg->mysql_user, cfg->mysql_password, cfg->mysql_database, username, otp_id, cfg->debug, cfg->debug_file);
DBG ("Using Mariadb or Mysql Database");
retval = check_user_token_mysql(cfg->mysql_server, cfg->mysql_user, cfg->mysql_password, cfg->mysql_database, username, otp_id, cfg->debug, cfg->debug_file);
#else
DBG (("Trying to use MYSQL, but this function is not compiled in pam_yubico!!"));
#endif
Expand Down
83 changes: 41 additions & 42 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,26 @@ get_user_cfgfile_path(const char *common_path, const char *filename, const struc
*
* Returns one of AUTH_FOUND, AUTH_NOT_FOUND, AUTH_NO_TOKENS, AUTH_ERROR.
*
* Need database with this table structure :
*
* CREATE TABLE IF NOT EXISTS `otp`.`yubikey_mappings` (
* `otp_id` VARCHAR(12) NOT NULL ,
* `username` VARCHAR(64) NOT NULL ,
* Need database with this table structure:
*
* CREATE TABLE IF NOT EXISTS `otp`.`yubikey_mappings`(
* `otp_id` VARCHAR(12) NOT NULL ,
* `username` VARCHAR(64) NOT NULL ,
* PRIMARY KEY (`otp_id`(12))
* );
*
*/
int
check_user_token_mysql (const char *mysql_server,
const char *mysql_user,
const char *mysql_password,
const char *mysql_database,
const char *username,
const char *otp_id,
int verbose,
FILE *debug_file)
check_user_token_mysql(const char *mysql_server,
const char *mysql_user,
const char *mysql_password,
const char *mysql_database,
const char *username,
const char *otp_id,
int verbose,
FILE *debug_file)
{

int retval = AUTH_ERROR;
int fd;
struct stat st;
Expand All @@ -131,7 +131,6 @@ check_user_token_mysql (const char *mysql_server,
MYSQL_STMT *stmt;
MYSQL_BIND ps_params[2];
MYSQL_BIND bind[1];

long unsigned int str_username;
long unsigned int str_otp;
long unsigned int length;
Expand All @@ -140,64 +139,64 @@ check_user_token_mysql (const char *mysql_server,
bool is_null;
bool error;

if (mysql_library_init(0, NULL, NULL)) {
if(mysql_library_init(0, NULL, NULL)){
if(verbose){
D (debug_file, "could not initialize MySQL client library");
}

return retval;
}

con = mysql_init(con);
if (!con) {
if(!con) {
if(verbose)
D (debug_file, "out of memorys");
return retval;
}

if (mysql_real_connect(con, mysql_server,mysql_user,mysql_password,mysql_database, 0, NULL, 0) == NULL)
if(mysql_real_connect(con, mysql_server,mysql_user,mysql_password,mysql_database, 0, NULL, 0) == NULL)
{
if(verbose)
D (debug_file, "Connection failed ...");
return retval;
return retval;
}

stmt = mysql_stmt_init(con);
if (!stmt)
if(!stmt)
{
if(verbose)
D (debug_file, "Connection failed ... 2");
return retval;
return retval;
}

const char *sql = "SELECT count(username) FROM yubikey_mappings WHERE username = ?;";
const char *sql2 = "SELECT count(username) FROM yubikey_mappings WHERE username = ? and otp_id = ?;";

if(otp_id == NULL)
{
if (mysql_stmt_prepare(stmt, sql, strlen(sql)))
if(mysql_stmt_prepare(stmt, sql, strlen(sql)))
{
if(verbose)
D (debug_file, "mysql_stmt_prepare() failed %s", mysql_stmt_error(stmt));
return retval;
return retval;
}
}else{
if (mysql_stmt_prepare(stmt, sql2, strlen(sql2)))
if(mysql_stmt_prepare(stmt, sql2, strlen(sql2)))
{
if(verbose)
D (debug_file, "mysql_stmt_prepare() failed %s", mysql_stmt_error(stmt));
return retval;
return retval;
}
}

str_username = strlen(username);
str_username = strlen(username);
memset(ps_params, 0, sizeof(ps_params));
ps_params[0].buffer_type = MYSQL_TYPE_STRING;
ps_params[0].buffer = (char *)username;
ps_params[0].buffer_length = str_username;
ps_params[0].length = &str_username;
ps_params[0].is_null = 0;

if(otp_id != NULL)
{
str_otp= strlen(otp_id);
Expand All @@ -208,18 +207,18 @@ check_user_token_mysql (const char *mysql_server,
ps_params[1].is_null = 0;
}

if (mysql_stmt_bind_param(stmt, ps_params))
if(mysql_stmt_bind_param(stmt, ps_params))
{
if(verbose)
D (debug_file, "mysql_stmt_bind_param() failed %s", mysql_stmt_error(stmt));
return retval;
return retval;
}

if (mysql_stmt_execute(stmt))
if(mysql_stmt_execute(stmt))
{
if(verbose)
D (debug_file, "mysql_stmt_execute() failed %s", mysql_stmt_error(stmt));
return retval;
return retval;
}

memset(bind, 0, sizeof(bind));
Expand All @@ -229,20 +228,20 @@ check_user_token_mysql (const char *mysql_server,
bind[0].is_null = &is_null;
bind[0].error = &error;

if (mysql_stmt_bind_result(stmt, bind))
if(mysql_stmt_bind_result(stmt, bind))
{
if(verbose)
D (debug_file, "mysql_stmt_bind_result() failed %s", mysql_stmt_error(stmt));
}

if (mysql_stmt_store_result(stmt))
if(mysql_stmt_store_result(stmt))
{
if(verbose)
D (debug_file, "mysql_stmt_store_result() failed %s", mysql_stmt_error(stmt));
return retval;
}

while (!mysql_stmt_fetch(stmt))
while(!mysql_stmt_fetch(stmt))
{
if(is_null)
{
Expand All @@ -260,27 +259,27 @@ check_user_token_mysql (const char *mysql_server,
return AUTH_NOT_FOUND;
}
}
else if (otp_id == NULL)
else if(otp_id == NULL)
{
if(int_data)
{
return AUTH_NOT_FOUND;
}
else
{
return AUTH_NO_TOKENS;
return AUTH_NO_TOKENS;
}
}
}
}
}

if (mysql_stmt_close(stmt))
if(mysql_stmt_close(stmt))
{
if(verbose)
D (debug_file, "mysql_stmt_close() failed %s", mysql_stmt_error(stmt));
return retval;
return retval;
}

mysql_close(con);
mysql_library_end();

Expand Down

0 comments on commit 11a0c14

Please sign in to comment.