1
0
Fork 0
mirror of https://gitlab.com/Syping/mayu synced 2024-10-06 22:26:54 +02:00

improve security

This commit is contained in:
Syping 2019-04-14 17:22:45 +02:00
parent f01ffd0f74
commit b898a6ca69
4 changed files with 16 additions and 4 deletions

View file

@ -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.

View file

@ -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
View file

@ -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
};

View file

@ -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.