ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm quite noob in ruby, but I've managed to understand the code, but here is something that also couldn't find explain well:
read file => Loop through user array => if file_line match user1 or user2 or userN [ ldap_filter_users =(|(user1)(user2)(userN))] => delete that line from file ...
I'm quite noob in ruby, but I've managed to understand the code, but here is something that also couldn't find explain well:
read file => Loop through user array => if file_line match user1 or user2 or userN [ ldap_filter_users =(|(user1)(user2)(userN))] => delete that line from file ...
Sorry I didn't comment it, but it seems like you understand the logic. What are you confused about?
#line1
#line2
[ldap_settings]
ldap_filters = yes
ldap_filter_users = should be added right here
[ad_settings]
#line1
#line2
[kerberos_settings]
#line1
#line2
1st case : users = %w/user1/
ldap_filter_users = (user1) =>this is the easiest case
if users.size == 1
$_var = "(uid=#{users[0]})"
else
users.each.with_index do |x, index|
if index == 0
$_var = "(|(uid=#{x})"
elsif index == users.size - 1
$_var << "(uid=#{x}))"
else
$_var << "(uid=#{x})"
end
end
end
#line1
#line2
[ldap_settings]
ldap_filters = yes
ldap_filter_users = should be added right here
[ad_settings]
#line1
#line2
[kerberos_settings]
#line1
#line2
1st case : users = %w/user1/
ldap_filter_users = (user1) =>this is the easiest case
if users.size == 1
$_var = "(uid=#{users[0]})"
else
users.each.with_index do |x, index|
if index == 0
$_var = "(|(uid=#{x})"
elsif index == users.size - 1
$_var << "(uid=#{x}))"
else
$_var << "(uid=#{x})"
end
end
end
Have a better method then this?
Since you need the line to be at a certain position, you'll have a much easier time reading each line from the file and filtering it that way. Here is an example in pseudo-code:
Code:
for line in file
if all users in the user array are not in line
if "ldap_filters = yes" in line
write "ldap_filter_users = yes"
write "ldap_filter_users = (|(user1)(user2)(userN))"
else
write line
For your other problem, which seems to be constructing the users line, something like this will work:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.