usermngr: daemonization

This commit is contained in:
Suvendhu Hansa 2024-11-19 13:14:38 +00:00 committed by IOPSYS Dev
parent 8c7f2bc2bd
commit 40bd23290f
No known key found for this signature in database
3 changed files with 20 additions and 142 deletions

View file

@ -5,13 +5,13 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=usermngr
PKG_VERSION:=1.2.19
PKG_VERSION:=1.3.0
LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/usermngr.git
PKG_SOURCE_VERSION:=99bf586d4facbf10239acf013f5c235b41fdcb5b
PKG_SOURCE_VERSION:=12e73f9f0717128add0fc1fba9c1b3ac4dbd0a6c
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
endif
@ -20,7 +20,6 @@ PKG_LICENSE:=BSD-3-Clause
PKG_LICENSE_FILES:=LICENSE
include $(INCLUDE_DIR)/package.mk
include ../bbfdm/bbfdm.mk
MAKE_PATH:=src
@ -28,8 +27,8 @@ define Package/usermngr
SECTION:=utils
CATEGORY:=Utilities
SUBMENU:=TRx69
DEPENDS:= +shadow-utils +libopenssl
DEPENDS+=+libbbfdm-api +libbbfdm-ubus +dm-service
DEPENDS:= +shadow-utils +libopenssl +libuci +libubox +ubus
DEPENDS+=+libbbfdm-api +libbbfdm-ubus +bbfdmd
TITLE:=Package to add Device.Users. datamodel support
endef
@ -48,11 +47,11 @@ define Package/usermngr/install
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_DIR) $(1)/etc/users/roles
$(INSTALL_BIN) ./files/etc/uci-defaults/90-indicate-bootstrap $(1)/etc/uci-defaults/90-indicate-bootstrap
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) ./files/etc/uci-defaults/91-sync-shells $(1)/etc/uci-defaults/91-sync-shells
$(INSTALL_BIN) ./files/etc/init.d/users $(1)/etc/init.d/users
$(INSTALL_BIN) ./files/etc/config/users $(1)/etc/config/users
$(BBFDM_INSTALL_MS_DM) $(PKG_BUILD_DIR)/src/libusermngr.so $(1) $(PKG_NAME)
$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/usermngr $(1)/usr/sbin/usermngr
endef
$(eval $(call BuildPackage,usermngr))

View file

@ -4,141 +4,25 @@ START=11
STOP=90
USE_PROCD=1
create_group() {
local group="$1"
local enabled deleted old_name
config_get enabled "$group" enabled ""
config_get deleted "$group" deleted ""
config_get old_name "$group" old_name ""
groupname=${group#*_}
if [ "$deleted" = "1" ]; then
groupdel -f "$groupname"
uci -q delete users."$group"
return 0
fi
if [ -n "$old_name" ]; then
del_group=${old_name#*_}
grep -rq "^$del_group:" /etc/group
if [ "$?" = "0" ]; then
groupdel -f "$del_group"
fi
uci -q delete users."$group".old_name
fi
if [ "$enabled" = "1" ]; then
grep -rq "^$groupname:" /etc/group
if [ "$?" = "1" ]; then
groupadd -f "$groupname"
fi
else
grep -rq "^$groupname:" /etc/group
if [ "$?" = "0" ]; then
groupdel -f "$groupname"
fi
fi
}
create_user() {
local user="$1"
local enabled password member_groups shell old_name deleted encrypted_password
config_get password "$user" password ""
config_get enabled "$user" enabled ""
config_get old_name "$user" old_name ""
config_get member_groups "$user" member_groups ""
config_get shell "$user" shell ""
config_get deleted "$user" deleted ""
config_get encrypted_password "$user" encrypted_password ""
if [ "$deleted" = "1" ]; then
userdel -f "$user"
uci -q delete users."$user"
return 0
fi
if [ -n "$old_name" ]; then
cat /etc/passwd | cut -d: -f1 | grep -qE "^$old_name$"
if [ "$?" = "0" ]; then
usermod -b -l "$user" "$old_name"
fi
uci -q delete users."$user".old_name
fi
grep -rq "^$user:" /etc/passwd
if [ "$?" = "1" ]; then
adduser -D -H -s /bin/false "$user"
fi
# set password
if [ -n "$password" ]; then
echo "$user:$password" | chpasswd
uci -q delete users."$user".password
fi
# set encrypted_password
if [ -n "$encrypted_password" ]; then
str=$(ubus call bbf.secure decode "{'data':'$encrypted_password'}" |jsonfilter -e @.value)
if [ -n "$str" ]; then
echo "$user:$str" | chpasswd
fi
fi
# set shell
usermod -s /bin/false "$user"
if [ -n "$shell" ] && [ "$shell" != "false" ]; then
shellname=$(cat /etc/shells | grep -r "/$shell$")
if [ -n "$shellname" ]; then
shell_sec=""
shell_en=""
uci_param=$(uci -q show users | grep -E "^users\.@shell\[[0-9]+\]\.name=\'$shell\'$")
if [ -n "$uci_param" ]; then
shell_sec=$(echo "$uci_param" | cut -d= -f1 | cut -d. -f2)
fi
if [ -n "$shell_sec" ]; then
shell_en=$(uci -q get users."$shell_sec".enabled)
fi
if [ "$shell_en" = "1" ]; then
usermod -s "$shellname" "$user"
fi
fi
fi
# add groups
usermod -G "" "$user"
if [ -n "$member_groups" ]; then
for i in ${member_groups//,/ }
do
group=${i#*_}
grep -rq "^$group:" /etc/group
if [ "$?" = "0" ]; then
usermod -aG "$group" "$user"
fi
done
fi
if [ "$enabled" = "1" ]; then
usermod -U "$user"
else
usermod -L "$user"
fi
}
PROG=/usr/sbin/usermngr
start_service() {
config_load users
# creation of non-static groups and users
config_foreach create_group group
config_foreach create_user user
uci commit users
procd_open_instance usermngr_dm
procd_set_param command $PROG
procd_set_param respawn
procd_close_instance
}
reload_service() {
stop
start
ret=$(ubus call service list '{"name":"users"}' | jsonfilter -qe '@.users.instances.usermngr_dm.running')
if [ "$ret" != "true" ]; then
stop
start
else
ubus send usermngr.reload
fi
return 0
}
service_triggers()

View file

@ -1,5 +0,0 @@
#!/bin/sh
touch /var/run/user_bootstrap
touch /var/run/group_bootstrap
touch /var/run/role_bootstrap