Free the debug info when making a critical section global.
[wine] / dlls / netapi32 / netapi32.c
1 /*
2  * Copyright 2001 Mike McCormack
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include "config.h"
20
21 #include <string.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #ifdef HAVE_UNISTD_H
25 # include <unistd.h>
26 #endif
27
28 #include "winbase.h"
29 #include "winreg.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "wine/debug.h"
33 #include "winerror.h"
34 #include "nb30.h"
35 #include "lmcons.h"
36 #include "iphlpapi.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(netbios);
39
40 HMODULE NETAPI32_hModule = 0;
41
42 static UCHAR NETBIOS_Enum(PNCB ncb)
43 {
44     int             i;
45     LANA_ENUM *lanas = (PLANA_ENUM) ncb->ncb_buffer;
46     DWORD apiReturn, size = 0;
47     PMIB_IFTABLE table;
48     UCHAR ret;
49  
50     TRACE("NCBENUM\n");
51  
52     apiReturn = GetIfTable(NULL, &size, FALSE);
53     if (apiReturn != NO_ERROR)
54       {
55         table = (PMIB_IFTABLE)malloc(size);
56         if (table)
57           {
58             apiReturn = GetIfTable(table, &size, FALSE);
59             if (apiReturn == NO_ERROR)
60               {
61                 lanas->length = 0;
62                 for (i = 0; i < table->dwNumEntries && lanas->length < MAX_LANA;
63                  i++)
64                   {
65                     if (table->table[i].dwType != MIB_IF_TYPE_LOOPBACK)
66                       {
67                         lanas->lana[lanas->length] = table->table[i].dwIndex;
68                         lanas->length++;
69                       }
70                   }
71                 ret = NRC_GOODRET;
72               }
73             else
74                 ret = NRC_SYSTEM;
75             free(table);
76           }
77         else
78             ret = NRC_NORESOURCES;
79       }
80     else
81         ret = NRC_SYSTEM;
82     return ret;
83 }
84
85
86 static UCHAR NETBIOS_Astat(PNCB ncb)
87 {
88     PADAPTER_STATUS astat = (PADAPTER_STATUS) ncb->ncb_buffer;
89     MIB_IFROW row;
90   
91     TRACE("NCBASTAT (Adapter %d)\n", ncb->ncb_lana_num);
92   
93     memset(astat, 0, sizeof astat);
94   
95     row.dwIndex = ncb->ncb_lana_num;
96     if (GetIfEntry(&row) != NO_ERROR)
97         return NRC_INVADDRESS;
98     /* doubt anyone cares, but why not.. */
99     if (row.dwType == MIB_IF_TYPE_TOKENRING)
100         astat->adapter_type = 0xff;
101     else
102         astat->adapter_type = 0xfe; /* for Ethernet */
103     return NRC_GOODRET;
104 }
105
106 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
107 {
108     TRACE("%p,%lx,%p\n", hinstDLL, fdwReason, lpvReserved);
109
110     switch (fdwReason) {
111         case DLL_PROCESS_ATTACH:
112             DisableThreadLibraryCalls(hinstDLL);
113             NETAPI32_hModule = hinstDLL;
114             break;
115         case DLL_PROCESS_DETACH:
116             break;
117     }
118
119     return TRUE;
120 }
121
122 BOOL WINAPI Netbios(PNCB pncb)
123 {
124     UCHAR ret = NRC_ILLCMD;
125
126     TRACE("ncb = %p\n",pncb);
127
128     if(!pncb)
129         return NRC_INVADDRESS;
130
131     switch(pncb->ncb_command&0x7f)
132     {
133     case NCBRESET:
134         FIXME("NCBRESET adapter %d\n",pncb->ncb_lana_num);
135         if(pncb->ncb_lana_num < MAX_LANA )
136           {
137             MIB_IFROW row;
138
139             row.dwIndex = pncb->ncb_lana_num;
140             if (GetIfEntry(&row) != NO_ERROR)
141                 ret = NRC_GOODRET;
142             else
143                 ret = NRC_ILLCMD; /* NetBIOS emulator not found */
144           }
145         else
146             ret = NRC_ILLCMD; /* NetBIOS emulator not found */
147         break;
148
149     case NCBADDNAME:
150         FIXME("NCBADDNAME\n");
151         break;
152
153     case NCBADDGRNAME:
154         FIXME("NCBADDGRNAME\n");
155         break;
156
157     case NCBDELNAME:
158         FIXME("NCBDELNAME\n");
159         break;
160
161     case NCBSEND:
162         FIXME("NCBSEND\n");
163         break;
164
165     case NCBRECV:
166         FIXME("NCBRECV\n");
167         break;
168
169     case NCBHANGUP:
170         FIXME("NCBHANGUP\n");
171         break;
172
173     case NCBCANCEL:
174         FIXME("NCBCANCEL\n");
175         break;
176
177     case NCBLISTEN:
178         FIXME("NCBLISTEN\n");
179         break;
180
181     case NCBASTAT:
182         ret = NETBIOS_Astat(pncb);
183         break;
184
185     case NCBENUM:
186         ret = NETBIOS_Enum(pncb);
187         break;
188
189     default:
190         FIXME("(%p): command code %02x\n", pncb, pncb->ncb_command);
191
192         ret = NRC_ILLCMD; /* NetBIOS emulator not found */
193     }
194     pncb->ncb_retcode = ret;
195     return ret;
196 }
197
198 NET_API_STATUS  WINAPI NetServerEnum(
199   LPCWSTR servername,
200   DWORD level,
201   LPBYTE* bufptr,
202   DWORD prefmaxlen,
203   LPDWORD entriesread,
204   LPDWORD totalentries,
205   DWORD servertype,
206   LPCWSTR domain,
207   LPDWORD resume_handle
208 )
209 {
210     FIXME("Stub (%p, %ld %p %ld %p %p %ld %s %p)\n",servername, level, bufptr,
211           prefmaxlen, entriesread, totalentries, servertype, debugstr_w(domain), resume_handle);
212
213     return ERROR_NO_BROWSER_SERVERS_FOUND;
214 }