annotate listener.c @ 1882:2839daa507b3

set envvar SSH_PUBKEYINFO if authstate.pubkey_info contains information
author HansH111 <hans@atbas.org>
date Sun, 13 Mar 2022 17:38:38 +0000
parents ce3ce75a6e04
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
74
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
1 /*
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
2 * Dropbear SSH
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
3 *
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
4 * Copyright (c) 2002,2003 Matt Johnston
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
5 * All rights reserved.
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
6 *
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
8 * of this software and associated documentation files (the "Software"), to deal
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
9 * in the Software without restriction, including without limitation the rights
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
11 * copies of the Software, and to permit persons to whom the Software is
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
12 * furnished to do so, subject to the following conditions:
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
13 *
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
14 * The above copyright notice and this permission notice shall be included in
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
15 * all copies or substantial portions of the Software.
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
16 *
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
23 * SOFTWARE. */
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
24
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 #include "includes.h"
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 #include "listener.h"
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 #include "session.h"
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 #include "dbutil.h"
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29
13
db2c8e6fb284 Fixed stupid agentfwd error (using the listening FD, not the accepted on. gah)
Matt Johnston <matt@ucc.asn.au>
parents: 9
diff changeset
30 void listeners_initialise() {
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 /* just one slot to start with */
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 ses.listeners = (struct Listener**)m_malloc(sizeof(struct Listener*));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 ses.listensize = 1;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 ses.listeners[0] = NULL;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 void set_listener_fds(fd_set * readfds) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
41 unsigned int i, j;
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 struct Listener *listener;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 /* check each in turn */
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 for (i = 0; i < ses.listensize; i++) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 listener = ses.listeners[i];
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 if (listener != NULL) {
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
48 for (j = 0; j < listener->nsocks; j++) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
49 FD_SET(listener->socks[j], readfds);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
50 }
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1040
diff changeset
56 void handle_listeners(const fd_set * readfds) {
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
58 unsigned int i, j;
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 struct Listener *listener;
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
60 int sock;
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 /* check each in turn */
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 for (i = 0; i < ses.listensize; i++) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 listener = ses.listeners[i];
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 if (listener != NULL) {
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
66 for (j = 0; j < listener->nsocks; j++) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
67 sock = listener->socks[j];
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
68 if (FD_ISSET(sock, readfds)) {
63
dcc43965928f - A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
69 listener->acceptor(listener, sock);
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
70 }
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 }
74
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
74 } /* Woo brace matching */
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76
63
dcc43965928f - A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
77 /* acceptor(int fd, void* typedata) is a function to accept connections,
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 * cleanup(void* typedata) happens when cleaning up */
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1040
diff changeset
79 struct Listener* new_listener(const int socks[], unsigned int nsocks,
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
80 int type, void* typedata,
1460
58a74cb829b8 Pointer parameter could be declared as pointing to const (callback)
Francois Perrad <francois.perrad@gadz.org>
parents: 1459
diff changeset
81 void (*acceptor)(const struct Listener* listener, int sock),
58a74cb829b8 Pointer parameter could be declared as pointing to const (callback)
Francois Perrad <francois.perrad@gadz.org>
parents: 1459
diff changeset
82 void (*cleanup)(const struct Listener*)) {
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 unsigned int i, j;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 struct Listener *newlisten = NULL;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 /* try get a new structure to hold it */
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 for (i = 0; i < ses.listensize; i++) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 if (ses.listeners[i] == NULL) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 break;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 /* or create a new one */
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 if (i == ses.listensize) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 if (ses.listensize > MAX_LISTENERS) {
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 74
diff changeset
96 TRACE(("leave newlistener: too many already"))
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
97 for (j = 0; j < nsocks; j++) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
98 close(socks[i]);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
99 }
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 return NULL;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 ses.listeners = (struct Listener**)m_realloc(ses.listeners,
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 (ses.listensize+LISTENER_EXTEND_SIZE)
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 *sizeof(struct Listener*));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 ses.listensize += LISTENER_EXTEND_SIZE;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 for (j = i; j < ses.listensize; j++) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 ses.listeners[j] = NULL;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
114 for (j = 0; j < nsocks; j++) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
115 ses.maxfd = MAX(ses.maxfd, socks[j]);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
116 }
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 74
diff changeset
118 TRACE(("new listener num %d ", i))
13
db2c8e6fb284 Fixed stupid agentfwd error (using the listening FD, not the accepted on. gah)
Matt Johnston <matt@ucc.asn.au>
parents: 9
diff changeset
119
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120 newlisten = (struct Listener*)m_malloc(sizeof(struct Listener));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 newlisten->index = i;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122 newlisten->type = type;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 newlisten->typedata = typedata;
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
124 newlisten->nsocks = nsocks;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
125 memcpy(newlisten->socks, socks, nsocks * sizeof(int));
63
dcc43965928f - A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
126 newlisten->acceptor = acceptor;
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127 newlisten->cleanup = cleanup;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129 ses.listeners[i] = newlisten;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130 return newlisten;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 /* Return the first listener which matches the type-specific comparison
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 * function. Particularly needed for global requests, like tcp */
1460
58a74cb829b8 Pointer parameter could be declared as pointing to const (callback)
Francois Perrad <francois.perrad@gadz.org>
parents: 1459
diff changeset
135 struct Listener * get_listener(int type, const void* typedata,
58a74cb829b8 Pointer parameter could be declared as pointing to const (callback)
Francois Perrad <francois.perrad@gadz.org>
parents: 1459
diff changeset
136 int (*match)(const void*, const void*)) {
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 unsigned int i;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139 struct Listener* listener;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141 for (i = 0, listener = ses.listeners[i]; i < ses.listensize; i++) {
1787
ce3ce75a6e04 Fix null pointer dereference removing listeners
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
142 if (listener && listener->type == type
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143 && match(typedata, listener->typedata)) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144 return listener;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
148 return NULL;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 void remove_listener(struct Listener* listener) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
153 unsigned int j;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
154
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155 if (listener->cleanup) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156 listener->cleanup(listener);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
157 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
159 for (j = 0; j < listener->nsocks; j++) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
160 close(listener->socks[j]);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
161 }
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162 ses.listeners[listener->index] = NULL;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163 m_free(listener);
1040
2b4fd440399d Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
164 }
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165
1040
2b4fd440399d Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
166 void remove_all_listeners(void) {
2b4fd440399d Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
167 unsigned int i;
2b4fd440399d Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
168 for (i = 0; i < ses.listensize; i++) {
2b4fd440399d Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
169 if (ses.listeners[i]) {
2b4fd440399d Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
170 remove_listener(ses.listeners[i]);
2b4fd440399d Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
171 }
2b4fd440399d Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
172 }
2b4fd440399d Free memory before exiting. Based on patch from Thorsten Horstmann.
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
173 m_free(ses.listeners);
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174 }