aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-11-22 10:31:36 +0100
committerChristian Grothoff <christian@grothoff.org>2018-11-22 10:31:36 +0100
commita9c5183b1b40792dff463b32b7e884e36a8ed5de (patch)
treea344bb49f7a3f9fbee3ca85cb94694890e4ac357 /src
parent8a039e9e8142bd95779fd8beb1b316be1a46668f (diff)
downloadgnunet-a9c5183b1b40792dff463b32b7e884e36a8ed5de.tar.gz
gnunet-a9c5183b1b40792dff463b32b7e884e36a8ed5de.zip
fixing #5437
Diffstat (limited to 'src')
-rw-r--r--src/gns/nss/nss_gns_query.c88
1 files changed, 57 insertions, 31 deletions
diff --git a/src/gns/nss/nss_gns_query.c b/src/gns/nss/nss_gns_query.c
index 032b2c93b..58c38323a 100644
--- a/src/gns/nss/nss_gns_query.c
+++ b/src/gns/nss/nss_gns_query.c
@@ -22,8 +22,23 @@
22#include <arpa/inet.h> 22#include <arpa/inet.h>
23#include <sys/types.h> 23#include <sys/types.h>
24#include <sys/socket.h> 24#include <sys/socket.h>
25#include <sys/wait.h>
25#include <netinet/in.h> 26#include <netinet/in.h>
26#include <errno.h> 27#include <errno.h>
28#include <unistd.h>
29#include <signal.h>
30
31
32static void
33kwait (pid_t chld)
34{
35 int ret;
36
37 kill (chld, SIGKILL);
38 waitpid (chld,
39 &ret,
40 0);
41}
27 42
28 43
29/** 44/**
@@ -44,36 +59,45 @@ gns_resolve_name (int af,
44 struct userdata *u) 59 struct userdata *u)
45{ 60{
46 FILE *p; 61 FILE *p;
47 char *cmd;
48 char line[128]; 62 char line[128];
49 int ret; 63 int ret;
50 int es; 64 int out[2];
65 pid_t pid;
51 66
52 if (AF_INET6 == af) 67 if (0 != pipe (out))
68 return -1;
69 pid = fork ();
70 if (-1 == pid)
71 return -1;
72 if (0 == pid)
53 { 73 {
54 if (-1 == asprintf (&cmd, 74 char *argv[] = {
55 "%s -t AAAA -u %s\n", 75 "gnunet-gns",
56 "gnunet-gns -r", 76 "-r",
57 name)) 77 "-t",
58 return -1; 78 (AF_INET6 == af) ? "AAAA" : "A",
79 "-u",
80 (char *) name,
81 NULL
82 };
83
84 (void) close (STDOUT_FILENO);
85 if ( (0 != close (out[0])) ||
86 (STDOUT_FILENO != dup2 (out[1], STDOUT_FILENO)) )
87 _exit (1);
88 (void) execvp ("gnunet-gns",
89 argv);
90 _exit (1);
59 } 91 }
60 else 92 (void) close (out[1]);
61 { 93 p = fdopen (out[0], "r");
62 if (-1 == asprintf (&cmd, 94 if (NULL == p)
63 "%s %s\n", 95 {
64 "gnunet-gns -r -u", 96 kwait (pid);
65 name))
66 return -1; 97 return -1;
67 } 98 }
68 if (NULL == (p = popen (cmd, "r")))
69 {
70 es = errno;
71 free (cmd);
72 errno = es;
73 return -1;
74 }
75 while (NULL != fgets (line, 99 while (NULL != fgets (line,
76 sizeof(line), 100 sizeof (line),
77 p)) 101 p))
78 { 102 {
79 if (u->count >= MAX_ENTRIES) 103 if (u->count >= MAX_ENTRIES)
@@ -92,8 +116,8 @@ gns_resolve_name (int af,
92 } 116 }
93 else 117 else
94 { 118 {
95 (void) pclose (p); 119 (void) fclose (p);
96 free (cmd); 120 kwait (pid);
97 errno = EINVAL; 121 errno = EINVAL;
98 return -1; 122 return -1;
99 } 123 }
@@ -109,19 +133,21 @@ gns_resolve_name (int af,
109 } 133 }
110 else 134 else
111 { 135 {
112 (void) pclose (p); 136 (void) fclose (p);
113 free (cmd); 137 kwait (pid);
114 errno = EINVAL; 138 errno = EINVAL;
115 return -1; 139 return -1;
116 } 140 }
117 } 141 }
118 } 142 }
119 } 143 }
120 ret = pclose (p); 144 (void) fclose (p);
121 free (cmd); 145 waitpid (pid,
122 if (! WIFEXITED (ret)) 146 &ret,
147 0);
148 if (! WIFEXITED (ret))
123 return -1; 149 return -1;
124 if (4 == WEXITSTATUS (ret)) 150 if (4 == WEXITSTATUS (ret))
125 return -2; /* not for GNS */ 151 return -2; /* not for GNS */
126 if (3 == ret) 152 if (3 == ret)
127 return -3; /* timeout -> not found */ 153 return -3; /* timeout -> not found */