summaryrefslogtreecommitdiffstats
path: root/sysutils/gnome-volume-manager/files/patch-src_manager.c
blob: a9a37cca2b2dd3e50619ce71ad910a534868376c (plain) (blame)
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
--- src/manager.c.orig  Tue Nov  7 13:01:17 2006
+++ src/manager.c   Tue Nov  7 21:18:25 2006
@@ -23,9 +23,12 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <dirent.h>
+#include <fcntl.h>
 #include <signal.h>
 #include <unistd.h>
 #include <utmp.h>
+#include <sys/param.h>
+#include <sys/mount.h>
 
 #include <locale.h>
 
@@ -3185,6 +3188,12 @@ gvm_local_user (void)
    size_t n;
    DIR *dir;
    int vt;
+#ifndef __linux__
+   int bytes, fd;
+   struct stat sb;
+   struct utmp buf[1024];
+   size_t len;
+#endif
    
    if (local & LOCAL_USER_CHECKED)
        return (local & LOCAL_USER_FOUND);
@@ -3208,6 +3217,7 @@ gvm_local_user (void)
    
  fallback:
    
+#ifdef __linux__
    if (!(local & LOCAL_USER_FOUND)) {
        setutent ();
        
@@ -3222,6 +3232,29 @@ gvm_local_user (void)
        
        endutent ();
    }
+#else
+   if ((fd = open (_PATH_WTMP, O_RDONLY, 0)) < 0 || fstat(fd, &sb) == -1) {
+       close (fd);
+       return TRUE;
+   }
+
+   len = (sb.st_size + sizeof(buf) - 1) / sizeof(buf);
+
+   while (!local && --len >= 0) {
+       if (lseek(fd, (off_t) (len * sizeof(buf)), L_SET) == -1 ||
+               (bytes = read (fd, buf, sizeof(buf))) == -1) {
+           close (fd);
+           return TRUE;
+       }
+       for (utmp = &buf[bytes / sizeof(buf[0]) - 1]; !local && utmp >= buf; --utmp) {
+           if (!utmp->ut_name[0] || strncmp (utmp->ut_name, user, n) != 0)
+               continue;
+           local = utmp->ut_line[0] == ':' && utmp->ut_line[1] >= '0' && utmp->ut_line[1] <= '9' || !strncmp (utmp->ut_line, "tty", 3) ? LOCAL_USER_FOUND : 0;
+       }
+   }
+
+   close (fd);
+#endif
    
    local |= LOCAL_USER_CHECKED;