forked from DragonOS-Community/DragonOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): user management tool (DragonOS-Community#825)
* 用户管理工具 * 重构 * 改为多个bin文件入口 * bin文件的usage显示自身程序名而非固定程序名
- Loading branch information
Showing
29 changed files
with
2,575 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/target | ||
/Cargo.lock | ||
/install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[package] | ||
name = "user_manage_tool" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "useradd" | ||
path = "src/cmd/useradd.rs" | ||
|
||
[[bin]] | ||
name = "userdel" | ||
path = "src/cmd/userdel.rs" | ||
|
||
[[bin]] | ||
name = "usermod" | ||
path = "src/cmd/usermod.rs" | ||
|
||
[[bin]] | ||
name = "passwd" | ||
path = "src/cmd/passwd.rs" | ||
|
||
[[bin]] | ||
name = "groupadd" | ||
path = "src/cmd/groupadd.rs" | ||
|
||
[[bin]] | ||
name = "groupdel" | ||
path = "src/cmd/groupdel.rs" | ||
|
||
[[bin]] | ||
name = "groupmod" | ||
path = "src/cmd/groupmod.rs" | ||
|
||
[dependencies] | ||
libc = "0.2.153" | ||
lazy_static = "1.4.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# The toolchain we use. | ||
# You can get it by running DragonOS' `tools/bootstrap.sh` | ||
TOOLCHAIN="+nightly-2023-08-15-x86_64-unknown-linux-gnu" | ||
RUSTFLAGS+="" | ||
|
||
ifdef DADK_CURRENT_BUILD_DIR | ||
# 如果是在dadk中编译,那么安装到dadk的安装目录中 | ||
INSTALL_DIR = $(DADK_CURRENT_BUILD_DIR) | ||
else | ||
# 如果是在本地编译,那么安装到当前目录下的install目录中 | ||
INSTALL_DIR = ./install | ||
endif | ||
|
||
|
||
ifeq ($(ARCH), x86_64) | ||
export RUST_TARGET=x86_64-unknown-linux-musl | ||
else ifeq ($(ARCH), riscv64) | ||
export RUST_TARGET=riscv64gc-unknown-linux-gnu | ||
else | ||
# 默认为x86_86,用于本地编译 | ||
export RUST_TARGET=x86_64-unknown-linux-musl | ||
endif | ||
|
||
build: | ||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --target $(RUST_TARGET) | ||
|
||
run-dragonreach: | ||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --target $(RUST_TARGET) --bin DragonReach | ||
|
||
clean: | ||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean | ||
|
||
build-release: | ||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --target $(RUST_TARGET) --release | ||
|
||
clean-release: | ||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean --target $(RUST_TARGET) --release | ||
|
||
fmt: | ||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt | ||
|
||
fmt-check: | ||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt --check | ||
|
||
.PHONY: install | ||
install: | ||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) install --target $(RUST_TARGET) --path . --no-track --root $(INSTALL_DIR) --force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
## useradd | ||
|
||
- usage:添加用户 | ||
|
||
> useradd [options] username | ||
useradd -c \<comment\> -d \<home\> -G \<group\> -g \<gid\> -s \<shell\> -u \<uid\> username | ||
|
||
- 参数说明: | ||
|
||
- 选项: | ||
-c comment 指定一段注释性描述 | ||
-d 目录 指定用户主目录,如果不存在,则创建该目录 | ||
-G 用户组 指定用户所属的用户组 | ||
-g 组id | ||
-s Shell 文件 指定用户的登录 Shell | ||
-u 用户号 指定用户的用户号 | ||
|
||
- 用户名: | ||
指定新账号的登录名。 | ||
|
||
- 更新文件: | ||
> /etc/passwd | ||
> /etc/shadow | ||
> /etc/group | ||
> /etc/gshadow | ||
## userdel | ||
|
||
- usage:删除用户 | ||
|
||
> userdel [options] username | ||
userdel -r username | ||
|
||
- 选项: | ||
-r 连同用户主目录一起删除。 | ||
|
||
- 更新文件: | ||
> /etc/passwd | ||
> /etc/shadow | ||
> /etc/group | ||
## usermod | ||
|
||
- usage:修改用户 | ||
|
||
> usermod [options] username | ||
usermod -a -G<组 1,组 2,...> -c<备注> -d<登入目录> -G<组名> -l<名称> -s<登入终端> -u<用户 id> username | ||
|
||
- 选项: | ||
-a -G<组 1,组 2,...> 将用户添加到其它组中 | ||
-c<备注> 修改用户帐号的备注文字。 | ||
-d 登入目录> 修改用户登入时的目录。 | ||
-G<组名> 修改用户所属的群组。 | ||
-l<名称> 修改用户名称。 | ||
-s\<shell\> 修改用户登入后所使用的 shell。 | ||
-u\<uid\> 修改用户 ID。 | ||
|
||
- 更新文件: | ||
> /etc/passwd | ||
> /etc/shadow | ||
> /etc/group | ||
> /etc/gshadow | ||
## passwd | ||
|
||
- usage:设置密码 | ||
|
||
> 普通用户: passwd | ||
> root 用户: passwd username | ||
普通用户只能修改自己的密码,因此不需要指定用户名。 | ||
|
||
- 更新文件 | ||
> /etc/shadow | ||
> /etc/passwd | ||
## groupadd | ||
|
||
- usage:添加用户组 | ||
|
||
> groupadd [options] groupname | ||
groupadd -g\<gid\> -p\<passwd\> groupname | ||
|
||
- 选项: | ||
-g\<gid\> 指定组 id | ||
-p 设置密码 | ||
|
||
- 更新文件 | ||
> /etc/group | ||
> /etc/gshadow | ||
## groupdel | ||
|
||
- usage:删除用户组 | ||
|
||
> groupdel groupname | ||
groupdel \<groupname\> | ||
|
||
- 注意事项: | ||
只有当用户组的组成员为空时才可以删除该组 | ||
|
||
- 更新文件 | ||
> /etc/group | ||
> /etc/gshadow | ||
## groupmod | ||
|
||
- usage:修改用户组信息 | ||
|
||
> groupmod [options] groupname | ||
groupadd -g\<new gid\> -n\<new groupname\> groupname | ||
|
||
- 选项: | ||
-g 设置新 gid | ||
-n 设置新组名 | ||
|
||
- 更新文件 | ||
> /etc/group | ||
> /etc/gshadow | ||
> /etc/passwd | ||
_/etc/passwd 文件格式:_ | ||
|
||
> 用户名:口令:用户标识号:组标识号:注释性描述:主目录:登录 Shell | ||
_/etc/shadow 文件格式:_ | ||
|
||
> 登录名:加密口令:最后一次修改时间:最小时间间隔:最大时间间隔:警告时间:不活动时间:失效时间:标志 | ||
_/etc/group 文件格式:_ | ||
|
||
> 组名:口令:组标识号:组内用户列表 | ||
_/etc/gshadow 文件格式:_ | ||
|
||
> 组名:组密码:组管理员名称:组成员 |
Oops, something went wrong.