mirror of
https://github.com/RubyMetric/chsrc
synced 2025-06-08 11:14:03 +08:00
Ensure root
Gitee close #I81YOX
This commit is contained in:
parent
2038b84d57
commit
094f1ed7d2
5
chsrc.c
5
chsrc.c
@ -846,6 +846,8 @@ os_ubuntu_getsrc(char* option)
|
|||||||
void
|
void
|
||||||
os_ubuntu_setsrc (char* option)
|
os_ubuntu_setsrc (char* option)
|
||||||
{
|
{
|
||||||
|
ensure_root();
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
if (NULL!=option) {
|
if (NULL!=option) {
|
||||||
@ -879,8 +881,7 @@ os_ubuntu_setsrc (char* option)
|
|||||||
"-ports/@\'< /etc/apt/sources.list.bak | cat > /etc/apt/sources.list");
|
"-ports/@\'< /etc/apt/sources.list.bak | cat > /etc/apt/sources.list");
|
||||||
}
|
}
|
||||||
|
|
||||||
chsrc_logcmd(cmd);
|
chsrc_runcmd(cmd);
|
||||||
system(cmd);
|
|
||||||
// char* rm = "rm -rf /etc/apt/source.list.bak";
|
// char* rm = "rm -rf /etc/apt/source.list.bak";
|
||||||
// system(rm);
|
// system(rm);
|
||||||
|
|
||||||
|
23
chsrc.h
23
chsrc.h
@ -261,6 +261,29 @@ chsrc_say_thanks (source_info* source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ensure_root ()
|
||||||
|
{
|
||||||
|
char* euid = getenv("$EUID");
|
||||||
|
if (NULL==euid) {
|
||||||
|
FILE* fp = popen("id -u", "r");
|
||||||
|
char buf[10] = {0};
|
||||||
|
fgets(buf, 10, fp);
|
||||||
|
fclose(fp);
|
||||||
|
if (0!=atoi(buf)) goto not_root;
|
||||||
|
else return;
|
||||||
|
} else {
|
||||||
|
if (0!=atoi(euid)) goto not_root;
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
not_root:
|
||||||
|
xy_error("chsrc: 请在命令前使用 sudo 来保证必要的权限");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Target Info */
|
/* Target Info */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void (*setfn)(char* option);
|
void (*setfn)(char* option);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user