Browse Source

improve security

master
Syping 3 years ago
parent
commit
b898a6ca69
  1. 2
      main.cpp
  2. 13
      mayu.cpp
  3. 3
      mayu.h
  4. 2
      mayu.pro

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

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

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

@ -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…
Cancel
Save