Merge 13831:14550 from trunk
[reactos.git] / reactos / lib / dnsapi / dnsapi / context.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/dnsapi/dnsapi/context.c
5 * PURPOSE: DNSAPI functions built on the ADNS library.
6 * PROGRAMER: Art Yerkes
7 * UPDATE HISTORY:
8 * 12/15/03 -- Created
9 */
10
11 #include <windows.h>
12 #include <winerror.h>
13 #include <windns.h>
14 #define NTOS_MODE_USER
15 #include <ntos.h>
16 #include <internal/windns.h>
17
18 /* DnsAcquireContextHandle *************
19 * Create a context handle that will allow us to open and retrieve queries.
20 *
21 * DWORD CredentialsFlags -- TRUE -- Unicode
22 * FALSE -- Ansi or UTF-8?
23 *
24 * PVOID Credentials -- Pointer to a SEC_WINNT_AUTH_IDENTITY
25 * TODO: Use it.
26 *
27 * PHANDLE ContextHandle -- Pointer to a HANDLE that will receive
28 * our context pointer.
29 *
30 * RETURNS:
31 * ERROR_SUCCESS or a failure code.
32 * TODO: Which ones area allowed?
33 */
34
35 extern DNS_STATUS WINAPI DnsAcquireContextHandle_UTF8
36 ( DWORD CredentialsFlags,
37 PVOID Credentials,
38 HANDLE *ContextHandle );
39
40 DNS_STATUS WINAPI DnsAcquireContextHandle_W
41 ( DWORD CredentialsFlags,
42 PVOID Credentials,
43 HANDLE *ContextHandle ) {
44 if( CredentialsFlags ) {
45 PWINDNS_CONTEXT Context;
46 int adns_status;
47
48 /* For now, don't worry about the user's identity. */
49 Context = (PWINDNS_CONTEXT)RtlAllocateHeap( RtlGetProcessHeap(), 0,
50 sizeof( WINDNS_CONTEXT ) );
51 /* The real work here is to create an adns_state that will help us
52 * do what we want to later. */
53 adns_status = adns_init( &Context->State,
54 adns_if_noenv |
55 adns_if_noerrprint |
56 adns_if_noserverwarn,
57 0 );
58 if( adns_status != adns_s_ok ) {
59 *ContextHandle = 0;
60 return DnsIntTranslateAdnsToDNS_STATUS( adns_status );
61 } else {
62 *ContextHandle = (HANDLE)Context;
63 return ERROR_SUCCESS;
64 }
65 } else {
66 return DnsAcquireContextHandle_UTF8( CredentialsFlags,
67 Credentials,
68 ContextHandle );
69 }
70 }
71
72 DNS_STATUS WINAPI DnsAcquireContextHandle_UTF8
73 ( DWORD CredentialsFlags,
74 PVOID Credentials,
75 HANDLE *ContextHandle ) {
76 if( CredentialsFlags ) {
77 return DnsAcquireContextHandle_W( CredentialsFlags,
78 Credentials,
79 ContextHandle );
80 } else {
81 /* Convert to unicode, then call the _W version
82 * For now, there is no conversion */
83 DNS_STATUS Status;
84
85 Status = DnsAcquireContextHandle_W( TRUE,
86 Credentials, /* XXX arty */
87 ContextHandle );
88
89 /* Free the unicode credentials when they exist. */
90
91 return Status;
92 }
93 }
94
95 DNS_STATUS WINAPI DnsAcquireContextHandle_A
96 ( DWORD CredentialFlags,
97 PVOID Credentials,
98 HANDLE *ContextHandle ) {
99 if( CredentialFlags ) {
100 return DnsAcquireContextHandle_W( CredentialFlags,
101 Credentials,
102 ContextHandle );
103 } else {
104 return DnsAcquireContextHandle_UTF8( CredentialFlags,
105 Credentials,
106 ContextHandle );
107 }
108 }
109 /* DnsReleaseContextHandle *************
110 * Release a context handle, freeing all resources.
111 */
112
113 void WINAPI DnsReleaseContextHandle
114 ( HANDLE ContextHandle ) {
115 PWINDNS_CONTEXT Context = (PWINDNS_CONTEXT)ContextHandle;
116 adns_finish( Context->State );
117 RtlFreeHeap( RtlGetProcessHeap(), 0, Context );
118 }
119