OSDN Git Service

am 43682d94: Fix a TOCTOU and symlink attack in netd.
[android-x86/system-netd.git] / DnsProxyListener.h
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef _DNSPROXYLISTENER_H__
18 #define _DNSPROXYLISTENER_H__
19
20 #include <sysutils/FrameworkListener.h>
21
22 #include "NetdCommand.h"
23
24 class DnsProxyListener : public FrameworkListener {
25 public:
26     DnsProxyListener();
27     virtual ~DnsProxyListener() {}
28
29 private:
30     class GetAddrInfoCmd : public NetdCommand {
31     public:
32         GetAddrInfoCmd();
33         virtual ~GetAddrInfoCmd() {}
34         int runCommand(SocketClient *c, int argc, char** argv);
35     };
36
37     class GetAddrInfoHandler {
38     public:
39         // Note: All of host, service, and hints may be NULL
40         GetAddrInfoHandler(SocketClient *c,
41                            char* host,
42                            char* service,
43                            struct addrinfo* hints)
44             : mClient(c),
45               mHost(host),
46               mService(service),
47               mHints(hints) {}
48         ~GetAddrInfoHandler();
49
50         static void* threadStart(void* handler);
51         void start();
52
53     private:
54         void run();
55         SocketClient* mClient;  // ref counted
56         char* mHost;    // owned
57         char* mService; // owned
58         struct addrinfo* mHints;  // owned
59     };
60
61     /* ------ gethostbyaddr ------*/
62     class GetHostByAddrCmd : public NetdCommand {
63     public:
64         GetHostByAddrCmd();
65         virtual ~GetHostByAddrCmd() {}
66         int runCommand(SocketClient *c, int argc, char** argv);
67     };
68
69     class GetHostByAddrHandler {
70     public:
71         GetHostByAddrHandler(SocketClient *c,
72                             void* address,
73                             int   addressLen,
74                             int   addressFamily)
75             : mClient(c),
76               mAddress(address),
77               mAddressLen(addressLen),
78               mAddressFamily(addressFamily) {}
79         ~GetHostByAddrHandler();
80
81         static void* threadStart(void* handler);
82         void start();
83
84     private:
85         void run();
86         SocketClient* mClient;  // ref counted
87         void* mAddress;    // address to lookup; owned
88         int   mAddressLen; // length of address to look up
89         int   mAddressFamily;  // address family
90     };
91 };
92
93 #endif