Skip to content

Commit c461dad

Browse files
committed
MGM: Refactoring - replace hardcoded user "adm" UID and GID
Created ADM_UID and ADM_GID in Constants.hh and replaced hardcoded integers (3 and 4) with those two constants. Fixes EOS-6399
1 parent 18ad447 commit c461dad

File tree

14 files changed

+42
-30
lines changed

14 files changed

+42
-30
lines changed

common/Constants.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#pragma once
2626
#include "common/Namespace.hh"
27+
#include <sys/types.h>
2728

2829
EOSCOMMONNAMESPACE_BEGIN
2930

@@ -83,5 +84,7 @@ static constexpr auto EOS_VTRACE_ATTR = "sys.vtrace";
8384
static constexpr auto EOS_UTRACE_ATTR = "sys.utrace";
8485
//! FST heartbeat key marker, the "stat." prefix makes it transient
8586
static constexpr auto FST_HEARTBEAT_KEY = "stat.heartbeat";
86-
87+
//! ADM uid and gid
88+
static constexpr uid_t ADM_UID = 3;
89+
static constexpr gid_t ADM_GID = 4;
8790
EOSCOMMONNAMESPACE_END

mgm/Recycle.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ Recycle::Print(std::string& std_out, std::string& std_err,
471471
}
472472

473473
if (global && ((!vid.uid) ||
474-
(vid.hasUid(3)) ||
475-
(vid.hasGid(4)))) {
474+
(vid.hasUid(eos::common::ADM_UID)) ||
475+
(vid.hasGid(eos::common::ADM_GID)))) {
476476
// add everything found in the recycle directory structure to the printmap
477477
std::string subdirs;
478478
XrdMgmOfsDirectory dirl;
@@ -1031,8 +1031,8 @@ Recycle::Purge(std::string& std_out, std::string& std_err,
10311031
}
10321032

10331033
if (vid.uid && !vid.sudoer &&
1034-
!(vid.hasUid(3)) &&
1035-
!(vid.hasGid(4))) {
1034+
!(vid.hasUid(eos::common::ADM_UID)) &&
1035+
!(vid.hasGid(eos::common::ADM_GID))) {
10361036
std_err = "error: you cannot purge your recycle bin without being a sudor "
10371037
"or having an admin role";
10381038
return EPERM;

mgm/XrdMgmOfs/Chmod.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ XrdMgmOfs::_chmod(const char* path,
148148
if (((fmd && (fmd->getCUid() == vid.uid)) && (!acl.CanNotChmod())) ||
149149
((cmd && (cmd->getCUid() == vid.uid)) && (!acl.CanNotChmod())) ||
150150
(!vid.uid) || // the root user
151-
(vid.uid == 3) || // the admin user
152-
(vid.gid == 4) || // the admin group
151+
(vid.uid == eos::common::ADM_UID) || // the admin user
152+
(vid.gid == eos::common::ADM_GID) || // the admin group
153153
(acl.CanChmod())
154154
) { // a pre-defined mask to apply to the desired modbits
155155
// the chmod ACL entry

mgm/XrdMgmOfs/Chown.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ XrdMgmOfs::_chown(const char* path,
8686
eos_static_debug("sys.acl %s acl.CanChown() %d", attrmap["sys.acl"].c_str(),
8787
acl.CanChown());
8888

89-
if (((vid.uid) && (!vid.hasUid(3) && !vid.hasGid(4)) &&
89+
if (((vid.uid) && (!vid.hasUid(eos::common::ADM_UID) && !vid.hasGid(eos::common::ADM_GID)) &&
9090
!acl.CanChown()) ||
9191
((vid.uid) && !acl.IsMutable())) {
9292
errno = EPERM;
@@ -96,7 +96,7 @@ XrdMgmOfs::_chown(const char* path,
9696
cmd->setCUid(uid);
9797
}
9898

99-
if (((!vid.uid) || (vid.uid == 3) || (vid.gid == 4)) &&
99+
if (((!vid.uid) || (vid.uid == eos::common::ADM_UID) || (vid.gid == eos::common::ADM_GID)) &&
100100
((unsigned int)gid != 0xffffffff)) {
101101
// Change the group
102102
cmd->setCGid(gid);
@@ -141,7 +141,7 @@ XrdMgmOfs::_chown(const char* path,
141141
eos_static_debug("sys.acl %s acl.CanChown() %d", attrmap["sys.acl"].c_str(),
142142
acl.CanChown());
143143

144-
if ((vid.uid) && (!vid.sudoer) && (vid.uid != 3) && (vid.gid != 4) &&
144+
if ((vid.uid) && (!vid.sudoer) && (vid.uid != eos::common::ADM_UID) && (vid.gid != eos::common::ADM_GID) &&
145145
!acl.CanChown()) {
146146
errno = EPERM;
147147
} else {

mgm/XrdMgmOfs/Find.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ XrdMgmOfs::_find(const char* path, XrdOucErrInfo& out_error,
705705
bool limited = false;
706706
bool fail_if_limited = (out_error.getErrInfo() == E2BIG);
707707

708-
if ((vid.uid != 0) && (!vid.hasUid(3)) && (!vid.hasGid(4)) && (!vid.sudoer)) {
708+
if ((vid.uid != 0) && (!vid.hasUid(eos::common::ADM_UID)) && (!vid.hasGid(eos::common::ADM_GID)) && (!vid.sudoer)) {
709709
limitresult = true;
710710
}
711711

mgm/proc/ProcInterface.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "ProcInterface.hh"
2525
#include <XrdOuc/XrdOucEnv.hh>
26+
#include "common/Constants.hh"
2627
#include "mgm/proc/admin/AccessCmd.hh"
2728
#include "mgm/proc/admin/ConfigCmd.hh"
2829
#include "mgm/proc/admin/ConvertCmd.hh"
@@ -588,8 +589,8 @@ ProcInterface::Authorize(const char* path, const char* info,
588589

589590
// One has to be part of the virtual users 2(daemon)/3(adm)/4(adm)
590591
return ((vid.hasUid(DAEMONUID)) ||
591-
(vid.hasUid(3)) ||
592-
(vid.hasGid(4)));
592+
(vid.hasUid(eos::common::ADM_UID)) ||
593+
(vid.hasGid(eos::common::ADM_GID)));
593594
}
594595

595596
// User access

mgm/proc/admin/AccessCmd.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "mgm/Access.hh"
2929
#include "mgm/Stat.hh"
3030
#include "common/StringUtils.hh"
31+
#include "common/Constants.hh"
3132
#include <XrdOuc/XrdOucEnv.hh>
3233
#include <cctype>
3334

@@ -85,7 +86,7 @@ AccessCmd::ProcessRequest() noexcept
8586
eos::console::ReplyProto reply;
8687
eos::console::AccessProto access = mReqProto.access();
8788

88-
if ((mVid.uid != 0) && (!mVid.hasUid(3)) && (!mVid.hasGid(4)) &&
89+
if ((mVid.uid != 0) && (!mVid.hasUid(eos::common::ADM_UID)) && (!mVid.hasGid(eos::common::ADM_GID)) &&
8990
(!mVid.sudoer)) {
9091
// root and admins only
9192
reply.set_std_out("");

mgm/proc/admin/ConvertCmd.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "namespace/interface/IFileMD.hh"
3131
#include "namespace/interface/IContainerMD.hh"
3232
#include "common/table_formatter/TableFormatterBase.hh"
33+
#include "common/Constants.hh"
3334
#include <json/json.h>
3435

3536
EOSMGMNAMESPACE_BEGIN
@@ -77,7 +78,7 @@ ConvertCmd::ProcessRequest() noexcept
7778
ListSubcmd(convert.list(), reply, jsonOutput);
7879
} else if (subcmd == eos::console::ConvertProto::kClear) {
7980
// check if vid has admin permissions (root, sudoer, admin user, admin group)
80-
if (!vid.uid || vid.sudoer || vid.hasUid(3) || vid.hasGid(4)) {
81+
if (!vid.uid || vid.sudoer || vid.hasUid(eos::common::ADM_UID) || vid.hasGid(eos::common::ADM_GID)) {
8182
ClearSubcmd(convert.clear(), reply);
8283
} else {
8384
reply.set_retc(EPERM);

mgm/proc/admin/QuotaCmd.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "mgm/Quota.hh"
3030
#include "mgm/Recycle.hh"
3131
#include "common/Path.hh"
32+
#include "common/Constants.hh"
3233

3334
EOSMGMNAMESPACE_BEGIN
3435

@@ -209,8 +210,8 @@ void QuotaCmd::LsSubcmd(const eos::console::QuotaProto_LsProto& ls,
209210
}
210211
}
211212

212-
if ((!mVid.uid) || mVid.hasUid(3) ||
213-
mVid.hasGid(4)) { // @note no.03 before 'vid' was used, using 'mVid' now
213+
if ((!mVid.uid) || mVid.hasUid(eos::common::ADM_UID) ||
214+
mVid.hasGid(eos::common::ADM_GID)) { // @note no.03 before 'vid' was used, using 'mVid' now
214215
// root and admin can set quota
215216
canQuota = true;
216217
} else {
@@ -327,7 +328,7 @@ void QuotaCmd::SetSubcmd(const eos::console::QuotaProto_SetProto& set,
327328

328329
bool canQuota;
329330

330-
if ((!mVid.uid) || mVid.hasUid(3) || mVid.hasGid(4)) { // @note no.03
331+
if ((!mVid.uid) || mVid.hasUid(eos::common::ADM_UID) || mVid.hasGid(eos::common::ADM_GID)) { // @note no.03
331332
// root and admin can set quota
332333
canQuota = true;
333334
} else {
@@ -519,7 +520,7 @@ void QuotaCmd::RmSubcmd(const eos::console::QuotaProto_RmProto& rm,
519520

520521
bool canQuota;
521522

522-
if ((!mVid.uid) || mVid.hasUid(3) || mVid.hasGid(4)) { // @note no.02
523+
if ((!mVid.uid) || mVid.hasUid(eos::common::ADM_UID) || mVid.hasGid(eos::common::ADM_GID)) { // @note no.02
523524
// root and admin can set quota
524525
canQuota = true;
525526
} else {

mgm/proc/user/Map.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "mgm/proc/ProcInterface.hh"
2525
#include "mgm/XrdMgmOfs.hh"
2626
#include "mgm/config/IConfigEngine.hh"
27+
#include "common/Constants.hh"
2728

2829
EOSMGMNAMESPACE_BEGIN
2930

@@ -45,7 +46,7 @@ ProcCommand::Map()
4546
}
4647

4748
if (mSubCmd == "link") {
48-
if ((!pVid->uid) || vid.hasUid(3) || vid.hasGid(4)) {
49+
if ((!pVid->uid) || vid.hasUid(eos::common::ADM_UID) || vid.hasGid(eos::common::ADM_GID)) {
4950
XrdOucString srcpath = pOpaque->Get("mgm.map.src");
5051
XrdOucString dstpath = pOpaque->Get("mgm.map.dest");
5152

@@ -94,8 +95,8 @@ ProcCommand::Map()
9495
XrdOucString path = pOpaque->Get("mgm.map.src");
9596

9697
if ((!pVid->uid) ||
97-
vid.hasUid(3) ||
98-
vid.hasGid(4)) {
98+
vid.hasUid(eos::common::ADM_UID) ||
99+
vid.hasGid(eos::common::ADM_GID)) {
99100
eos::common::RWMutexWriteLock lock(gOFS->PathMapMutex);
100101

101102
if ((!path.length()) || (!gOFS->PathMap.count(path.c_str()))) {

0 commit comments

Comments
 (0)