summaryrefslogtreecommitdiff
path: root/src/lib/evil
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2014-12-09 20:35:15 +0100
committerCedric BAIL <cedric@osg.samsung.com>2014-12-10 02:38:53 +0100
commitf52be78699a2a3165a74f37910eabefec68a977d (patch)
tree1525cd86db388e634c4beca3f23e0cbe25d6b337 /src/lib/evil
parent407f7bbb0b985c1083c71628dd08b0347f99a0aa (diff)
evil: add getpwnam() function
@feature Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/lib/evil')
-rw-r--r--src/lib/evil/evil_pwd.c64
-rw-r--r--src/lib/evil/pwd.h26
2 files changed, 57 insertions, 33 deletions
diff --git a/src/lib/evil/evil_pwd.c b/src/lib/evil/evil_pwd.c
index 0830b5b26a..14463c6561 100644
--- a/src/lib/evil/evil_pwd.c
+++ b/src/lib/evil/evil_pwd.c
@@ -2,8 +2,9 @@
2# include "config.h" 2# include "config.h"
3#endif /* HAVE_CONFIG_H */ 3#endif /* HAVE_CONFIG_H */
4 4
5#include <windows.h> 5#define _POSIX
6#include <security.h> 6#include <io.h>
7#include <lmcons.h>
7 8
8#include "Evil.h" 9#include "Evil.h"
9#include "pwd.h" 10#include "pwd.h"
@@ -12,44 +13,46 @@
12static struct passwd pw; 13static struct passwd pw;
13 14
14struct passwd * 15struct passwd *
15getpwuid (uid_t uid) 16getpwnam(const char *n)
16{ 17{
17 static char user_name[PATH_MAX]; 18 static char user_name[UNLEN + 1];
18 TCHAR name[PATH_MAX]; 19 TCHAR name[UNLEN + 1];
19 ULONG length; 20 DWORD length;
20 BOOLEAN res; 21 BOOLEAN res;
21#ifdef UNICODE 22#ifdef UNICODE
22 char *a_name; 23 char *a_name;
23# endif /* UNICODE */ 24# endif /* UNICODE */
24 25
25 length = PATH_MAX; 26 length = UNLEN + 1;
26#ifdef _WIN32_WINNT 27 res = GetUserName(name, &length);
27 res = GetUserNameEx(NameDisplay, name, &length); 28 if (!res)
28#else 29 return NULL;
29 res = GetUserNameEx(NameWindowsCeLocal, name, &length); 30
30#endif
31#ifdef UNICODE 31#ifdef UNICODE
32 if (res) 32 a_name = evil_wchar_to_char(name);
33 if (a_name)
33 { 34 {
34 a_name = evil_wchar_to_char(name); 35 int l;
35 if (a_name)
36 {
37 int l;
38 36
39 l = strlen(a_name); 37 l = strlen(a_name);
40 if (l >= PATH_MAX) 38 if (l >= PATH_MAX)
41 l = PATH_MAX; 39 l = PATH_MAX;
42 memcpy(user_name, a_name, l); 40 memcpy(user_name, a_name, l);
43 user_name[l] = '\0'; 41 user_name[l] = '\0';
44 free(a_name); 42 free(a_name);
45 }
46 else
47 res = 0;
48 } 43 }
44 else
45 return NULL;
46#else
47 memcpy(user_name, name, strlen(name) + 1);
49#endif /* UNICODE */ 48#endif /* UNICODE */
49
50 if (strcmp(n, user_name) != 0)
51 return NULL;
52
50 pw.pw_name = (res ? user_name : NULL); 53 pw.pw_name = (res ? user_name : NULL);
51 pw.pw_passwd = NULL; 54 pw.pw_passwd = NULL;
52 pw.pw_uid = uid; 55 pw.pw_uid = 0;
53 pw.pw_gid = 0; 56 pw.pw_gid = 0;
54 pw.pw_change = 0; 57 pw.pw_change = 0;
55 pw.pw_class = NULL; 58 pw.pw_class = NULL;
@@ -63,3 +66,10 @@ getpwuid (uid_t uid)
63 66
64 return &pw; 67 return &pw;
65} 68}
69
70struct passwd *
71getpwuid(uid_t uid)
72{
73 return getpwnam(getlogin());
74 (void)uid;
75}
diff --git a/src/lib/evil/pwd.h b/src/lib/evil/pwd.h
index 256c75ff57..a5ed996b2b 100644
--- a/src/lib/evil/pwd.h
+++ b/src/lib/evil/pwd.h
@@ -31,21 +31,35 @@ extern "C" {
31struct passwd { 31struct passwd {
32 char *pw_name; /**< user name */ 32 char *pw_name; /**< user name */
33 char *pw_passwd; /**< encrypted password (always @c NULL) */ 33 char *pw_passwd; /**< encrypted password (always @c NULL) */
34 uid_t pw_uid; /**< user uid */ 34 uid_t pw_uid; /**< user uid (always 0) */
35 gid_t pw_gid; /**< user gid (always O) */ 35 gid_t pw_gid; /**< user gid (always 0) */
36 time_t pw_change; /**< password change time (always 0) */ 36 time_t pw_change; /**< password change time (always 0) */
37 char *pw_class; /**< user access class (always @c NULL) */ 37 char *pw_class; /**< user access class (always @c NULL) */
38 char *pw_gecos; /**< Honeywell login info */ 38 char *pw_gecos; /**< Honeywell login info */
39 char *pw_dir; /**< home directory */ 39 char *pw_dir; /**< home directory */
40 char *pw_shell; /**< default shell */ 40 char *pw_shell; /**< default shell */
41 time_t pw_expire; /**< account expiration (always O) */ 41 time_t pw_expire; /**< account expiration (always 0) */
42 int pw_fields; /**< internal: fields filled in (always O) */ 42 int pw_fields; /**< internal: fields filled in (always 0) */
43}; 43};
44 44
45/** 45/**
46 * @brief Return a passwd structure. 46 * @brief Return a passwd structure.
47 * 47 *
48 * @param uid The User ID 48 * @param n The name of the user.
49 * @return A stacally allocated passwd structure.
50 *
51 * This function fills a static buffer @ref passwd with the user name @p n.
52 *
53 * Conformity: None.
54 *
55 * Supported OS: Windows XP.
56 */
57EAPI struct passwd *getpwnam(const char *n);
58
59/**
60 * @brief Return a passwd structure.
61 *
62 * @param uid The User ID.
49 * @return A stacally allocated passwd structure. 63 * @return A stacally allocated passwd structure.
50 * 64 *
51 * This function fills a static buffer @ref passwd with @p uid and the 65 * This function fills a static buffer @ref passwd with @p uid and the
@@ -53,7 +67,7 @@ struct passwd {
53 * 67 *
54 * Conformity: None. 68 * Conformity: None.
55 * 69 *
56 * Supported OS: Windows XP, CE. 70 * Supported OS: Windows XP.
57 */ 71 */
58EAPI struct passwd *getpwuid (uid_t uid); 72EAPI struct passwd *getpwuid (uid_t uid);
59 73