我正在尝试将用户添加到 Berkeley db 数据库中以进行 vsftpd 的 PAM 身份验证。该数据库最初是由 db_load 实用程序从用户名和密码的文本文件创建的。
db_load -T -t hash -f vusers.txt vsftpd-virtual-user.db
这些用户的 PAM 身份验证工作正常。我编写了将用户添加到该数据库的 c++ 应用程序。
int ret = -1;
char *description = "user5";
char *pass = "password5";
// Database open omitted for clarity
Dbt data(pass, strlen(pass) + 1);
Dbt key(description, strlen(description) + 1);
ret = db.put(NULL, &key, &data, DB_NOOVERWRITE);
操作成功通过,但 PAM 无法识别新添加的用户。我检查了数据库的内容,发现最初添加的数据与我的应用程序添加的数据不同:它包含一些在用户名和密码后面尾随的二进制数据。PAM db 数据格式是什么?如何解决问题?
这是添加新主菜之前的 db_dump 输出
bash-4.2$ db_dump -d a /etc/vsftpd_virtual-users.db
In-memory DB structure:
hash: 0x90000 (open called, read-only)
meta_pgno: 0
h_ffactor: 0
h_nelem: 2
h_hash: 0xb770bb00
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
page 0: hash metadata: LSN [0][1]: level 0
magic: 0x61561
version: 9
pagesize: 4096
type: 8
metaflags 0
keys: 0 records: 0
free list: 0
last_pgno: 2
flags: 0
uid: d 0 8e 0 7 8 0 0 9d 2b 10 be 8a 11 0 0 0 0 0 0
max_bucket: 1
high_mask: 0x1
low_mask: 0
ffactor: 0
nelem: 2
h_charkey: 0x5e688dd1
spare points: 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
page 1: hash: LSN [0][1]: level 0
prev: 0 next: 0 entries: 2 offset: 4085
[000] 4091 len: 4 data: usr2
[001] 4085 len: 5 data: pass2
page 2: hash: LSN [0][1]: level 0
prev: 0 next: 0 entries: 2 offset: 4085
[000] 4091 len: 4 data: usr1
[001] 4085 len: 5 data: pass1
在添加了“user5”和“pass5”的新主菜之后
bash-4.2$ db_dump -d a 1vsftpd_virtual-users.db
In-memory DB structure:
hash: 0x90000 (open called, read-only)
meta_pgno: 0
h_ffactor: 0
h_nelem: 3
h_hash: 0xb7675b00
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
page 0: hash metadata: LSN [0][1]: level 0
magic: 0x61561
version: 9
pagesize: 4096
type: 8
metaflags 0
keys: 0 records: 0
free list: 0
last_pgno: 2
flags: 0
uid: d 0 8e 0 7 8 0 0 9d 2b 10 be 8a 11 0 0 0 0 0 0
max_bucket: 1
high_mask: 0x1
low_mask: 0
ffactor: 0
nelem: 3
h_charkey: 0x5e688dd1
spare points: 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
page 1: hash: LSN [0][1]: level 0
prev: 0 next: 0 entries: 2 offset: 4085
[000] 4091 len: 4 data: usr2
[001] 4085 len: 5 data: pass2
page 2: hash: LSN [0][1]: level 0
prev: 0 next: 0 entries: 4 offset: 4072
[000] 4091 len: 4 data: usr1
[001] 4085 len: 5 data: pass1
[002] 4079 len: 5 data: 0x750x730x720x3500
[003] 4072 len: 6 data: 0x700x610x730x730x3500