diff --git a/main.cpp b/main.cpp index 4052b0c..eea0d9b 100644 --- a/main.cpp +++ b/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. diff --git a/mayu.cpp b/mayu.cpp index 0455711..210a777 100644 --- a/mayu.cpp +++ b/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; diff --git a/mayu.h b/mayu.h index 2c190fa..2b09b67 100644 --- a/mayu.h +++ b/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 }; diff --git a/mayu.pro b/mayu.pro index accb72a..4d4b60c 100644 --- a/mayu.pro +++ b/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.