diff options
Diffstat (limited to 'networking/isrv_identd.c')
-rw-r--r-- | networking/isrv_identd.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c index a41405c33..252c8aba9 100644 --- a/networking/isrv_identd.c +++ b/networking/isrv_identd.c | |||
@@ -25,8 +25,7 @@ enum { TIMEOUT = 20 }; | |||
25 | 25 | ||
26 | typedef struct identd_buf_t { | 26 | typedef struct identd_buf_t { |
27 | int pos; | 27 | int pos; |
28 | int fd_flag; | 28 | char buf[64 - sizeof(int)]; |
29 | char buf[64 - 2*sizeof(int)]; | ||
30 | } identd_buf_t; | 29 | } identd_buf_t; |
31 | 30 | ||
32 | #define bogouser bb_common_bufsiz1 | 31 | #define bogouser bb_common_bufsiz1 |
@@ -42,7 +41,7 @@ static int new_peer(isrv_state_t *state, int fd) | |||
42 | if (isrv_register_fd(state, peer, fd) < 0) | 41 | if (isrv_register_fd(state, peer, fd) < 0) |
43 | return peer; /* failure, unregister peer */ | 42 | return peer; /* failure, unregister peer */ |
44 | 43 | ||
45 | buf->fd_flag = fcntl(fd, F_GETFL) | O_NONBLOCK; | 44 | ndelay_on(fd); |
46 | isrv_want_rd(state, fd); | 45 | isrv_want_rd(state, fd); |
47 | return 0; | 46 | return 0; |
48 | } | 47 | } |
@@ -51,19 +50,16 @@ static int do_rd(int fd, void **paramp) | |||
51 | { | 50 | { |
52 | identd_buf_t *buf = *paramp; | 51 | identd_buf_t *buf = *paramp; |
53 | char *cur, *p; | 52 | char *cur, *p; |
54 | int retval = 0; /* session is ok (so far) */ | ||
55 | int sz; | 53 | int sz; |
56 | 54 | ||
57 | cur = buf->buf + buf->pos; | 55 | cur = buf->buf + buf->pos; |
58 | 56 | ||
59 | if (buf->fd_flag & O_NONBLOCK) | 57 | sz = safe_read(fd, cur, sizeof(buf->buf) - 1 - buf->pos); |
60 | fcntl(fd, F_SETFL, buf->fd_flag); | ||
61 | sz = safe_read(fd, cur, sizeof(buf->buf) - buf->pos); | ||
62 | 58 | ||
63 | if (sz < 0) { | 59 | if (sz < 0) { |
64 | if (errno != EAGAIN) | 60 | if (errno != EAGAIN) |
65 | goto term; /* terminate this session if !EAGAIN */ | 61 | goto term; |
66 | goto ok; | 62 | return 0; /* "session is ok" */ |
67 | } | 63 | } |
68 | 64 | ||
69 | buf->pos += sz; | 65 | buf->pos += sz; |
@@ -71,19 +67,22 @@ static int do_rd(int fd, void **paramp) | |||
71 | p = strpbrk(cur, "\r\n"); | 67 | p = strpbrk(cur, "\r\n"); |
72 | if (p) | 68 | if (p) |
73 | *p = '\0'; | 69 | *p = '\0'; |
74 | if (!p && sz && buf->pos <= (int)sizeof(buf->buf)) | 70 | if (!p && sz) |
75 | goto ok; | 71 | return 0; /* "session is ok" */ |
72 | |||
76 | /* Terminate session. If we are in server mode, then | 73 | /* Terminate session. If we are in server mode, then |
77 | * fd is still in nonblocking mode - we never block here */ | 74 | * fd is still in nonblocking mode - we never block here */ |
78 | if (fd == 0) fd++; /* inetd mode? then write to fd 1 */ | 75 | if (fd == 0) |
76 | fd++; /* inetd mode? then write to fd 1 */ | ||
79 | fdprintf(fd, "%s : USERID : UNIX : %s\r\n", buf->buf, bogouser); | 77 | fdprintf(fd, "%s : USERID : UNIX : %s\r\n", buf->buf, bogouser); |
78 | /* | ||
79 | * Why bother if we are going to close fd now anyway? | ||
80 | * if (server) | ||
81 | * ndelay_off(fd); | ||
82 | */ | ||
80 | term: | 83 | term: |
81 | free(buf); | 84 | free(buf); |
82 | retval = 1; /* terminate */ | 85 | return 1; /* "terminate" */ |
83 | ok: | ||
84 | if (buf->fd_flag & O_NONBLOCK) | ||
85 | fcntl(fd, F_SETFL, buf->fd_flag & ~O_NONBLOCK); | ||
86 | return retval; | ||
87 | } | 86 | } |
88 | 87 | ||
89 | static int do_timeout(void **paramp UNUSED_PARAM) | 88 | static int do_timeout(void **paramp UNUSED_PARAM) |
@@ -95,10 +94,9 @@ static void inetd_mode(void) | |||
95 | { | 94 | { |
96 | identd_buf_t *buf = xzalloc(sizeof(*buf)); | 95 | identd_buf_t *buf = xzalloc(sizeof(*buf)); |
97 | /* buf->pos = 0; - xzalloc did it */ | 96 | /* buf->pos = 0; - xzalloc did it */ |
98 | /* We do NOT want nonblocking I/O here! */ | ||
99 | /* buf->fd_flag = 0; - xzalloc did it */ | ||
100 | do | 97 | do |
101 | alarm(TIMEOUT); | 98 | alarm(TIMEOUT); |
99 | /* Note: we do NOT want nonblocking I/O here! */ | ||
102 | while (do_rd(0, (void*)&buf) == 0); | 100 | while (do_rd(0, (void*)&buf) == 0); |
103 | } | 101 | } |
104 | 102 | ||
@@ -120,7 +118,7 @@ int fakeidentd_main(int argc UNUSED_PARAM, char **argv) | |||
120 | opt = getopt32(argv, "fiwb:", &bind_address); | 118 | opt = getopt32(argv, "fiwb:", &bind_address); |
121 | strcpy(bogouser, "nobody"); | 119 | strcpy(bogouser, "nobody"); |
122 | if (argv[optind]) | 120 | if (argv[optind]) |
123 | strncpy(bogouser, argv[optind], sizeof(bogouser)); | 121 | strncpy(bogouser, argv[optind], sizeof(bogouser) - 1); |
124 | 122 | ||
125 | /* Daemonize if no -f and no -i and no -w */ | 123 | /* Daemonize if no -f and no -i and no -w */ |
126 | if (!(opt & OPT_fiw)) | 124 | if (!(opt & OPT_fiw)) |