mirror of
https://gitlab.com/Syping/mayu
synced 2024-11-21 11:30:22 +01:00
improve security
This commit is contained in:
parent
f01ffd0f74
commit
b898a6ca69
4 changed files with 16 additions and 4 deletions
2
main.cpp
2
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.
|
||||
|
|
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 a new issue