[114] | 1 |
|
---|
| 2 | /*
|
---|
| 3 | *@@sourcefile lan.c:
|
---|
| 4 | * LAN helpers.
|
---|
| 5 | *
|
---|
| 6 | * Usage: All OS/2 programs.
|
---|
| 7 | *
|
---|
| 8 | * Function prefixes (new with V0.81):
|
---|
| 9 | * -- nls* LAN helpers
|
---|
| 10 | *
|
---|
| 11 | * This file is new with 0.9.16.
|
---|
| 12 | *
|
---|
| 13 | * Note: Version numbering in this file relates to XWorkplace version
|
---|
| 14 | * numbering.
|
---|
| 15 | *
|
---|
| 16 | *@@header "helpers\nls.h"
|
---|
| 17 | *@@added V0.9.16 (2001-10-19) [umoeller]
|
---|
| 18 | */
|
---|
| 19 |
|
---|
| 20 | /*
|
---|
| 21 | * Copyright (C) 2001 Ulrich Mller.
|
---|
| 22 | * This file is part of the "XWorkplace helpers" source package.
|
---|
| 23 | * This is free software; you can redistribute it and/or modify
|
---|
| 24 | * it under the terms of the GNU General Public License as published
|
---|
| 25 | * by the Free Software Foundation, in version 2 as it comes in the
|
---|
| 26 | * "COPYING" file of the XWorkplace main distribution.
|
---|
| 27 | * This program is distributed in the hope that it will be useful,
|
---|
| 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 30 | * GNU General Public License for more details.
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | #define OS2EMX_PLAIN_CHAR
|
---|
| 34 | // this is needed for "os2emx.h"; if this is defined,
|
---|
| 35 | // emx will define PSZ as _signed_ char, otherwise
|
---|
| 36 | // as unsigned char
|
---|
| 37 |
|
---|
| 38 | #define INCL_DOS
|
---|
| 39 | #include <os2.h>
|
---|
| 40 |
|
---|
[229] | 41 | // #define PURE_32
|
---|
| 42 | // #include <neterr.h>
|
---|
| 43 | // #include <netcons.h>
|
---|
| 44 | // #include <server.h>
|
---|
[114] | 45 |
|
---|
| 46 | #include <stdlib.h>
|
---|
| 47 | #include <stdio.h>
|
---|
| 48 | #include <string.h>
|
---|
| 49 |
|
---|
| 50 | #include "setup.h" // code generation and debugging options
|
---|
| 51 |
|
---|
| 52 | #include "helpers\dosh.h"
|
---|
| 53 | #include "helpers\lan.h"
|
---|
| 54 | #include "helpers\standards.h"
|
---|
| 55 |
|
---|
| 56 | #pragma hdrstop
|
---|
| 57 |
|
---|
| 58 | /*
|
---|
| 59 | *@@category: Helpers\Network helpers
|
---|
| 60 | * See lan.c.
|
---|
| 61 | */
|
---|
| 62 |
|
---|
| 63 | /* ******************************************************************
|
---|
| 64 | *
|
---|
| 65 | * Prototypes
|
---|
| 66 | *
|
---|
| 67 | ********************************************************************/
|
---|
| 68 |
|
---|
[229] | 69 | #define API32_FUNCTION APIRET APIENTRY
|
---|
| 70 |
|
---|
| 71 | typedef API32_FUNCTION NET32WKSTAGETINFO(PCSZ pszServer,
|
---|
[114] | 72 | unsigned long ulLevel,
|
---|
[229] | 73 | PBYTE pbBuffer,
|
---|
[114] | 74 | unsigned long ulBuffer,
|
---|
| 75 | unsigned long *pulTotalAvail);
|
---|
| 76 |
|
---|
[229] | 77 | typedef API32_FUNCTION NET32SERVERENUM2(PCSZ pszServer,
|
---|
[114] | 78 | unsigned long ulLevel,
|
---|
[229] | 79 | PBYTE pbBuffer,
|
---|
[114] | 80 | unsigned long cbBuffer,
|
---|
| 81 | unsigned long *pcEntriesRead,
|
---|
| 82 | unsigned long *pcTotalAvail,
|
---|
| 83 | unsigned long flServerType,
|
---|
[229] | 84 | PBYTE pszDomain);
|
---|
[114] | 85 |
|
---|
[229] | 86 | typedef API32_FUNCTION NET32SERVICESTATUS(PCSZ pbBuffer,
|
---|
| 87 | unsigned long ulBuffer);
|
---|
| 88 |
|
---|
| 89 | typedef API32_FUNCTION NET32SERVICEGETINFO(PCSZ pszServer,
|
---|
| 90 | PCSZ pszService,
|
---|
| 91 | unsigned long ulLevel,
|
---|
| 92 | PBYTE pbBuffer,
|
---|
| 93 | unsigned long ulBuffer,
|
---|
| 94 | unsigned long *pulTotalAvail);
|
---|
| 95 |
|
---|
| 96 | typedef API32_FUNCTION NET32SERVICECONTROL(PCSZ pszServer,
|
---|
| 97 | PCSZ pszService,
|
---|
| 98 | unsigned short usOpcode,
|
---|
| 99 | unsigned short usArg,
|
---|
| 100 | PBYTE pbBuffer,
|
---|
| 101 | unsigned long ulBuffer);
|
---|
| 102 |
|
---|
| 103 | typedef API32_FUNCTION NET32SERVICEINSTALL(PCSZ pszServer,
|
---|
| 104 | PCSZ pszService,
|
---|
| 105 | PCSZ pszCmdArgs,
|
---|
| 106 | PBYTE pbBuffer,
|
---|
| 107 | unsigned long ulBuffer);
|
---|
| 108 |
|
---|
[114] | 109 | /* ******************************************************************
|
---|
| 110 | *
|
---|
| 111 | * Globals
|
---|
| 112 | *
|
---|
| 113 | ********************************************************************/
|
---|
| 114 |
|
---|
| 115 | HMODULE hmodLan = NULLHANDLE;
|
---|
| 116 |
|
---|
| 117 | NET32WKSTAGETINFO *pNet32WkstaGetInfo = NULL;
|
---|
| 118 | NET32SERVERENUM2 *pNet32ServerEnum2 = NULL;
|
---|
[229] | 119 | NET32SERVICESTATUS *pNet32ServiceStatus = NULL;
|
---|
| 120 | NET32SERVICEGETINFO *pNet32ServiceGetInfo = NULL;
|
---|
| 121 | NET32SERVICECONTROL *pNet32ServiceControl = NULL;
|
---|
| 122 | NET32SERVICEINSTALL *pNet32ServiceInstall = NULL;
|
---|
[114] | 123 |
|
---|
| 124 | RESOLVEFUNCTION NetResolves[] =
|
---|
| 125 | {
|
---|
| 126 | "Net32WkstaGetInfo", (PFN*)&pNet32WkstaGetInfo,
|
---|
[229] | 127 | "Net32ServerEnum2", (PFN*)&pNet32ServerEnum2,
|
---|
| 128 | "Net32ServiceStatus", (PFN*)&pNet32ServiceStatus,
|
---|
| 129 | "Net32ServiceGetInfo", (PFN*)&pNet32ServiceGetInfo,
|
---|
| 130 | "Net32ServiceControl", (PFN*)&pNet32ServiceControl,
|
---|
| 131 | "Net32ServiceInstall", (PFN*)&pNet32ServiceInstall,
|
---|
[114] | 132 | };
|
---|
| 133 |
|
---|
[222] | 134 | STATIC ULONG G_ulNetsResolved = -1; // -1 == not init'd
|
---|
[114] | 135 | // 0 == success
|
---|
| 136 | // APIRET == failure
|
---|
| 137 |
|
---|
| 138 | /*
|
---|
| 139 | *@@ lanInit:
|
---|
[229] | 140 | * initializes the LAN server interface.
|
---|
[114] | 141 | *
|
---|
[229] | 142 | * Returns:
|
---|
| 143 | *
|
---|
| 144 | * -- NO_ERROR: functions resolved successfully,
|
---|
| 145 | * engine is ready.
|
---|
| 146 | *
|
---|
| 147 | * or the error codes from doshResolveImports.
|
---|
[114] | 148 | */
|
---|
| 149 |
|
---|
| 150 | APIRET lanInit(VOID)
|
---|
| 151 | {
|
---|
| 152 | if (G_ulNetsResolved == -1)
|
---|
| 153 | {
|
---|
| 154 | G_ulNetsResolved = doshResolveImports("NETAPI32", // \MUGLIB\DLL
|
---|
| 155 | &hmodLan,
|
---|
| 156 | NetResolves,
|
---|
| 157 | ARRAYITEMCOUNT(NetResolves));
|
---|
| 158 | }
|
---|
| 159 |
|
---|
[229] | 160 | return G_ulNetsResolved;
|
---|
[114] | 161 | }
|
---|
| 162 |
|
---|
| 163 | /*
|
---|
| 164 | *@@ lanQueryServers:
|
---|
| 165 | * returns an array of SERVER structures describing
|
---|
| 166 | * the servers which are available from this computer.
|
---|
| 167 | *
|
---|
| 168 | * With PEER, this should return the peers, assuming
|
---|
| 169 | * that remote IBMLAN.INI's do not contain "srvhidden = yes".
|
---|
| 170 | *
|
---|
| 171 | * If NO_ERROR is returned, the caller should free()
|
---|
| 172 | * the returned array
|
---|
| 173 | */
|
---|
| 174 |
|
---|
| 175 | APIRET lanQueryServers(PSERVER *paServers, // out: array of SERVER structs
|
---|
| 176 | ULONG *pcServers) // out: array item count (NOT array size)
|
---|
| 177 | {
|
---|
| 178 | APIRET arc;
|
---|
[229] | 179 |
|
---|
[114] | 180 | if (!(arc = lanInit()))
|
---|
| 181 | {
|
---|
| 182 | ULONG ulEntriesRead = 0,
|
---|
| 183 | cTotalAvail = 0;
|
---|
| 184 | PSERVER pBuf;
|
---|
| 185 | ULONG cb = 4096; // set this fixed, can't get it to work otherwise
|
---|
[116] | 186 | if (pBuf = (PSERVER)doshMalloc(cb,
|
---|
| 187 | &arc))
|
---|
[114] | 188 | {
|
---|
| 189 | if (!(arc = pNet32ServerEnum2(NULL,
|
---|
| 190 | 1, // ulLevel
|
---|
[229] | 191 | (PBYTE)pBuf, // pbBuffer
|
---|
[114] | 192 | cb, // cbBuffer,
|
---|
| 193 | &ulEntriesRead, // *pcEntriesRead,
|
---|
| 194 | &cTotalAvail, // *pcTotalAvail,
|
---|
| 195 | SV_TYPE_ALL, // all servers
|
---|
| 196 | NULL))) // pszDomain == all domains
|
---|
| 197 | {
|
---|
| 198 | *pcServers = ulEntriesRead;
|
---|
| 199 | *paServers = pBuf;
|
---|
| 200 | }
|
---|
| 201 | else
|
---|
| 202 | free(pBuf);
|
---|
| 203 | }
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | printf(__FUNCTION__ ": arc %d\n", arc);
|
---|
| 207 |
|
---|
[167] | 208 | return arc;
|
---|
[114] | 209 | }
|
---|
| 210 |
|
---|
[229] | 211 | /*
|
---|
| 212 | *@@ lanServiceGetInfo:
|
---|
| 213 | * queries the given service.
|
---|
| 214 | *
|
---|
[257] | 215 | * If NO_ERROR is returned,
|
---|
| 216 | +
|
---|
| 217 | + SERVICEBUF.svci2_status & SERVICE_INSTALL_STATE
|
---|
| 218 | +
|
---|
| 219 | * can be queried for the service state, which should
|
---|
| 220 | * be one of the following:
|
---|
| 221 | *
|
---|
| 222 | * -- SERVICE_UNINSTALLED: not running. For the
|
---|
| 223 | * REQUESTER service, this is only a theoretical
|
---|
| 224 | * value because without it, NERR_WkstaNotStarted
|
---|
| 225 | * (2138) is returned.
|
---|
| 226 | *
|
---|
| 227 | * -- SERVICE_INSTALL_PENDING: start in progress
|
---|
| 228 | *
|
---|
| 229 | * -- SERVICE_UNINSTALL_PENDING: stop in progress
|
---|
| 230 | *
|
---|
| 231 | * -- SERVICE_INSTALLED: running
|
---|
| 232 | *
|
---|
| 233 | * Alternatively, call lanServiceControl with the
|
---|
| 234 | * SERVICE_CTRL_INTERROGATE code, which actually asks the
|
---|
| 235 | * service.
|
---|
| 236 | *
|
---|
| 237 | * Returns, among others:
|
---|
| 238 | *
|
---|
| 239 | * -- NO_ERROR
|
---|
| 240 | *
|
---|
| 241 | * -- NERR_WkstaNotStarted (2138): requester is not
|
---|
| 242 | * running.
|
---|
| 243 | *
|
---|
| 244 | * -- NERR_ServiceNotInstalled: requested service is
|
---|
| 245 | * not running.
|
---|
| 246 | *
|
---|
[229] | 247 | *@@added V1.0.0 (2002-09-24) [umoeller]
|
---|
| 248 | */
|
---|
| 249 |
|
---|
| 250 | APIRET lanServiceGetInfo(PCSZ pcszServiceName,
|
---|
| 251 | PSERVICEBUF2 pBuf)
|
---|
| 252 | {
|
---|
| 253 | APIRET arc;
|
---|
| 254 |
|
---|
| 255 | if (!(arc = lanInit()))
|
---|
| 256 | {
|
---|
| 257 | ULONG ulBytesAvail = 0;
|
---|
| 258 | arc = pNet32ServiceGetInfo(NULL,
|
---|
| 259 | pcszServiceName,
|
---|
| 260 | 2, // level
|
---|
| 261 | (PBYTE)pBuf,
|
---|
| 262 | sizeof(SERVICEBUF2),
|
---|
| 263 | &ulBytesAvail);
|
---|
| 264 |
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | return arc;
|
---|
| 268 | }
|
---|
| 269 | /*
|
---|
| 270 | *@@ lanServiceInstall:
|
---|
| 271 | * starts the given service. The service name
|
---|
| 272 | * must be fully qualified so you cannot
|
---|
| 273 | * abbreviate "requester" with "req", for
|
---|
[257] | 274 | * example (as valid with the NET START command).
|
---|
[229] | 275 | *
|
---|
[257] | 276 | * The name of the service is found in the IBMLAN.INI file.
|
---|
| 277 | * The executable file name of the service is matched to a
|
---|
| 278 | * corresponding entry in the Services section of the
|
---|
| 279 | * IBMLAN.INI file. Any relative file path name supplied
|
---|
| 280 | * for a service is assumed to be relative to the LAN
|
---|
| 281 | * Server root directory (\IBMLAN).
|
---|
| 282 | *
|
---|
| 283 | * #Net32ServiceInstall supports a cmdargs argument, which
|
---|
| 284 | * is presently always passed as NULL with this implementation.
|
---|
| 285 | *
|
---|
[229] | 286 | * Returns, among others:
|
---|
| 287 | *
|
---|
| 288 | * -- NO_ERROR
|
---|
| 289 | *
|
---|
| 290 | * -- NERR_ServiceInstalled (2182): the service
|
---|
| 291 | * has already been started.
|
---|
| 292 | *
|
---|
| 293 | * -- NERR_BadServiceName (2185): invalid service
|
---|
| 294 | * name.
|
---|
| 295 | *
|
---|
| 296 | *@@added V1.0.0 (2002-09-24) [umoeller]
|
---|
| 297 | */
|
---|
| 298 |
|
---|
| 299 | APIRET lanServiceInstall(PCSZ pcszServiceName,
|
---|
| 300 | PSERVICEBUF2 pBuf2) // out: service data
|
---|
| 301 | {
|
---|
| 302 | APIRET arc;
|
---|
| 303 |
|
---|
| 304 | if (!(arc = lanInit()))
|
---|
| 305 | {
|
---|
| 306 | SERVICEBUF2 buf2;
|
---|
| 307 |
|
---|
| 308 | if (!(arc = pNet32ServiceInstall(NULL,
|
---|
| 309 | pcszServiceName,
|
---|
| 310 | NULL,
|
---|
| 311 | (PBYTE)pBuf2,
|
---|
| 312 | sizeof(SERVICEBUF2))))
|
---|
| 313 | ;
|
---|
| 314 | }
|
---|
| 315 |
|
---|
| 316 | return arc;
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | /*
|
---|
| 320 | *@@ lanServiceControl:
|
---|
[257] | 321 | * queries, pauses, resumes, or stops the given service. This
|
---|
| 322 | * has the functionality of the NET STOP command.
|
---|
[229] | 323 | *
|
---|
| 324 | * opcode must be one of:
|
---|
| 325 | *
|
---|
| 326 | * -- SERVICE_CTRL_INTERROGATE (0): interrogate service status.
|
---|
[257] | 327 | * This is similar to running lanServiceGetInfo, except
|
---|
| 328 | * that this one actually asks the service for its status,
|
---|
| 329 | * while lanServiceGetInfo simply dumps the status last
|
---|
| 330 | * posted.
|
---|
[229] | 331 | *
|
---|
| 332 | * -- SERVICE_CTRL_PAUSE (1): pause service.
|
---|
| 333 | *
|
---|
| 334 | * -- SERVICE_CTRL_CONTINUE (2): continue service.
|
---|
| 335 | *
|
---|
| 336 | * -- SERVICE_CTRL_UNINSTALL (3): stop service.
|
---|
| 337 | *
|
---|
| 338 | *@@added V1.0.0 (2002-09-24) [umoeller]
|
---|
| 339 | */
|
---|
| 340 |
|
---|
| 341 | APIRET lanServiceControl(PCSZ pcszServiceName,
|
---|
| 342 | ULONG opcode,
|
---|
| 343 | PSERVICEBUF2 pBuf2) // out: service data
|
---|
| 344 | {
|
---|
| 345 | APIRET arc;
|
---|
| 346 |
|
---|
| 347 | if (!(arc = lanInit()))
|
---|
| 348 | {
|
---|
| 349 | if (!(arc = pNet32ServiceControl(NULL,
|
---|
| 350 | pcszServiceName,
|
---|
| 351 | opcode,
|
---|
| 352 | 0,
|
---|
| 353 | (PBYTE)pBuf2,
|
---|
| 354 | sizeof(SERVICEBUF2))))
|
---|
| 355 | ;
|
---|
| 356 |
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | return arc;
|
---|
| 360 | }
|
---|
| 361 |
|
---|
[114] | 362 | #ifdef __LAN_TEST__
|
---|
| 363 |
|
---|
| 364 | int main(void)
|
---|
| 365 | {
|
---|
| 366 | ULONG ul;
|
---|
| 367 |
|
---|
| 368 | PSERVER paServers;
|
---|
| 369 | ULONG cServers;
|
---|
| 370 | lanQueryServers(&paServers, &cServers);
|
---|
| 371 |
|
---|
| 372 | for (ul = 0;
|
---|
| 373 | ul < cServers;
|
---|
| 374 | ul++)
|
---|
| 375 | {
|
---|
| 376 | printf("Server %d: \\\\%s (%s)\n",
|
---|
| 377 | ul,
|
---|
| 378 | paServers[ul].achServerName,
|
---|
| 379 | paServers[ul].pszComment);
|
---|
| 380 | }
|
---|
| 381 |
|
---|
| 382 | return 0;
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | #endif
|
---|
| 386 |
|
---|