summaryrefslogtreecommitdiff
path: root/sysutils/policykit/files/patch-tools_polkit-auth.c
blob: 3f8ad0402631052d984347ede80917c3cbd063da (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
--- tools/polkit-auth.c.orig	2008-04-08 12:23:22.000000000 -0400
+++ tools/polkit-auth.c	2008-04-22 01:24:55.000000000 -0400
@@ -37,7 +37,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
-#ifdef HAVE_SOLARIS
+#if defined(HAVE_SOLARIS) || defined(HAVE_FREEBSD)
 #include <sys/wait.h>
 #endif
 #include <pwd.h>
@@ -72,6 +72,77 @@ typedef struct {
         GMainLoop *loop;
 } UserData;
 
+#ifndef HAVE_GETLINE
+static ssize_t
+getline (char **lineptr, size_t *n, FILE *stream)
+{
+  char *line, *p;
+  long size, copy;
+
+  if (lineptr == NULL || n == NULL) {
+          errno = EINVAL;
+          return (ssize_t) -1;
+  }
+
+  if (ferror (stream))
+          return (ssize_t) -1;
+
+  /* Make sure we have a line buffer to start with.  */
+  if (*lineptr == NULL || *n < 2) /* !seen and no buf yet need 2 chars.  */ {
+#ifndef        MAX_CANON
+#define        MAX_CANON        256
+#endif
+          if (!*lineptr)
+                  line = (char *) malloc (MAX_CANON);
+          else
+                  line = (char *) realloc (*lineptr, MAX_CANON);
+          if (line == NULL)
+                  return (ssize_t) -1;
+          *lineptr = line;
+          *n = MAX_CANON;
+  }
+
+  line = *lineptr;
+  size = *n;
+
+  copy = size;
+  p = line;
+
+  while (1) {
+          long len;
+
+          while (--copy > 0) {
+                  int c = getc (stream);
+
+                  if (c == EOF)
+                          goto lose;
+                  else if ((*p++ = c) == '\n')
+                          goto win;
+          }
+
+          /* Need to enlarge the line buffer.  */
+          len = p - line;
+          size *= 2;
+          line = (char *) realloc (line, size);
+          if (line == NULL)
+                  goto lose;
+          *lineptr = line;
+          *n = size;
+          p = line + len;
+          copy = size - len;
+  }
+
+lose:
+  if (p == *lineptr)
+          return (ssize_t) -1;
+
+  /* Return a partial line since we got an error in the middle.  */
+win:
+  *p = '\0';
+  return p - *lineptr;
+}
+#endif
+
 static void
 conversation_type (PolKitGrant *polkit_grant, PolKitResult auth_type, void *user_data)
 {