--- /dev/null
+#pragma once
+#include <grp.h>
+#include <pwd.h>
+#include <string>
+#include <sys/types.h>
+
+static uid_t convertToUid(const char* user) {
+ errno = 0;
+ long val = std::strtol(user, nullptr, 10);
+ if ((!errno && val != 0) || (val == 0 && user[0] == '0' && user[1] == '\0'))
+ return (uid_t) val;
+
+ struct passwd pwent;
+ struct passwd *pwd;
+ char buf[1024];
+ if (getpwnam_r(user, &pwent, buf, sizeof(buf), &pwd) || !pwd)
+ return (uid_t) -1;
+
+ return pwd->pw_uid;
+}
+
+static gid_t convertToGid(const char* group) {
+ errno = 0;
+ long val = std::strtol(group, nullptr, 10);
+ if ((!errno && val != 0) || (val == 0 && group[0] == '0' && group[1] == '\0'))
+ return (gid_t) val;
+
+ struct group grent;
+ struct group *gg;
+ char buf[1024];
+ if (getgrnam_r(group, &grent, buf, sizeof(buf), &gg) || !gg)
+ return (gid_t) -1;
+
+ return gg->gr_gid;
+}
+
*/
#include "libdbuspolicy1-private.h"
#include "tslog.hpp"
+#include "uid_gid_helpers.hpp"
#include "xml_parser.hpp"
#include <boost/algorithm/string/predicate.hpp>
#include <cstring>
#include <dirent.h>
#include <expat.h>
-#include <grp.h>
#include <libgen.h>
#include <memory>
-#include <pwd.h>
#include <unistd.h>
using namespace ldp_xml_parser;
}
}
-namespace {
-static uid_t convertToUid(const char* user) {
- long val = -1;
- errno = 0;
- val = std::strtol(user, NULL, 10);
- if (!errno && (val != 0 ))
- return (uid_t)val;
- if ((val == 0 && user[0] == '0' && user[1] == 0))
- return (uid_t)val;
-
- struct passwd pwent;
- struct passwd *pwd;
- char buf[1024];
- if (getpwnam_r(user, &pwent, buf, sizeof(buf), &pwd) || !pwd)
- return (uid_t)-1;
-
- return pwd->pw_uid;
-}
-
-static gid_t convertToGid(const char* group) {
- long val = -1;
- errno = 0;
- val = std::strtol(group, NULL, 10);
- if (!errno && (val != 0))
- return (gid_t)val;
- if ((val == 0 && group[0] == '0' && group[1] == 0))
- return (gid_t)val;
-
- struct group grent;
- struct group *gg;
- char buf[1024];
- if (getgrnam_r(group, &grent, buf, sizeof(buf), &gg) || !gg)
- return (gid_t)-1;
-
- return gg->gr_gid;
-}
-}
-
void XmlParser::parsePolicyAttribute(const char* name, const char* value)
{
//possible values (from dbus-daemon man):