cedric pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=f52be78699a2a3165a74f37910eabefec68a977d
commit f52be78699a2a3165a74f37910eabefec68a977d Author: Vincent Torri <[email protected]> Date: Tue Dec 9 20:35:15 2014 +0100 evil: add getpwnam() function @feature Signed-off-by: Cedric BAIL <[email protected]> --- src/lib/evil/evil_pwd.c | 64 ++++++++++++++++++++++++++++--------------------- src/lib/evil/pwd.h | 26 +++++++++++++++----- 2 files changed, 57 insertions(+), 33 deletions(-) diff --git a/src/lib/evil/evil_pwd.c b/src/lib/evil/evil_pwd.c index 0830b5b..14463c6 100644 --- a/src/lib/evil/evil_pwd.c +++ b/src/lib/evil/evil_pwd.c @@ -2,8 +2,9 @@ # include "config.h" #endif /* HAVE_CONFIG_H */ -#include <windows.h> -#include <security.h> +#define _POSIX +#include <io.h> +#include <lmcons.h> #include "Evil.h" #include "pwd.h" @@ -12,44 +13,46 @@ static struct passwd pw; struct passwd * -getpwuid (uid_t uid) +getpwnam(const char *n) { - static char user_name[PATH_MAX]; - TCHAR name[PATH_MAX]; - ULONG length; + static char user_name[UNLEN + 1]; + TCHAR name[UNLEN + 1]; + DWORD length; BOOLEAN res; #ifdef UNICODE char *a_name; # endif /* UNICODE */ - length = PATH_MAX; -#ifdef _WIN32_WINNT - res = GetUserNameEx(NameDisplay, name, &length); -#else - res = GetUserNameEx(NameWindowsCeLocal, name, &length); -#endif + length = UNLEN + 1; + res = GetUserName(name, &length); + if (!res) + return NULL; + #ifdef UNICODE - if (res) + a_name = evil_wchar_to_char(name); + if (a_name) { - a_name = evil_wchar_to_char(name); - if (a_name) - { - int l; + int l; - l = strlen(a_name); - if (l >= PATH_MAX) - l = PATH_MAX; - memcpy(user_name, a_name, l); - user_name[l] = '\0'; - free(a_name); - } - else - res = 0; + l = strlen(a_name); + if (l >= PATH_MAX) + l = PATH_MAX; + memcpy(user_name, a_name, l); + user_name[l] = '\0'; + free(a_name); } + else + return NULL; +#else + memcpy(user_name, name, strlen(name) + 1); #endif /* UNICODE */ + + if (strcmp(n, user_name) != 0) + return NULL; + pw.pw_name = (res ? user_name : NULL); pw.pw_passwd = NULL; - pw.pw_uid = uid; + pw.pw_uid = 0; pw.pw_gid = 0; pw.pw_change = 0; pw.pw_class = NULL; @@ -63,3 +66,10 @@ getpwuid (uid_t uid) return &pw; } + +struct passwd * +getpwuid(uid_t uid) +{ + return getpwnam(getlogin()); + (void)uid; +} diff --git a/src/lib/evil/pwd.h b/src/lib/evil/pwd.h index 256c75f..a5ed996 100644 --- a/src/lib/evil/pwd.h +++ b/src/lib/evil/pwd.h @@ -31,21 +31,35 @@ extern "C" { struct passwd { char *pw_name; /**< user name */ char *pw_passwd; /**< encrypted password (always @c NULL) */ - uid_t pw_uid; /**< user uid */ - gid_t pw_gid; /**< user gid (always O) */ + uid_t pw_uid; /**< user uid (always 0) */ + gid_t pw_gid; /**< user gid (always 0) */ time_t pw_change; /**< password change time (always 0) */ char *pw_class; /**< user access class (always @c NULL) */ char *pw_gecos; /**< Honeywell login info */ char *pw_dir; /**< home directory */ char *pw_shell; /**< default shell */ - time_t pw_expire; /**< account expiration (always O) */ - int pw_fields; /**< internal: fields filled in (always O) */ + time_t pw_expire; /**< account expiration (always 0) */ + int pw_fields; /**< internal: fields filled in (always 0) */ }; /** * @brief Return a passwd structure. * - * @param uid The User ID + * @param n The name of the user. + * @return A stacally allocated passwd structure. + * + * This function fills a static buffer @ref passwd with the user name @p n. + * + * Conformity: None. + * + * Supported OS: Windows XP. + */ +EAPI struct passwd *getpwnam(const char *n); + +/** + * @brief Return a passwd structure. + * + * @param uid The User ID. * @return A stacally allocated passwd structure. * * This function fills a static buffer @ref passwd with @p uid and the @@ -53,7 +67,7 @@ struct passwd { * * Conformity: None. * - * Supported OS: Windows XP, CE. + * Supported OS: Windows XP. */ EAPI struct passwd *getpwuid (uid_t uid); --
