Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had the very same problem. However, writing my own custom authentication module would've been an overkill since the available pgsql auth does nearly everything I want.. Here's what changes I made for it to suit my needs:</p> <p>In log_pgsql_p.h add <code>static char *salting;</code> and <code>static char *sqlreq_getsalt;</code> and extend the <code>static ConfigKeywords pgsql_config_keywords[]</code> with <code>{ "PGSQLSalting", &amp;salting },</code> and <code>{ "PGSQLGetSalt", &amp;sqlreq_getsalt },</code>.</p> <p>In log_pgsql.h I added <code>#define SALT_SQL_APPEND "append"</code>, <code>#define SALT_SQL_PREPEND "prepend"</code> and <code>#define SALT_SQL_NONE "none"</code>.</p> <p>In log_pgsql.c I then made the following changes in the <code>pw_psql_check</code> function:</p> <p>I declared <code>const char *salt = NULL;</code> and <code>char * salted_password = NULL;</code> at the top. Directly before <code>spwd</code> gets assigned the result of the query to <code>sqlreq_getpw</code> I added</p> <pre><code>if (strcasecmp(salting, SALT_SQL_NONE) != 0) { salt = pw_pgsql_getquery(id_sql_server, sqlreq_getsalt, escaped_account, escaped_ip, escaped_port, escaped_peer_ip, escaped_decimal_ip); } </code></pre> <p>Then, before the encryption takes place:</p> <pre><code>if (salt != NULL) { int salted_pw_size = strlen(salt) + strlen(password) + 1; salted_password = (char *) malloc(salted_pw_size); if (strcasecmp(salting, SALT_SQL_APPEND) == 0) { strcpy(salted_password, password); strcat(salted_password, salt); } else if (strcasecmp(salting, SALT_SQL_PREPEND) == 0) { strcpy(salted_password, salt); strcat(salted_password, password); } } else { salted_password = (char *) malloc(strlen(password)); strcpy(salted_password, password); } </code></pre> <p>And then I replaced the <code>password</code> argument in subsequent calls to the crypt-methods (crypt, crypto_hash_md5, crypto_hash_sha1) and the <code>strcasecmp</code> for 'cleartext' with <code>(const char*)salted_password</code>.</p> <p>Now all that's left to do is tidying up the memory we allocated. Especially the plaintext-password with appended/prepended salt shouldn't remain in memory - call it paranoia if you want. So after the <code>bye:</code> label add</p> <pre><code>free((void *) salt; if(strcasecmp(salting, SALT_SQL_NONE) != 0) { volatile char *salted_password_ = (volatile char *) salted_password; while(*salted_password_ != 0) { *salted_password_++ = 0; } free((void *) salted_password); } </code></pre> <p>With these changes you now have two additional parameters in your config file available:</p> <ul> <li>PGSQLSalting: Accepts 'append' (appends the salt to the pw), 'prepend' and 'none' (without the apostrophe)</li> <li>PGSQLGetSalt: Here you specify the field in your db to fetch the salt from, much like with the crypted password you need to retrieve via PGSQLGetPw.</li> </ul> <p>Edit: Oh, and don't forget to free the allocated memory at the end of the function!</p> <p>I also can provide a diff file that works for the release 1.0.36.. <a href="http://pastie.org/5080976" rel="nofollow">here you go!</a> Beware though, i added the if around the freeing of salted_password later (because i only later realized how this might lead to an error if salted_password points to password), so this is not in the diff and I'm too lazy to change the diff file :/</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload