From: Arvin Schnell Date: Fri, 1 Aug 2014 07:51:58 +0000 (+0200) Subject: - show id of user if namename cannot be detected X-Git-Tag: v0.2.4~5^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2d0c71b2ffd08bcf9e4b4e6b4944f0715c77127f;p=thirdparty%2Fsnapper.git - show id of user if namename cannot be detected --- diff --git a/client/misc.cc b/client/misc.cc index c4b043b8..1d40ad77 100644 --- a/client/misc.cc +++ b/client/misc.cc @@ -196,3 +196,16 @@ read_configdata(const list& l, const map& old) return configdata; } + + +string +username(uid_t uid) +{ + string username; + gid_t gid; + + if (!get_uid_username_gid(uid, username, gid)) + return sformat("unknown (%d)", uid); + + return username; +} diff --git a/client/misc.h b/client/misc.h index 924a41fb..65728ef4 100644 --- a/client/misc.h +++ b/client/misc.h @@ -47,3 +47,5 @@ show_userdata(const map& userdata); map read_configdata(const list& l, const map& old = map()); +string +username(uid_t uid); diff --git a/package/snapper.changes b/package/snapper.changes index 08af4cd7..887d04b1 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -3,6 +3,7 @@ Thu Jul 31 15:38:16 CEST 2014 - aschnell@suse.de - also handle primary group of user when checking permissions (see gh#openSUSE/snapper#100) +- show id of user if namename cannot be detected ------------------------------------------------------------------- Fri Jul 25 12:38:33 CEST 2014 - aschnell@suse.de diff --git a/snapper/AppUtil.cc b/snapper/AppUtil.cc index 681f332b..377ca8f8 100644 --- a/snapper/AppUtil.cc +++ b/snapper/AppUtil.cc @@ -262,24 +262,6 @@ namespace snapper } - string - username(uid_t uid) - { - struct passwd pwd; - struct passwd* result; - - long bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); - char buf[bufsize]; - - if (getpwuid_r(uid, &pwd, buf, bufsize, &result) != 0 || result != &pwd) - return "unknown"; - - memset(pwd.pw_passwd, 0, strlen(pwd.pw_passwd)); - - return pwd.pw_name; - } - - bool get_uid_username_gid(uid_t uid, string& username, gid_t& gid) { diff --git a/snapper/AppUtil.h b/snapper/AppUtil.h index 1afb9c94..452b48e1 100644 --- a/snapper/AppUtil.h +++ b/snapper/AppUtil.h @@ -85,7 +85,6 @@ namespace snapper string datetime(time_t time, bool utc, bool classic); time_t scan_datetime(const string& str, bool utc); - string username(uid_t uid); bool get_uid_username_gid(uid_t uid, string& username, gid_t& gid); bool get_user_uid(const char* username, uid_t& uid); bool get_group_gid(const char* groupname, gid_t& gid);