Skip to content

Commit

Permalink
sql: add mysql_port configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
klali committed Apr 6, 2021
1 parent 54c2104 commit aa81bb8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions pam_yubico.8.txt
Expand Up @@ -119,6 +119,9 @@ Path of a system-wide directory where challenge-response files can be found for
*mysql_server*=_mysqlserver_::
Hostname/Adress of mysql server. Example 10.0.0.1

*mysql_port*=_mysqlport_::
Network port of mysql server.

*mysql_user*=_mysqluser_::
User for accessing to the database. Strongly recommended to use a specific user with read only access.

Expand Down
10 changes: 7 additions & 3 deletions pam_yubico.c
Expand Up @@ -135,6 +135,7 @@ struct cfg
const char *yubi_attr;
const char *yubi_attr_prefix;
const char *mysql_server;
int mysql_port;
const char *mysql_user;
const char *mysql_password;
const char *mysql_database;
Expand Down Expand Up @@ -176,7 +177,7 @@ authorize_user_token (struct cfg *cfg,
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);
retval = check_user_token_mysql(cfg->mysql_server, cfg->mysql_port, 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 Expand Up @@ -892,9 +893,11 @@ parse_cfg (int flags, int argc, const char **argv, struct cfg *cfg)
cfg->chalresp_path = argv[i] + 14;
if (strncmp (argv[i], "mysql_server=", 13) == 0)
cfg->mysql_server = argv[i] + 13;
if (strncmp (argv[i], "mysql_user=", 11) == 0)
if (strncmp (argv[i], "mysql_port=", 11) == 0)
sscanf (argv[i], "mysql_port=%u", &cfg->mysql_port);
if (strncmp (argv[i], "mysql_user=", 11) == 0)
cfg->mysql_user = argv[i] + 11;
if (strncmp (argv[i], "mysql_password=", 15) == 0)
if (strncmp (argv[i], "mysql_password=", 15) == 0)
cfg->mysql_password = argv[i] + 15;
if (strncmp (argv[i], "mysql_database=", 15) == 0)
cfg->mysql_database = argv[i] + 15;
Expand Down Expand Up @@ -965,6 +968,7 @@ parse_cfg (int flags, int argc, const char **argv, struct cfg *cfg)
DBG ("mode=%s", cfg->mode == CLIENT ? "client" : "chresp" );
DBG ("chalresp_path=%s", cfg->chalresp_path ? cfg->chalresp_path : "(null)");
DBG ("mysql_server=%s", cfg->mysql_server ? cfg->mysql_server : "(null)");
DBG ("mysql_port=%d", cfg->mysql_port);
DBG ("mysql_user=%s", cfg->mysql_user ? cfg->mysql_user : "(null)");
DBG ("mysql_database=%s", cfg->mysql_database ? cfg->mysql_database : "(null)");

Expand Down
3 changes: 2 additions & 1 deletion util.c
Expand Up @@ -114,6 +114,7 @@ get_user_cfgfile_path(const char *common_path, const char *filename, const struc
*/
int
check_user_token_mysql(const char *mysql_server,
int mysql_port,
const char *mysql_user,
const char *mysql_password,
const char *mysql_database,
Expand Down Expand Up @@ -152,7 +153,7 @@ check_user_token_mysql(const char *mysql_server,
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, mysql_port, NULL, 0) == NULL)
{
if(verbose)
D (debug_file, "Connection failed ...");
Expand Down
4 changes: 3 additions & 1 deletion util.h
Expand Up @@ -52,7 +52,9 @@

int get_user_cfgfile_path(const char *common_path, const char *filename, const struct passwd *user, char **fn);
#ifdef HAVE_MYSQL
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);
int check_user_token_mysql(const char *mysql_server, int mysql_port, const char *mysql_user,
const char *mysql_password, const char *mysql_database, const char *username, const char *otp_id, int verbose,
FILE *debug_file);
#endif
int check_user_token(const char *authfile, const char *username, const char *otp_id, int verbose, FILE *debug_file);

Expand Down

0 comments on commit aa81bb8

Please sign in to comment.