1. 程式人生 > >openldap 批量增加或修改屬性

openldap 批量增加或修改屬性

1. 把excel表匯入資料庫再程式設計生成或直接生成需要修改的ldif格式檔案,命名為modify.ldif

檔案內容格式如下:

dn: uid=20180103,ou=201801,ou=2018,ou=student,ou=people,dc=linbsoft,dc=com
changetype: modify
add: mobile
mobile: 13812345678
【空行】
dn: uid=20180104,ou=201801,ou=2018,ou=student,ou=people,dc=linbsoft,dc=com
changetype: modify
replace: mobile
mobile: 13912345678
【空行】
.....

其中 add是增加屬性,replace是修改已存在屬性

2. 把檔案上載到linux伺服器

3.執行bash命令

#ldapmodify -x -D "cn=admin,dc=linbsoft,dc=com" -W -f modify.ldif

該命令會提示輸入openldap管理員賬號admin的密碼,然後執行修改openldap屬性的操作,注意如果其中某個屬性修改出錯,會中斷執行,造成部分後面的修改操作沒有完成。

4.如果匯入照片,可以使用如下語法

jpegPhoto: < file:///stuphoto/2018/201801/20180103.jpg

5.以下是把excel匯入到mssql後,vb.net生成ldif的程式

        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
            Dim mydbObject As DBObject = New DBObject
            Dim bh As String = TextBox1.Text.Trim
            Dim nj As String = Left(bh, 4)

            Dim sqlstr As String = "select xh,mobile  from mobile" + nj + " where bj='" + bh + "'"
            Dim set1 As DataSet = mydbObject.ExecuteSql(sqlstr, "t1")
            Dim drow As DataRow
            Dim xh As String
            Dim mobile As String
            TextBox2.Text = ""
            TextBox2.Text += Chr(10)
            For Each drow In set1.Tables(0).Rows
                xh = drow("xh").ToString.Trim
                mobile = drow("mobile").ToString.Trim
                If mobile.Length > 7 Then
                    TextBox2.Text += Chr(10)
                    TextBox2.Text += "dn: uid=" + xh + ",ou=" + bh + ",ou=" + nj + ",ou=student,ou=people,dc=linbsoft,dc=com" + Chr(10)
                    TextBox2.Text += "changetype: modify" + Chr(10)
                    TextBox2.Text += "add: mobile" + Chr(10)
                    TextBox2.Text += "mobile: " + mobile + Chr(10)
                End If
            Next
        End Sub