postgresql – 使用密码salt的Pure-ftpd和Postgreql Auth
我最近开始设置PureFTP服务器的任务.在工作中我们使用
Postgresql 8.4.架构基本上归结为,
username text password character(40) password_salt text 密码存储为sha1(密码盐)的哈希值.使用Postgresql的pgcrypto我可以提供用户名和密码,并找出用户是否有auth: SELECT encode( digest( $password ||password_salt,'sha1' ),'hex' ) = password AS password_correct,username,password,password_salt FROM contact.person; 现在我遇到的问题是这样的功能需要我将密码输入查询. Pureftp目前的auth-postgresql实现似乎不太可行.它仅支持提供: L is replaced by the login of a user trying to authenticate. I is replaced by the IP address the client connected to. P is replaced by the port number the client connected to. R is replaced by the remote IP address the client connected from. D is replaced by the remote IPv4 address,as a long decimal number. 还有其他方法可以做到这一点吗?我要么需要在查询中获取密码,要么取出盐和密码,并找到另一种在Pureftp中编写代码的方法. 显然,我有另外一个写custom authentication module的选项,但我认为pg模块会支持这种基本的salting. 参考 > Pure FTPd’s Postgresql-auth docs 解决方法
我遇到了同样的问题.然而,编写我自己的自定义身份验证模块将是一个过度杀伤,因为可用的pgsql auth几乎可以完成我想要的任何事情.
以下是我为满足我的需求而做出的改变: 在log_pgsql_p.h中添加静态char * salting;和静态char * sqlreq_getsalt;并使用{“PGSQLSalting”,& salting}和{“PGSQLGetSalt”,& sqlreq_getsalt}扩展静态ConfigKeywords pgsql_config_keywords []. 在log_pgsql.h中,我添加了#define SALT_SQL_APPEND“append”,#define SALT_SQL_PREPEND“prepend”和#define SALT_SQL_NONE“none”. 在log_pgsql.c中,我在pw_psql_check函数中进行了以下更改: 我声明了const char * salt = NULL;和char * salted_pa??ssword = NULL;在顶部. 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); } 然后,在加密发生之前: 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); } 然后我在后续调用crypt-methods(crypt,crypto_hash_md5,crypto_hash_sha1)和strcasecmp替换了’cleartext’和(const char *)salted_pa??ssword. 现在剩下要做的就是整理我们分配的内存.特别是带有附加/前置盐的明文密码不应该保留在内存中 – 如果你愿意,可以称之为偏执狂.所以在再见之后:标签添加 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); } 通过这些更改,您现在可以在配置文件中使用两个附加参数: > PGSQLSalting:接受’append'(将盐附加到pw),’prepend’和’none'(没有撇号) 编辑:哦,不要忘记在功能结束时释放分配的内存! 我也可以提供一个适用于1.0.36版本的差异文件.here you go!请注意,我添加了if后面的salted_pa??ssword释放(因为我后来才意识到如果salted_pa??ssword指向密码,这可能会导致错误),所以这不是差异,我懒得改变差异文件:/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |