Software /
code /
prosody
Annotate
util-src/windows.c @ 2078:a5f154548154
util.sasl: Return proper error when client provides authzid.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Fri, 13 Nov 2009 04:24:17 +0500 |
parent | 2062:699686c8d016 |
child | 2923:b7049746bd29 |
rev | line source |
---|---|
2062
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 #include <stdio.h> |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 #include <windows.h> |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 #include <windns.h> |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 #include "lua.h" |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 #include "lauxlib.h" |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 static int Lget_nameservers(lua_State *L) { |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 char stack_buffer[1024]; // stack allocated buffer |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 IP4_ARRAY* ips = (IP4_ARRAY*) stack_buffer; |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 DWORD len = sizeof(stack_buffer); |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 DNS_STATUS status; |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 status = DnsQueryConfig(DnsConfigDnsServerList, FALSE, NULL, NULL, ips, &len); |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 if (status == 0) { |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 DWORD i; |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 lua_createtable(L, ips->AddrCount, 0); |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 for (i = 0; i < ips->AddrCount; i++) { |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 DWORD ip = ips->AddrArray[i]; |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 char ip_str[16] = ""; |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 sprintf_s(ip_str, sizeof(ip_str), "%d.%d.%d.%d", (ip >> 0) & 255, (ip >> 8) & 255, (ip >> 16) & 255, (ip >> 24) & 255); |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 lua_pushstring(L, ip_str); |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 lua_rawseti(L, -2, i+1); |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 } |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 return 1; |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 } else { |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 luaL_error(L, "DnsQueryConfig returned %d", status); |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 return 0; // unreachable, but prevents a compiler warning |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 } |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 } |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 static const luaL_Reg Reg[] = |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 { |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 { "get_nameservers", Lget_nameservers }, |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 { NULL, NULL } |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 }; |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 LUALIB_API int luaopen_util_windows(lua_State *L) { |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 luaL_register(L, "windows", Reg); |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 lua_pushliteral(L, "version"); /** version */ |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 lua_pushliteral(L, "-3.14"); |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 lua_settable(L,-3); |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 return 1; |
699686c8d016
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 } |