Skip to content

Commit f2bba36

Browse files
author
pptfz
committed
更新ldap笔记
1 parent aa6410d commit f2bba36

10 files changed

Lines changed: 186 additions & 0 deletions

File tree

docs/Linux/Linux服务/ldap/Self Service Password.md renamed to docs/Linux/Linux服务/ldap/Self Service Password/Self Service Password.md

File renamed without changes.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Self Service Password修改密码报错
2+
3+
## 报错信息
4+
5+
用户修改密码,页面报错 `密码被 LDAP 目录服务拒绝` ,日志报错如下
6+
7+
```php
8+
[Mon Sep 08 06:07:25.578613 2025] [php:notice] [pid 19:tid 19] [client 12.12.13.19:21786] LDAP - Modify password error 50 (Insufficient access), referer: https://ssp.xxx.com/index.php
9+
```
10+
11+
![iShot_2025-09-05_15.04.06](https://raw.githubusercontent.com/pptfz/picgo-images/master/img/iShot_2025-09-05_15.04.06.png)
12+
13+
14+
15+
16+
17+
## 解决方法
18+
19+
### 查看acl
20+
21+
:::tip 说明
22+
23+
```shell
24+
$ ldapsearch -H ldapi:/// -Y EXTERNAL -b "olcDatabase={2}mdb,cn=config" olcAccess
25+
26+
SASL/EXTERNAL authentication started
27+
SASL username: gidNumber=0+uidNumber=1001,cn=peercred,cn=external,cn=auth
28+
SASL SSF: 0
29+
# extended LDIF
30+
#
31+
# LDAPv3
32+
# base <olcDatabase={2}mdb,cn=config> with scope subtree
33+
# filter: (objectclass=*)
34+
# requesting: olcAccess
35+
#
36+
37+
# {2}mdb, config
38+
dn: olcDatabase={2}mdb,cn=config
39+
40+
# search result
41+
search: 2
42+
result: 0 Success
43+
44+
# numResponses: 2
45+
# numEntries: 1
46+
```
47+
48+
49+
50+
51+
52+
编辑文件
53+
54+
```
55+
cat > add-acl.ldif << EOF
56+
dn: olcDatabase={2}mdb,cn=config
57+
changetype: modify
58+
add: olcAccess
59+
olcAccess: to attrs=userPassword
60+
by self write
61+
by anonymous auth
62+
by * none
63+
EOF
64+
```
65+
66+
67+
68+
执行
69+
70+
```shell
71+
ldapmodify -H ldapi:/// -Y EXTERNAL -f add-acl.ldif
72+
```
73+
74+
输出
75+
76+
```shell
77+
SASL/EXTERNAL authentication started
78+
SASL username: gidNumber=0+uidNumber=1001,cn=peercred,cn=external,cn=auth
79+
SASL SSF: 0
80+
modifying entry "olcDatabase={2}mdb,cn=config"
81+
```
82+
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# ldap批量创建用户
2+
3+
4+
5+
编辑用户文件
6+
7+
```
8+
cat > users.txt << EOF
9+
zhuzhisheng
10+
libin
11+
lichao
12+
lianglikai
13+
songtingsen
14+
wangjun
15+
wanglin
16+
wangpengfei
17+
yanxin
18+
zhangjintao
19+
zhangxing
20+
zhangzhenbiao
21+
zhaoxiaofei
22+
zhaoyulong
23+
EOF
24+
```
25+
26+
27+
28+
批量增加用户
29+
30+
```shell
31+
cat > add-users.sh << 'AAA'
32+
#!/bin/bash
33+
34+
BASE_DN="cn=后端组,ou=kingclub,dc=zmexing,dc=com"
35+
GROUP_GID=1000
36+
PASSWORD="{SSHA}G7h4TMhnEuc1iR5pR/E7E9WPQ7rW23UJ"
37+
DOMAIN="zmexing.com"
38+
39+
UID_START=1001
40+
41+
while read -r USERNAME
42+
do
43+
EMAIL="${USERNAME}@${DOMAIN}"
44+
UID=$UID_START
45+
46+
cat <<EOF | ldapadd -x -H ldap://localhost:1389 -D "cn=admin,dc=zmexing,dc=com" -w 'NgIZnm#b%6PI'
47+
dn: uid=${USERNAME},${BASE_DN}
48+
objectClass: inetOrgPerson
49+
objectClass: posixAccount
50+
objectClass: top
51+
cn: ${USERNAME}
52+
sn: ${USERNAME}
53+
uid: ${USERNAME}
54+
uidNumber: ${UID}
55+
gidNumber: ${GROUP_GID}
56+
homeDirectory: /home/${USERNAME}
57+
loginShell: /bin/bash
58+
mail: ${EMAIL}
59+
userPassword: ${PASSWORD}
60+
EOF
61+
62+
UID_START=$((UID_START+1))
63+
64+
done < users.txt
65+
AAA
66+
```
67+
68+
69+
70+
批量删除用户
71+
72+
```shell
73+
cat > del-users.sh << 'EOF'
74+
#!/bin/bash
75+
76+
BASE_DN="cn=后端组,ou=kingclub,dc=zmexing,dc=com"
77+
78+
while read -r USERNAME
79+
do
80+
DN="uid=${USERNAME},${BASE_DN}"
81+
82+
echo "Deleting ${DN} ..."
83+
ldapdelete -x -H ldap://localhost:1389 -D "cn=admin,dc=zmexing,dc=com" -w 'NgIZnm#b%6PI' "${DN}"
84+
85+
done < users.txt
86+
EOF
87+
```
88+
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# yearning对接ldap
2+
3+
4+
5+
`LDAP_Search filter` 要写成如下
6+
7+
```shell
8+
(&(objectClass=organizationalPerson)(uid=%s))
9+
```
10+
11+
12+
13+
![iShot_2025-09-08_16.19.51](https://raw.githubusercontent.com/pptfz/picgo-images/master/img/iShot_2025-09-08_16.19.51.png)
14+
15+
16+

0 commit comments

Comments
 (0)