Automatic mapping between LDAP users and local users

Post here if you have some suggestions or you want to request a new feature.
Post Reply
fred9176
Posts: 23
Joined: Mon Jul 02, 2012 9:29 am

Automatic mapping between LDAP users and local users

Post by fred9176 »

Hello,

Would it be possible to add an automatic mapping between ldap accounts and local accounts ?

Actually, we have to create a local user for each ldap user with a different name and map every user in the authentication ldap tab.

We could use a specific prefix or suffix to automaticcaly map users.
For example, if my ldap user is j.doe, we could create a local user called j.doe-local (or ldap_j.doe, ...) and WingFTp should automaticaly know that the 2 users are linked.

Regards,

Fred
FTP
Site Admin
Posts: 1917
Joined: Tue Sep 29, 2009 6:09 am

Re: Automatic mapping between LDAP users and local users

Post by FTP »

OK, I will give you a Lua script for creating a local user and adding AD-to-Local mapping automatically,

You can add the following script into "Event Manager -> FTP Events (HTTP Events and SSH Events) -> OnUserLoggedIn -> Lua Script":

Code: Select all

local strDomain = "%Domain"
local strRootDir = "c:/temp"
local strADUser = "%Name"
local strLocalUser = "local_".."%Name"
local strMapping = c_GetOptionStr(strDomain,DOPTION_ADUSER_MAPPING_STR)

if not string.find(strMapping, "%Name"..":", 0, true) then
	if c_UserExist(strDomain,strLocalUser) == false then
		local strPassword = md5( (c_GetTimeUS() + c_GetRandom())..c_GetServerID().."mypassword" )
		c_AddUser(strDomain,strLocalUser, strPassword, 63, 1, 1)
		c_AddUserDirectory(strDomain,strLocalUser, strRootDir.."/"..strADUser, "/", true, true, true, true, true, true, false, false, false, true, false, false)
		c_MkDir(strRootDir.."/"..strADUser)
	end
	c_SetOptionStr(strDomain,DOPTION_ADUSER_MAPPING_STR,strMapping.."\r\n"..strADUser..":"..strLocalUser)
end
WebFTP
Posts: 3
Joined: Tue Dec 13, 2016 5:53 pm

Re: Automatic mapping between LDAP users and local users

Post by WebFTP »

Hello,

Which option should I use instead of DOPTION_ADUSER_MAPPING_STR in the string c_SetOptionStr (strDomain, ...) when I use the LDAP connector?

Regards,
Andreas
FTP
Site Admin
Posts: 1917
Joined: Tue Sep 29, 2009 6:09 am

Re: Automatic mapping between LDAP users and local users

Post by FTP »

OK, it should be "DOPTION_LDAP_MAPPING_STR". You can check out all the key strings under "lua/ServerInterface.lua".
WebFTP
Posts: 3
Joined: Tue Dec 13, 2016 5:53 pm

Re: Automatic mapping between LDAP users and local users

Post by WebFTP »

Hello

At the moment, I am adjusting the script so that there is no automatic mapping for existing local users. Unfortunately my change does not work as desired. Can you help me?

Code: Select all

local strDomain = "%Domain"
local strRootDir = "c:/temp"
local strADUser = "%Name"
local strLocalUser = "%Name".."_local"
local strMapping = c_GetOptionStr(strDomain,DOPTION_LDAP_MAPPING_STR)

if c_UserExist(strDomain,strADUser) == false then
	if not string.find(strMapping, "%Name"..":") then
		if c_UserExist(strDomain,strLocalUser) == false then
			local strPassword = md5( (c_GetTimeUS() + c_GetRandom())..c_GetServerID().."mypassword" )
			c_AddUser(strDomain,strLocalUser, strPassword, 63, 1, 1)
			c_AddUserDirectory(strDomain,strLocalUser, strRootDir.."/"..strADUser, "/", true, true, true, true, true, true, false, false, false, true, false, false)
			c_MkDir(strRootDir.."/"..strADUser)
		end
		c_SetOptionStr(strDomain,DOPTION_LDAP_MAPPING_STR,strMapping.."\r\n"..strADUser..":"..strLocalUser)
	end
end
WebFTP
Posts: 3
Joined: Tue Dec 13, 2016 5:53 pm

Re: Automatic mapping between LDAP users and local users

Post by WebFTP »

Can you help me with my problem?
The condition "if c_UserExist (strDomain, strADUser) == false then" does not work properly!

Regards,
Andreas
FTP
Site Admin
Posts: 1917
Joined: Tue Sep 29, 2009 6:09 am

Re: Automatic mapping between LDAP users and local users

Post by FTP »

It means the local user "%Name" already exists, anyway, you can print that username in the server logs:

Code: Select all

c_AddSystemLog("Username: %Name", 0)
Post Reply