forked from enlightenment/efl
evil: add getpwnam() function
@feature Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
This commit is contained in:
parent
407f7bbb0b
commit
f52be78699
|
@ -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
|
||||
#ifdef UNICODE
|
||||
if (res)
|
||||
{
|
||||
a_name = evil_wchar_to_char(name);
|
||||
if (a_name)
|
||||
{
|
||||
int l;
|
||||
length = UNLEN + 1;
|
||||
res = GetUserName(name, &length);
|
||||
if (!res)
|
||||
return NULL;
|
||||
|
||||
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;
|
||||
#ifdef UNICODE
|
||||
a_name = evil_wchar_to_char(name);
|
||||
if (a_name)
|
||||
{
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue