mirror of https://gitlab.com/Syping/mayu
Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
Syping | b898a6ca69 | |
Syping | f01ffd0f74 | |
Syping | dd01afacf6 |
59
main.cpp
59
main.cpp
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
* mayu Mate Are You Up
|
||||
* Copyright (C) 2018 Syping
|
||||
* Copyright (C) 2019 Syping
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -35,26 +35,43 @@ int main(int argc, char *argv[])
|
|||
mayuMode a_mode = mayuMode::Ping;
|
||||
for (int i = arguments.length(); i > 0; i--) {
|
||||
const QString &argument = arguments.at(i-1);
|
||||
if (argument == "-p" || argument == "--ping") {
|
||||
a_mode = mayuMode::Ping;
|
||||
arguments.removeAt(i-1);
|
||||
if (argument.left(2) == "--") {
|
||||
if (argument == "--ping") {
|
||||
a_mode = mayuMode::Ping;
|
||||
arguments.removeAt(i-1);
|
||||
}
|
||||
else if (argument == "--resolve") {
|
||||
a_mode = mayuMode::Resolve;
|
||||
arguments.removeAt(i-1);
|
||||
}
|
||||
else if (argument == "--clean") {
|
||||
a_clean = true;
|
||||
arguments.removeAt(i-1);
|
||||
}
|
||||
else {
|
||||
QTextStream(stderr) << "Unknown Option found: " << argument << endl;
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
else if (argument == "-r" || argument == "--resolve") {
|
||||
a_mode = mayuMode::Resolve;
|
||||
arguments.removeAt(i-1);
|
||||
}
|
||||
else if (argument == "-c" || argument == "--clean") {
|
||||
a_clean = true;
|
||||
arguments.removeAt(i-1);
|
||||
}
|
||||
else if (argument == "-pc" || argument == "-cp") {
|
||||
a_mode = mayuMode::Ping;
|
||||
a_clean = true;
|
||||
arguments.removeAt(i-1);
|
||||
}
|
||||
else if (argument == "-rc" || argument == "-cr") {
|
||||
a_mode = mayuMode::Resolve;
|
||||
a_clean = true;
|
||||
else if (argument.left(1) == "-" && argument.length() != 1) {
|
||||
for (int ii = argument.length(); ii > 0; ii--) {
|
||||
switch (argument.at(ii-1).cell()) {
|
||||
case 'p':
|
||||
a_mode = mayuMode::Ping;
|
||||
break;
|
||||
case 'r':
|
||||
a_mode = mayuMode::Resolve;
|
||||
break;
|
||||
case 'c':
|
||||
a_clean = true;
|
||||
break;
|
||||
case '-':
|
||||
break;
|
||||
default:
|
||||
QTextStream(stderr) << "Unknown Option found: " << argument.at(ii-1) << endl;
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
arguments.removeAt(i-1);
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +84,7 @@ int main(int argc, char *argv[])
|
|||
return a_mayu.getResult();
|
||||
}
|
||||
else {
|
||||
QTextStream(stdout) << "Usage: " << a.arguments().at(0) << " [-p ping]" << " [-r resolve]" << " [-c clean]" << " input.txt" << " output.json" << endl;
|
||||
QTextStream(stderr) << "Usage: " << a.arguments().at(0) << " [-cpr]" << " [--clean]" << " [--ping]" << " [--resolve]" << " [HOSTS FILE]" << " [OUTPUT FILE]" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
13
mayu.cpp
13
mayu.cpp
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
* mayu Mate Are You Up
|
||||
* Copyright (C) 2018 Syping
|
||||
* Copyright (C) 2019 Syping
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -403,11 +403,17 @@ bool mayu::p_dropPrivileges()
|
|||
{
|
||||
#if _POSIX_SAVED_IDS
|
||||
p_uid = geteuid();
|
||||
p_gid = getegid();
|
||||
int status = seteuid(getuid());
|
||||
if (status != 0) {
|
||||
QTextStream(stderr) << "Dropping of privileges has failed!" << endl;
|
||||
return false;
|
||||
}
|
||||
status = setegid(getgid());
|
||||
if (status != 0) {
|
||||
QTextStream(stderr) << "Dropping of privileges has failed!" << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
|
@ -422,6 +428,11 @@ bool mayu::p_regainPrivileges()
|
|||
QTextStream(stderr) << "Regaining of privileges has failed!" << endl;
|
||||
return false;
|
||||
}
|
||||
status = setegid(p_gid);
|
||||
if (status != 0) {
|
||||
QTextStream(stderr) << "Regaining of privileges has failed!" << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
|
|
3
mayu.h
3
mayu.h
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
* mayu Mate Are You Up
|
||||
* Copyright (C) 2018 Syping
|
||||
* Copyright (C) 2019 Syping
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -82,6 +82,7 @@ private:
|
|||
bool p_clean;
|
||||
#ifdef PRIVILEGE_DROP_REQUIRED
|
||||
uid_t p_uid;
|
||||
gid_t p_gid;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
2
mayu.pro
2
mayu.pro
|
@ -1,6 +1,6 @@
|
|||
#/*****************************************************************************
|
||||
#* mayu Mate Are You Up
|
||||
#* Copyright (C) 2018 Syping
|
||||
#* Copyright (C) 2019 Syping
|
||||
#*
|
||||
#* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
#* you may not use this file except in compliance with the License.
|
||||
|
|
Loading…
Reference in New Issue