evil: add getpwnam() function
authorVincent Torri <vincent.torri@gmail.com>
Tue, 9 Dec 2014 19:35:15 +0000 (20:35 +0100)
committerCedric BAIL <cedric@osg.samsung.com>
Wed, 10 Dec 2014 01:38:53 +0000 (02:38 +0100)
@feature

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
src/lib/evil/evil_pwd.c
src/lib/evil/pwd.h

index 0830b5b..14463c6 100644 (file)
@@ -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"
 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;
+}
index 256c75f..a5ed996 100644 (file)
@@ -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);