]> granicus.if.org Git - pgbouncer/commitdiff
dont waste room for storing login-time salt.
authorMarko Kreen <markokr@gmail.com>
Thu, 3 Jul 2008 13:07:28 +0000 (13:07 +0000)
committerMarko Kreen <markokr@gmail.com>
Thu, 3 Jul 2008 13:07:28 +0000 (13:07 +0000)
Instead store it in cancel_key[], as it is used
only once, before generating the cancel_key.

include/bouncer.h
src/client.c

index 608472a127739d34624411ba325a0a42d8812d48..50a5b2e87dbed6ce5d559f3029d5d48237895fb8 100644 (file)
@@ -270,7 +270,6 @@ struct PgSocket {
        usec_t request_time;    /* last activity time */
        usec_t query_start;     /* query start moment */
 
-       char salt[4];           /* login key salt */
        uint8_t cancel_key[BACKENDKEY_LEN]; /* client: generated, server: remote */
        PgAddr remote_addr;     /* ip:port for remote endpoint */
        PgAddr local_addr;      /* ip:port for local endpoint */
@@ -288,6 +287,9 @@ struct PgSocket {
 #define tmp_sk_linkfd  query_start
 /* takeover_clean_socket() needs to clean those up */
 
+/* where the salt is temporarly stored */
+#define tmp_login_salt  cancel_key
+
 /* main.c */
 extern int cf_verbose;
 extern int cf_daemon;
index bda55b71127f1d651e61fcadb1c6943a80bf7dfe..2845852dabdfba81248f173e99c897d5c1d00624 100644 (file)
@@ -36,14 +36,14 @@ static bool check_client_passwd(PgSocket *client, const char *passwd)
        case AUTH_PLAIN:
                return strcmp(user->passwd, passwd) == 0;
        case AUTH_CRYPT:
-               correct = crypt(user->passwd, (char *)client->salt);
+               correct = crypt(user->passwd, (char *)client->tmp_login_salt);
                return strcmp(correct, passwd) == 0;
        case AUTH_MD5:
                if (strlen(passwd) != MD5_PASSWD_LEN)
                        return false;
                if (!isMD5(user->passwd))
                        pg_md5_encrypt(user->passwd, user->name, strlen(user->name), user->passwd);
-               pg_md5_encrypt(user->passwd + 3, client->salt, 4, md5);
+               pg_md5_encrypt(user->passwd + 3, (char *)client->tmp_login_salt, 4, md5);
                return strcmp(md5, passwd) == 0;
        }
        return false;
@@ -168,16 +168,16 @@ static bool send_client_authreq(PgSocket *client)
        if (auth == AUTH_CRYPT) {
                saltlen = 2;
                get_random_bytes(randbuf, saltlen);
-               client->salt[0] = valid_crypt_salt[randbuf[0] & SALT_MASK];
-               client->salt[1] = valid_crypt_salt[randbuf[1] & SALT_MASK];
-               client->salt[2] = 0;
+               client->tmp_login_salt[0] = valid_crypt_salt[randbuf[0] & SALT_MASK];
+               client->tmp_login_salt[1] = valid_crypt_salt[randbuf[1] & SALT_MASK];
+               client->tmp_login_salt[2] = 0;
        } else if (cf_auth_type == AUTH_MD5) {
                saltlen = 4;
-               get_random_bytes((void*)client->salt, saltlen);
+               get_random_bytes((void*)client->tmp_login_salt, saltlen);
        } else if (auth == AUTH_ANY)
                auth = AUTH_TRUST;
 
-       SEND_generic(res, client, 'R', "ib", auth, client->salt, saltlen);
+       SEND_generic(res, client, 'R', "ib", auth, client->tmp_login_salt, saltlen);
        return res;
 }