summaryrefslogtreecommitdiff
path: root/src/lib/evil/evil_pwd.c
blob: 14463c6561981a39c32e96813a2dfc60260b84b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */

#define _POSIX
#include <io.h>
#include <lmcons.h>

#include "Evil.h"
#include "pwd.h"


static struct passwd pw;

struct passwd *
getpwnam(const char *n)
{
   static char user_name[UNLEN + 1];
   TCHAR       name[UNLEN + 1];
   DWORD       length;
   BOOLEAN     res;
#ifdef UNICODE
   char       *a_name;
# endif /* UNICODE */

   length = UNLEN + 1;
   res = GetUserName(name, &length);
   if (!res)
     return NULL;

#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 = 0;
   pw.pw_gid = 0;
   pw.pw_change = 0;
   pw.pw_class = NULL;
   pw.pw_gecos = (res ? user_name : NULL);
   pw.pw_dir = (char *)evil_homedir_get();
   pw.pw_shell = getenv("SHELL");
   if (!pw.pw_shell)
     pw.pw_shell = "sh";
   pw.pw_expire = 0;
   pw.pw_fields = 0;

   return &pw;
}

struct passwd *
getpwuid(uid_t uid)
{
   return getpwnam(getlogin());
   (void)uid;
}