Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37481192
en ru br
ALT Linux repos
S:0.1-alt8
5.0: 0.1-alt8
4.1: 0.2-alt7.M41.1
4.0: 0.2-alt4.M40.2

Group :: Development/Other
RPM: cl-user-tools

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

cl-user-tools-0.1/000075500000000000000000000000001076302264500140655ustar00rootroot00000000000000cl-user-tools-0.1/etc/000075500000000000000000000000001076302264500146405ustar00rootroot00000000000000cl-user-tools-0.1/etc/cl-user.conf000064400000000000000000000001251076302264500170570ustar00rootroot00000000000000host=localhost
base="dc=user,dc=com"
binddn="cn=admin,dc=user,dc=com"
#bindpw=secret
cl-user-tools-0.1/scripts/000075500000000000000000000000001076302264500155545ustar00rootroot00000000000000cl-user-tools-0.1/scripts/cl-getent000075500000000000000000000045151076302264500173710ustar00rootroot00000000000000#!/bin/sh -e

. shell-error
. /etc/cl-user.conf

[ "$#" -eq 1 ] || fatal "more arguments required"
db="$1"; shift

[ -n "$bindpw" ] && bindpw="-w $bindpw" || bindpw="-W"

if [ "$bindpw" = "-W" ]; then
echo -n "Enter LDAP Password: "
read -es passwd
echo
bindpw="-w '$passwd'"
fi

ldap_search_groups()
{
local key
local value
local cn
local gid
local found

ldapsearch -b "$base" -D "$binddn" $bindpw -x -H "ldap://${host:-localhost}" "objectClass=posixGroup" cn gidNumber | \
while read key value; do
if [ "$key" = "dn:" -o "$key" = "result:" ]; then
if [ ! -z "$found" ]; then
[ -n "$cn" -a -n "$gid" ] && echo "$cn:x:$gid:"
cn=
gid=
fi
found=1
fi
[ "$key" = "cn:" ] && cn="$value"
[ "$key" = "gidNumber:" ] && gid="$value"
done
}

ldap_search_group_users()
{
local key
local value
local list
local found
local gid="$1"

ldapsearch -b "$base" -D "$binddn" $bindpw -x -H "ldap://${host:-localhost}" "(&(objectClass=posixGroup)(gidNumber=$gid))" memberUid | \
while read key value; do
if [ "$key" = "dn:" -o "$key" = "result:" ]; then
if [ ! -z "$found" ]; then
[ -n "$list" ] && echo "$list"
list=
fi
found=1
fi
if [ "$key" = "memberUid:" ]; then
if [ -n "$list" ]; then
list="$list,$value"
else
list="$value"
fi
fi
done
}

ldap_search_users()
{
local key
local value
local cn
local gid
local found

ldapsearch -b "$base" -D "$binddn" $bindpw -x -H "ldap://${host:-localhost}" "objectClass=posixAccount" cn userPassword uidNumber gidNumber homeDirectory loginShell uid | \
while read key value; do
if [ "$key" = "dn:" -o "$key" = "result:" ]; then
if [ ! -z "$found" ]; then
echo "$userid:x:$uid:$gid:$cn:$home:$shell"
userid=
uid=
gid=
cn=
home=
shell=
fi
found=1
fi
[ "$key" = "uid:" ] && userid="$value"
[ "$key" = "uidNumber:" ] && uid="$value"
[ "$key" = "gidNumber:" ] && gid="$value"
[ "$key" = "cn:" ] && cn="$value"
[ "$key" = "homeDirectory:" ] && home="$value"
[ "$key" = "loginShell:" ] && shell="$value"
done
}

case "$db" in
"group")
ldap_search_groups | \
while IFS=: read cn x gid tail; do
echo -n "$cn:$x:$gid:"
users="$(ldap_search_group_users $gid)"
echo "$users"
done
break;;
"passwd")
ldap_search_users
break;;
esac

cl-user-tools-0.1/scripts/cl-groupadd000075500000000000000000000015601076302264500177050ustar00rootroot00000000000000#!/bin/sh -e

. shell-error
. /etc/cl-user.conf

[ "$#" -eq 1 ] || fatal "more arguments required"
group="$1"; shift

[ -n "$bindpw" ] && bindpw="-w $bindpw" || bindpw="-W"

#check for name
getent group "$group" && fatal "same name already exists"

#calculate gid
gid_avail="$(getent group| cut -f3 -d: |sort -unr|head -n1)"
gid_min="${gid_min:-$(sed -rn 's,^GID_MIN[[:space:]]+([^[:space:]]+),\1,p' /etc/login.defs)}"
gid_max="${gid_max:-$(sed -rn 's,^GID_MAX[[:space:]]+([^[:space:]]+),\1,p' /etc/login.defs)}"

gid=$(( $gid_avail + 1 ))

[ "$gid" -le "$gid_max" ] || fatal "not free gid available"
[ "$gid" -lt "$gid_min" ] && gid="$gid_min"

message "using gid - $gid"

#edit ldap
ldapadd -a -D "$binddn" $bindpw -x -H "ldap://${host:-localhost}"<<EOF
dn: cn=$group,ou=Group,$base
objectClass: posixGroup
objectClass: top
cn: $group
userPassword: {crypt}x
gidNumber: $gid
EOF
cl-user-tools-0.1/scripts/cl-groupdel000075500000000000000000000006601076302264500177210ustar00rootroot00000000000000#!/bin/sh -e

. shell-error
. /etc/cl-user.conf

[ "$#" -eq 1 ] || fatal "more arguments required"
group="$1"; shift

[ -n "$bindpw" ] && bindpw="-w $bindpw" || bindpw="-W"

gid="$(getent group "$group"|cut -f3 -d:)"

message "group's gid - $gid"

getent passwd|cut -f4 -d:|fgrep -xqs "$gid" && fatal "cannot remove user's primary group"

ldapdelete -D "$binddn" $bindpw -x -H "ldap://${host:-localhost}" "cn=$group,ou=Group,$base"
cl-user-tools-0.1/scripts/cl-init000075500000000000000000000007451076302264500170470ustar00rootroot00000000000000#!/bin/sh -e

. /etc/cl-user.conf

[ -n "$bindpw" ] && bindpw="-w $bindpw" || bindpw="-W"

ldapadd -a -D "$binddn" $bindpw -x -H "ldap://${host:-localhost}"<<EOF
dn: $base
objectClass: organization
objectClass: dcObject
$(printf %s\\n "$base" |
tr -s '[:space:],' '\n' |
sed -r -n -e '1 { s/dc=[[:space:]]*/dc: /p }' -e '$ { s/dc=[[:space:]]*/o: /p }')

dn: ou=People,$base
objectClass: organizationalUnit
ou: People

dn: ou=Group,$base
objectClass: organizationalUnit
ou: Group
EOF
cl-user-tools-0.1/scripts/cl-passwd000075500000000000000000000012141076302264500173750ustar00rootroot00000000000000#!/bin/sh -e

. shell-error
. /etc/cl-user.conf

[ "$#" -eq 1 ] || fatal "more arguments required"
user="$1"; shift

[ -n "$bindpw" ] && bindpw="-w $bindpw" || bindpw="-W"

pw="$(slappasswd -h '{CRYPT}')"

[ -n "$pw" ] || fatal "No password given"

uid="$(getent passwd "$user"|cut -f3 -d:)"
gid="$(getent passwd "$user"|cut -f4 -d:)"
home="$(getent passwd "$user"|cut -f6 -d:)"

#edit ldap
ldapmodify -D "$binddn" $bindpw -x -H "ldap://${host:-localhost}"<<EOF
dn: uid=$user,ou=People,$base
uid: $user
cn: $user
objectClass: account
objectClass: posixAccount
objectClass: top
userPassword: $pw
uidNumber: $uid
gidNumber: $gid
homeDirectory: $home
EOF
cl-user-tools-0.1/scripts/cl-sshkeygen000075500000000000000000000006771076302264500201100ustar00rootroot00000000000000#!/bin/sh -e

. shell-error

[ "$#" -eq 1 ] || fatal "more arguments required"
user="$1"; shift

uid="$(getent passwd "$user"|cut -f3 -d:)"

[ -n "$uid" ] || fatal "user not found in database"
[ -d "/home/$user" ] || fatal "home directory doesn't exists"

message "using uid - $uid"

su -l "$user" -c "ssh-keygen -t dsa -b 1024 -f /home/$user/.ssh/id_dsa -N \"\""
su -l "$user" -c "cp /home/$user/.ssh/id_dsa.pub /home/$user/.ssh/authorized_keys"
cl-user-tools-0.1/scripts/cl-useradd000075500000000000000000000024621076302264500175310ustar00rootroot00000000000000#!/bin/sh -e

. shell-error
. /etc/cl-user.conf

[ "$#" -eq 1 ] || fatal "more arguments required"
user="$1"; shift

[ -n "$bindpw" ] && bindpw="-w $bindpw" || bindpw="-W"

#check for name
getent passwd "$user" && fatal "same name already exists"

#calculate uid
uid_avail="$(getent passwd| cut -f3 -d: |sort -unr|head -n1)"
uid_min="${uid_min:-$(sed -rn 's,^UID_MIN[[:space:]]+([^[:space:]]+),\1,p' /etc/login.defs)}"
uid_max="${uid_max:-$(sed -rn 's,^UID_MAX[[:space:]]+([^[:space:]]+),\1,p' /etc/login.defs)}"

uid=$(( $uid_avail + 1 ))

[ "$uid" -le "$uid_max" ] || fatal "not free uid available"
[ "$uid" -lt "$uid_min" ] && uid="$uid_min"

message "using uid - $uid"

#add group and calculate gid
getent group "$user" && fatal "same name in group database already exists"
cl-groupadd "$user"
gid="$(getent group "$user"|cut -f3 -d:)"

message "using gid - $gid"

#edit ldap
ldapadd -a -D "$binddn" $bindpw -x -H "ldap://${host:-localhost}"<<EOF
dn: uid=$user,ou=People,$base
uid: $user
cn: $user
objectClass: account
objectClass: posixAccount
objectClass: top
loginShell: /bin/bash
userPassword: {crypt}x
uidNumber: $uid
gidNumber: $gid
homeDirectory: /home/$user
EOF

if [ -d "/home/$user" ]; then
message "home directory already exists"
else
cp -r /etc/skel "/home/$user"
chown -R "$uid:$gid" "/home/$user"
fi
cl-user-tools-0.1/scripts/cl-userdel000075500000000000000000000004641076302264500175450ustar00rootroot00000000000000#!/bin/sh -e

. shell-error
. /etc/cl-user.conf

[ "$#" -eq 1 ] || fatal "more arguments required"
user="$1"; shift

[ -n "$bindpw" ] && bindpw="-w $bindpw" || bindpw="-W"

ldapdelete -D "$binddn" $bindpw -x -H "ldap://${host:-localhost}" "uid=$user,ou=People,$base"
cl-groupdel "$user"
rm -rf "/home/$user"
cl-user-tools-0.1/scripts/cl-usermod000075500000000000000000000005111076302264500175510ustar00rootroot00000000000000#!/bin/sh -e

. shell-error
. /etc/cl-user.conf

[ "$#" -eq 1 ] || fatal "more arguments required"
user="$1"; shift

[ -n "$bindpw" ] && bindpw="-w $bindpw" || bindpw="-W"

#edit ldap
(echo "dn: uid=$user,ou=People,$base"
while read line; do
echo $line
done ) |
ldapmodify -D "$binddn" $bindpw -x -H "ldap://${host:-localhost}"
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin