feat: added override to ensure that admins have user perms
This commit is contained in:
parent
dc7139a86f
commit
ff282e823b
1 changed files with 21 additions and 7 deletions
|
@ -39,12 +39,13 @@ fn uid_to_dn(uid: &str) -> String{
|
||||||
|
|
||||||
async fn update_admin(config: &Config) -> tide::Result<()>{
|
async fn update_admin(config: &Config) -> tide::Result<()>{
|
||||||
let users = vec!["silver", "evanc", "eoghanconlon73"];
|
let users = vec!["silver", "evanc", "eoghanconlon73"];
|
||||||
update_group(config,"skynet-admins", &users).await?;
|
update_group(config,"skynet-admins", &users, true).await?;
|
||||||
|
// admins automatically get added as users
|
||||||
|
update_group(config,"skynet-users", &users, false).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_group(config: &Config, group: &str, users: &Vec<&str>) -> tide::Result<()>{
|
async fn update_group(config: &Config, group: &str, users: &Vec<&str>, replace: bool) -> tide::Result<()>{
|
||||||
let mut ldap = LdapConn::new(&config.ldap_host)?;
|
let mut ldap = LdapConn::new(&config.ldap_host)?;
|
||||||
|
|
||||||
// use the admin account
|
// use the admin account
|
||||||
|
@ -52,13 +53,26 @@ async fn update_group(config: &Config, group: &str, users: &Vec<&str>) -> tide::
|
||||||
|
|
||||||
let dn_skynet_admins = format!("cn={},ou=groups,dc=skynet,dc=ie", group);
|
let dn_skynet_admins = format!("cn={},ou=groups,dc=skynet,dc=ie", group);
|
||||||
let skynet_admins = users.clone().into_iter().map(|uid| uid_to_dn(uid)).collect();
|
let skynet_admins = users.clone().into_iter().map(|uid| uid_to_dn(uid)).collect();
|
||||||
let mods = vec![Mod::Replace("member".to_string(), skynet_admins)];
|
let mods = if replace {
|
||||||
ldap.modify(&dn_skynet_admins, mods)?.success()?;
|
vec![Mod::Replace("member".to_string(), skynet_admins)]
|
||||||
|
} else {
|
||||||
|
vec![Mod::Add("member".to_string(), skynet_admins)]
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(x) = ldap.modify(&dn_skynet_admins, mods) {
|
||||||
|
println!("{:?}", x);
|
||||||
|
}
|
||||||
|
|
||||||
let dn_skynet_admins_linux = format!("cn={}-linux,ou=groups,dc=skynet,dc=ie", group);
|
let dn_skynet_admins_linux = format!("cn={}-linux,ou=groups,dc=skynet,dc=ie", group);
|
||||||
let skynet_admins_linux = users.clone().into_iter().map(|uid| uid.to_string()).collect();
|
let skynet_admins_linux = users.clone().into_iter().map(|uid| uid.to_string()).collect();
|
||||||
let mods = vec![Mod::Replace("memberUid".to_string(), skynet_admins_linux)];
|
let mods = if replace {
|
||||||
ldap.modify(&dn_skynet_admins_linux, mods)?.success()?;
|
vec![Mod::Replace("memberUid".to_string(), skynet_admins_linux)]
|
||||||
|
} else {
|
||||||
|
vec![Mod::Add("memberUid".to_string(), skynet_admins_linux)]
|
||||||
|
};
|
||||||
|
if let Err(x) = ldap.modify(&dn_skynet_admins_linux, mods){
|
||||||
|
println!("{:?}", x);
|
||||||
|
};
|
||||||
|
|
||||||
ldap.unbind()?;
|
ldap.unbind()?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue