| 1 |
|
|---|
| 2 | /*
|
|---|
| 3 | *@@sourcefile xsecapi.c:
|
|---|
| 4 | *
|
|---|
| 5 | *@@header "shared\xsecapi.h"
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | /*
|
|---|
| 9 | * Copyright (C) 2001-2003 Ulrich Mller.
|
|---|
| 10 | *
|
|---|
| 11 | * This file is part of the XWorkplace source package.
|
|---|
| 12 | * XWorkplace is free software; you can redistribute it and/or modify
|
|---|
| 13 | * it under the terms of the GNU General Public License as published
|
|---|
| 14 | * by the Free Software Foundation, in version 2 as it comes in the
|
|---|
| 15 | * "COPYING" file of the XWorkplace main distribution.
|
|---|
| 16 | * This program is distributed in the hope that it will be useful,
|
|---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 19 | * GNU General Public License for more details.
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | #pragma strings(readonly)
|
|---|
| 23 |
|
|---|
| 24 | /*
|
|---|
| 25 | * Suggested #include order:
|
|---|
| 26 | * 1) os2.h
|
|---|
| 27 | * 2) C library headers
|
|---|
| 28 | * 3) setup.h (code generation and debugging options)
|
|---|
| 29 | * 4) headers in helpers\
|
|---|
| 30 | * 5) at least one SOM implementation header (*.ih)
|
|---|
| 31 | * 6) dlgids.h, headers in shared\ (as needed)
|
|---|
| 32 | * 7) headers in implementation dirs (e.g. filesys\, as needed)
|
|---|
| 33 | * 8) #pragma hdrstop and then more SOM headers which crash with precompiled headers
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #define INCL_DOSPROCESS
|
|---|
| 37 | #define INCL_DOSSEMAPHORES
|
|---|
| 38 | #define INCL_DOSQUEUES
|
|---|
| 39 | #define INCL_DOSERRORS
|
|---|
| 40 | #include <os2.h>
|
|---|
| 41 |
|
|---|
| 42 | // C library headers
|
|---|
| 43 | #include <stdio.h>
|
|---|
| 44 |
|
|---|
| 45 | // generic headers
|
|---|
| 46 | #include "setup.h" // code generation and debugging options
|
|---|
| 47 |
|
|---|
| 48 | // headers in /helpers
|
|---|
| 49 | #include "helpers\standards.h" // some standard macros
|
|---|
| 50 | #include "helpers\stringh.h" // string helper routines
|
|---|
| 51 |
|
|---|
| 52 | // XWorkplace implementation headers
|
|---|
| 53 | #include "helpers\xwpsecty.h" // XWorkplace Security
|
|---|
| 54 |
|
|---|
| 55 | // other SOM headers
|
|---|
| 56 | #pragma hdrstop
|
|---|
| 57 |
|
|---|
| 58 | /* ******************************************************************
|
|---|
| 59 | *
|
|---|
| 60 | * Helpers
|
|---|
| 61 | *
|
|---|
| 62 | ********************************************************************/
|
|---|
| 63 |
|
|---|
| 64 | /*
|
|---|
| 65 | *@@ XWPSHELLCOMMAND:
|
|---|
| 66 | *
|
|---|
| 67 | *@@added V0.9.11 (2001-04-22) [umoeller]
|
|---|
| 68 | */
|
|---|
| 69 |
|
|---|
| 70 | typedef struct _XWPSHELLCOMMAND
|
|---|
| 71 | {
|
|---|
| 72 | PXWPSHELLQUEUEDATA pShared;
|
|---|
| 73 | PID pidXWPShell;
|
|---|
| 74 | HQUEUE hqXWPShell;
|
|---|
| 75 | } XWPSHELLCOMMAND, *PXWPSHELLCOMMAND;
|
|---|
| 76 |
|
|---|
| 77 | VOID FreeXWPShellCommand(PXWPSHELLCOMMAND pCommand);
|
|---|
| 78 |
|
|---|
| 79 | /*
|
|---|
| 80 | *@@ CreateXWPShellCommand:
|
|---|
| 81 | * creates a command for XWPShell to process.
|
|---|
| 82 | *
|
|---|
| 83 | * See XWPSHELLQUEUEDATA for a description of
|
|---|
| 84 | * what's going on here.
|
|---|
| 85 | *
|
|---|
| 86 | * ulCommand must be one of QUECMD_* values.
|
|---|
| 87 | *
|
|---|
| 88 | * If this returns NO_ERROR, the caller must
|
|---|
| 89 | * then fill in the shared data according to
|
|---|
| 90 | * what the command requires and use
|
|---|
| 91 | * SendXWPShellCommand then.
|
|---|
| 92 | *
|
|---|
| 93 | * Among others, this can return:
|
|---|
| 94 | *
|
|---|
| 95 | * -- ERROR_NOT_ENOUGH_MEMORY
|
|---|
| 96 | *
|
|---|
| 97 | * -- ERROR_QUE_NAME_NOT_EXIST (343): XWPShell queue
|
|---|
| 98 | * not found, XWPShell is probably not running.
|
|---|
| 99 | *
|
|---|
| 100 | *@@added V0.9.11 (2001-04-22) [umoeller]
|
|---|
| 101 | */
|
|---|
| 102 |
|
|---|
| 103 | APIRET CreateXWPShellCommand(ULONG ulCommand, // in: command
|
|---|
| 104 | PXWPSHELLCOMMAND *ppCommand) // out: cmd structure if NO_ERROR is returned
|
|---|
| 105 | {
|
|---|
| 106 | APIRET arc = NO_ERROR;
|
|---|
| 107 |
|
|---|
| 108 | PXWPSHELLCOMMAND pCommand;
|
|---|
| 109 | if (!(pCommand = NEW(XWPSHELLCOMMAND)))
|
|---|
| 110 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
|---|
| 111 | else
|
|---|
| 112 | {
|
|---|
| 113 | ZERO(pCommand);
|
|---|
| 114 |
|
|---|
| 115 | // check if XWPShell is running; if so the queue must exist
|
|---|
| 116 | if ( (!(arc = DosOpenQueue(&pCommand->pidXWPShell,
|
|---|
| 117 | &pCommand->hqXWPShell,
|
|---|
| 118 | QUEUE_XWPSHELL)))
|
|---|
| 119 | && (!(arc = DosAllocSharedMem((PVOID*)&pCommand->pShared,
|
|---|
| 120 | NULL, // unnamed
|
|---|
| 121 | sizeof(XWPSHELLQUEUEDATA),
|
|---|
| 122 | PAG_COMMIT | OBJ_GIVEABLE | PAG_READ | PAG_WRITE)))
|
|---|
| 123 | )
|
|---|
| 124 | {
|
|---|
| 125 | PXWPSHELLQUEUEDATA pShared = pCommand->pShared;
|
|---|
| 126 |
|
|---|
| 127 | if ( (!(arc = DosGiveSharedMem(pShared,
|
|---|
| 128 | pCommand->pidXWPShell,
|
|---|
| 129 | PAG_READ | PAG_WRITE)))
|
|---|
| 130 | && (!(arc = DosCreateEventSem(NULL,
|
|---|
| 131 | &pShared->hevData,
|
|---|
| 132 | DC_SEM_SHARED,
|
|---|
| 133 | FALSE))) // reset
|
|---|
| 134 | )
|
|---|
| 135 | {
|
|---|
| 136 | pShared->ulCommand = ulCommand;
|
|---|
| 137 | pShared->cbStruct = sizeof(XWPSHELLQUEUEDATA);
|
|---|
| 138 | }
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | if (!arc)
|
|---|
| 142 | *ppCommand = pCommand;
|
|---|
| 143 | else
|
|---|
| 144 | FreeXWPShellCommand(pCommand);
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | return arc;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | /*
|
|---|
| 151 | *@@ SendXWPShellCommand:
|
|---|
| 152 | * sends a command to XWPShell and waits for
|
|---|
| 153 | * the command to be processed.
|
|---|
| 154 | *
|
|---|
| 155 | * Be warned, this blocks the calling thread.
|
|---|
| 156 | * Even though XWPShell should be following
|
|---|
| 157 | * the PM 0.1 seconds rule in most cases,
|
|---|
| 158 | * some calls such as "create user" can be
|
|---|
| 159 | * expensive and you might want to start a
|
|---|
| 160 | * second thread for this.
|
|---|
| 161 | *
|
|---|
| 162 | * Returns:
|
|---|
| 163 | *
|
|---|
| 164 | * -- NO_ERROR: command written, and XWPShell
|
|---|
| 165 | * responded correctly.
|
|---|
| 166 | *
|
|---|
| 167 | * -- ERROR_TIMEOUT (640): XWPShell did not
|
|---|
| 168 | * respond within five seconds.
|
|---|
| 169 | *
|
|---|
| 170 | * -- XWPSEC_QUEUE_INVALID_CMD: XWPShell did
|
|---|
| 171 | * not recognize the given command code.
|
|---|
| 172 | *
|
|---|
| 173 | * -- XWPSEC_STRUCT_MISMATCH: sizeof XWPSHELLQUEUEDATA
|
|---|
| 174 | * does not match; probably a wrong version of
|
|---|
| 175 | * XWPShell is installed.
|
|---|
| 176 | *
|
|---|
| 177 | * -- XWPSEC_INTEGRITY: internal error in XWPShell.
|
|---|
| 178 | * Some data structure was corrupt, and this is
|
|---|
| 179 | * really a bug and should be fixed.
|
|---|
| 180 | *
|
|---|
| 181 | * plus the many command-specific XWPSEC_*
|
|---|
| 182 | * error codes.
|
|---|
| 183 | *
|
|---|
| 184 | *@@added V0.9.11 (2001-04-22) [umoeller]
|
|---|
| 185 | */
|
|---|
| 186 |
|
|---|
| 187 | APIRET SendXWPShellCommand(PXWPSHELLCOMMAND pCommand)
|
|---|
| 188 | {
|
|---|
| 189 | APIRET arc = NO_ERROR;
|
|---|
| 190 |
|
|---|
| 191 | if (!pCommand)
|
|---|
| 192 | arc = ERROR_INVALID_PARAMETER;
|
|---|
| 193 | else
|
|---|
| 194 | {
|
|---|
| 195 | if ( (!(arc = DosWriteQueue(pCommand->hqXWPShell,
|
|---|
| 196 | (ULONG)pCommand->pShared, // request data
|
|---|
| 197 | 0,
|
|---|
| 198 | NULL,
|
|---|
| 199 | 0))) // priority
|
|---|
| 200 | // wait 5 seconds for XWPShell to write the data
|
|---|
| 201 | && (!(arc = DosWaitEventSem(pCommand->pShared->hevData,
|
|---|
| 202 | 5*1000)))
|
|---|
| 203 | )
|
|---|
| 204 | {
|
|---|
| 205 | // return what XWPShell returns
|
|---|
| 206 | arc = pCommand->pShared->arc;
|
|---|
| 207 | }
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | return arc;
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | /*
|
|---|
| 214 | *@@ FreeXWPShellCommand:
|
|---|
| 215 | * cleans up.
|
|---|
| 216 | *
|
|---|
| 217 | *@@added V0.9.11 (2001-04-22) [umoeller]
|
|---|
| 218 | */
|
|---|
| 219 |
|
|---|
| 220 | VOID FreeXWPShellCommand(PXWPSHELLCOMMAND pCommand)
|
|---|
| 221 | {
|
|---|
| 222 | if (pCommand)
|
|---|
| 223 | {
|
|---|
| 224 | if (pCommand->pShared)
|
|---|
| 225 | {
|
|---|
| 226 | if (pCommand->pShared->hevData)
|
|---|
| 227 | DosCloseEventSem(pCommand->pShared->hevData);
|
|---|
| 228 |
|
|---|
| 229 | DosFreeMem(pCommand->pShared);
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | if (pCommand->hqXWPShell)
|
|---|
| 233 | DosCloseQueue(pCommand->hqXWPShell);
|
|---|
| 234 |
|
|---|
| 235 | free(pCommand);
|
|---|
| 236 | }
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | /* ******************************************************************
|
|---|
| 240 | *
|
|---|
| 241 | * XWPShell security APIs
|
|---|
| 242 | *
|
|---|
| 243 | ********************************************************************/
|
|---|
| 244 |
|
|---|
| 245 | /*
|
|---|
| 246 | *@@ xsecQueryStatus:
|
|---|
| 247 | * tests whether XWorkplace security is working and
|
|---|
| 248 | * returns ring-0 statistics.
|
|---|
| 249 | *
|
|---|
| 250 | + If this returns NO_ERROR, XWPShell is running
|
|---|
| 251 | * correctly. Check XWPSECSTATUS.fLocalSecurity to
|
|---|
| 252 | * learn whether the ring-0 driver is active also.
|
|---|
| 253 | *
|
|---|
| 254 | * Required authority: None.
|
|---|
| 255 | *
|
|---|
| 256 | * Command-specific error codes in addition to those
|
|---|
| 257 | * returned by CreateXWPShellCommand and
|
|---|
| 258 | * SendXWPShellCommand:
|
|---|
| 259 | *
|
|---|
| 260 | * -- none.
|
|---|
| 261 | *
|
|---|
| 262 | *@@added V1.0.1 (2003-01-05) [umoeller]
|
|---|
| 263 | */
|
|---|
| 264 |
|
|---|
| 265 | APIRET xsecQueryStatus(PXWPSECSTATUS pStatus) // out: ring-0 status (ptr can be null)
|
|---|
| 266 | {
|
|---|
| 267 | APIRET arc = NO_ERROR;
|
|---|
| 268 | PXWPSHELLCOMMAND pCommand;
|
|---|
| 269 |
|
|---|
| 270 | if (!(arc = CreateXWPShellCommand(QUECMD_QUERYSTATUS,
|
|---|
| 271 | &pCommand)))
|
|---|
| 272 | {
|
|---|
| 273 | if (!(arc = SendXWPShellCommand(pCommand)))
|
|---|
| 274 | if (pStatus)
|
|---|
| 275 | memcpy(pStatus,
|
|---|
| 276 | &pCommand->pShared->Data.Status,
|
|---|
| 277 | sizeof(pCommand->pShared->Data.Status));
|
|---|
| 278 |
|
|---|
| 279 | FreeXWPShellCommand(pCommand);
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 | return arc;
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | /*
|
|---|
| 286 | *@@ xsecQueryLocalUser:
|
|---|
| 287 | * returns info for the user who's currently
|
|---|
| 288 | * logged on locally, that is, the user who
|
|---|
| 289 | * owns the shell.
|
|---|
| 290 | *
|
|---|
| 291 | * Required authority: None.
|
|---|
| 292 | *
|
|---|
| 293 | * Command-specific error codes in addition to those
|
|---|
| 294 | * returned by CreateXWPShellCommand and
|
|---|
| 295 | * SendXWPShellCommand:
|
|---|
| 296 | *
|
|---|
| 297 | * -- XWPSEC_NO_LOCAL_USER: no user is currently
|
|---|
| 298 | * logged on locally (XWPShell is probably
|
|---|
| 299 | * displaying logon dialog).
|
|---|
| 300 | *
|
|---|
| 301 | *@@added V0.9.11 (2001-04-22) [umoeller]
|
|---|
| 302 | */
|
|---|
| 303 |
|
|---|
| 304 | APIRET xsecQueryLocalUser(PXWPUSERDBENTRY *ppLocalUser) // out: currently logged on user
|
|---|
| 305 | {
|
|---|
| 306 | APIRET arc = NO_ERROR;
|
|---|
| 307 | PXWPSHELLCOMMAND pCommand;
|
|---|
| 308 |
|
|---|
| 309 | if (!(arc = CreateXWPShellCommand(QUECMD_QUERYLOCALUSER,
|
|---|
| 310 | &pCommand)))
|
|---|
| 311 | {
|
|---|
| 312 | if (!(arc = SendXWPShellCommand(pCommand)))
|
|---|
| 313 | {
|
|---|
| 314 | // alright:
|
|---|
| 315 | PXWPUSERDBENTRY pLocal = pCommand->pShared->Data.pLocalUser;
|
|---|
| 316 | if (!(*ppLocalUser = (PXWPUSERDBENTRY)malloc(pLocal->cbStruct)))
|
|---|
| 317 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
|---|
| 318 | else
|
|---|
| 319 | memcpy(*ppLocalUser,
|
|---|
| 320 | pLocal,
|
|---|
| 321 | pLocal->cbStruct);
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 | FreeXWPShellCommand(pCommand);
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | return arc;
|
|---|
| 328 | }
|
|---|
| 329 |
|
|---|
| 330 | /*
|
|---|
| 331 | *@@ xsecQueryAllUsers:
|
|---|
| 332 | * returns an array of XWPUSERDBENTRY structs
|
|---|
| 333 | * with all the users currently in the userdb.
|
|---|
| 334 | *
|
|---|
| 335 | * Warning: The array items are variable in
|
|---|
| 336 | * size depending on group memberships, so
|
|---|
| 337 | * always use the cbStruct member of each
|
|---|
| 338 | * array item to climb to the next.
|
|---|
| 339 | *
|
|---|
| 340 | * Required authority: XWPPERM_QUERYUSERINFO.
|
|---|
| 341 | *
|
|---|
| 342 | * Command-specific error codes in addition to those
|
|---|
| 343 | * returned by CreateXWPShellCommand and
|
|---|
| 344 | * SendXWPShellCommand:
|
|---|
| 345 | *
|
|---|
| 346 | * -- XWPSEC_INSUFFICIENT_AUTHORITY
|
|---|
| 347 | *
|
|---|
| 348 | * plus the error codes from sudbQueryUsers.
|
|---|
| 349 | *
|
|---|
| 350 | *@@added V0.9.19 (2002-04-02) [umoeller]
|
|---|
| 351 | */
|
|---|
| 352 |
|
|---|
| 353 | APIRET xsecQueryAllUsers(PULONG pcUsers, // ou: array item count
|
|---|
| 354 | PXWPUSERDBENTRY *ppaUsers) // out: array of users (to be freed)
|
|---|
| 355 | {
|
|---|
| 356 | APIRET arc = NO_ERROR;
|
|---|
| 357 | PXWPSHELLCOMMAND pCommand;
|
|---|
| 358 |
|
|---|
| 359 | if (!(arc = CreateXWPShellCommand(QUECMD_QUERYUSERS,
|
|---|
| 360 | &pCommand)))
|
|---|
| 361 | {
|
|---|
| 362 | if (!(arc = SendXWPShellCommand(pCommand)))
|
|---|
| 363 | {
|
|---|
| 364 | // alright:
|
|---|
| 365 | // the array items are variable in size, so check
|
|---|
| 366 | ULONG ul,
|
|---|
| 367 | cbTotal = 0;
|
|---|
| 368 | PBYTE pbUserThis = (PBYTE)pCommand->pShared->Data.QueryUsers.paUsers;
|
|---|
| 369 | PXWPUSERDBENTRY paUsers;
|
|---|
| 370 | for (ul = 0;
|
|---|
| 371 | ul < pCommand->pShared->Data.QueryUsers.cUsers;
|
|---|
| 372 | ++ul)
|
|---|
| 373 | {
|
|---|
| 374 | ULONG cbThis = ((PXWPUSERDBENTRY)pbUserThis)->cbStruct;
|
|---|
| 375 | cbTotal += cbThis;
|
|---|
| 376 | pbUserThis += cbThis;
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | if (!(paUsers = malloc(cbTotal)))
|
|---|
| 380 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
|---|
| 381 | else
|
|---|
| 382 | {
|
|---|
| 383 | memcpy(paUsers,
|
|---|
| 384 | pCommand->pShared->Data.QueryUsers.paUsers,
|
|---|
| 385 | cbTotal);
|
|---|
| 386 | *pcUsers = pCommand->pShared->Data.QueryUsers.cUsers;
|
|---|
| 387 | *ppaUsers = paUsers;
|
|---|
| 388 | }
|
|---|
| 389 |
|
|---|
| 390 | // free shared mem given to us by XWPShell
|
|---|
| 391 | DosFreeMem(pCommand->pShared->Data.QueryUsers.paUsers);
|
|---|
| 392 | }
|
|---|
| 393 |
|
|---|
| 394 | FreeXWPShellCommand(pCommand);
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | return arc;
|
|---|
| 398 | }
|
|---|
| 399 |
|
|---|
| 400 | /*
|
|---|
| 401 | *@@ xsecQueryGroups:
|
|---|
| 402 | * returns an array of XWPGROUPDBENTRY structs
|
|---|
| 403 | * with all the groups currently in the userdb.
|
|---|
| 404 | *
|
|---|
| 405 | * Required authority: XWPPERM_QUERYUSERINFO.
|
|---|
| 406 | *
|
|---|
| 407 | * Command-specific error codes in addition to those
|
|---|
| 408 | * returned by CreateXWPShellCommand and
|
|---|
| 409 | * SendXWPShellCommand:
|
|---|
| 410 | *
|
|---|
| 411 | * -- XWPSEC_INSUFFICIENT_AUTHORITY
|
|---|
| 412 | *
|
|---|
| 413 | * plus the error codes from sudbQueryGroups.
|
|---|
| 414 | *
|
|---|
| 415 | *@@added V0.9.19 (2002-04-02) [umoeller]
|
|---|
| 416 | */
|
|---|
| 417 |
|
|---|
| 418 | APIRET xsecQueryGroups(PULONG pcGroups,
|
|---|
| 419 | PXWPGROUPDBENTRY *ppaGroups) // out: array of users (to be freed)
|
|---|
| 420 | {
|
|---|
| 421 | APIRET arc = NO_ERROR;
|
|---|
| 422 | PXWPSHELLCOMMAND pCommand;
|
|---|
| 423 |
|
|---|
| 424 | if (!(arc = CreateXWPShellCommand(QUECMD_QUERYGROUPS,
|
|---|
| 425 | &pCommand)))
|
|---|
| 426 | {
|
|---|
| 427 | if (!(arc = SendXWPShellCommand(pCommand)))
|
|---|
| 428 | {
|
|---|
| 429 | // alright:
|
|---|
| 430 | PXWPGROUPDBENTRY paGroups;
|
|---|
| 431 | ULONG cb = pCommand->pShared->Data.QueryGroups.cGroups
|
|---|
| 432 | * sizeof(XWPGROUPDBENTRY);
|
|---|
| 433 |
|
|---|
| 434 | if (!(paGroups = malloc(cb)))
|
|---|
| 435 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
|---|
| 436 | else
|
|---|
| 437 | {
|
|---|
| 438 | memcpy(paGroups,
|
|---|
| 439 | pCommand->pShared->Data.QueryGroups.paGroups,
|
|---|
| 440 | cb);
|
|---|
| 441 | *pcGroups = pCommand->pShared->Data.QueryGroups.cGroups;
|
|---|
| 442 | *ppaGroups = paGroups;
|
|---|
| 443 | }
|
|---|
| 444 |
|
|---|
| 445 | // free shared mem given to us by XWPShell
|
|---|
| 446 | DosFreeMem(pCommand->pShared->Data.QueryGroups.paGroups);
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | FreeXWPShellCommand(pCommand);
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 | return arc;
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | /*
|
|---|
| 456 | *@@ xsecQueryUserName:
|
|---|
| 457 | * convenience function that returns a single user name.
|
|---|
| 458 | *
|
|---|
| 459 | * Required authority: none. We consider plain user names
|
|---|
| 460 | * something not worth protecting.
|
|---|
| 461 | *
|
|---|
| 462 | *@@added V1.0.2 (2003-11-13) [umoeller]
|
|---|
| 463 | */
|
|---|
| 464 |
|
|---|
| 465 | APIRET xsecQueryUserName(XWPSECID uid, // in: user ID
|
|---|
| 466 | PSZ pszUserName) // out: user name (buffer must be XWPSEC_NAMELEN in size)
|
|---|
| 467 | {
|
|---|
| 468 | APIRET arc = NO_ERROR;
|
|---|
| 469 | PXWPSHELLCOMMAND pCommand;
|
|---|
| 470 |
|
|---|
| 471 | if (!(arc = CreateXWPShellCommand(QUECMD_QUERYUSERNAME,
|
|---|
| 472 | &pCommand)))
|
|---|
| 473 | {
|
|---|
| 474 | PQUEUEUNION pUnion = &pCommand->pShared->Data;
|
|---|
| 475 |
|
|---|
| 476 | pUnion->QueryUserName.uid = uid;
|
|---|
| 477 |
|
|---|
| 478 | if (!(arc = SendXWPShellCommand(pCommand)))
|
|---|
| 479 | strlcpy(pszUserName,
|
|---|
| 480 | pUnion->QueryUserName.szUserName,
|
|---|
| 481 | XWPSEC_NAMELEN);
|
|---|
| 482 |
|
|---|
| 483 | FreeXWPShellCommand(pCommand);
|
|---|
| 484 | }
|
|---|
| 485 |
|
|---|
| 486 | return arc;
|
|---|
| 487 | }
|
|---|
| 488 |
|
|---|
| 489 | /*
|
|---|
| 490 | *@@ xsecQueryProcessOwner:
|
|---|
| 491 | * returns the UID on whose behalf the given
|
|---|
| 492 | * process is running.
|
|---|
| 493 | *
|
|---|
| 494 | * Required authority: none.
|
|---|
| 495 | *
|
|---|
| 496 | * Command-specific error codes in addition to those
|
|---|
| 497 | * returned by CreateXWPShellCommand and
|
|---|
| 498 | * SendXWPShellCommand:
|
|---|
| 499 | *
|
|---|
| 500 | * -- XWPSEC_INSUFFICIENT_AUTHORITY
|
|---|
| 501 | *
|
|---|
| 502 | *@@added V0.9.19 (2002-04-02) [umoeller]
|
|---|
| 503 | */
|
|---|
| 504 |
|
|---|
| 505 | APIRET xsecQueryProcessOwner(USHORT pid, // in: process ID or 0 for caller
|
|---|
| 506 | XWPSECID *puid) // out: user ID
|
|---|
| 507 | {
|
|---|
| 508 | APIRET arc = NO_ERROR;
|
|---|
| 509 | PXWPSHELLCOMMAND pCommand;
|
|---|
| 510 |
|
|---|
| 511 | if (!(arc = CreateXWPShellCommand(QUECMD_QUERYPROCESSOWNER,
|
|---|
| 512 | &pCommand)))
|
|---|
| 513 | {
|
|---|
| 514 | PQUEUEUNION pUnion = &pCommand->pShared->Data;
|
|---|
| 515 |
|
|---|
| 516 | pUnion->QueryProcessOwner.pid = pid;
|
|---|
| 517 |
|
|---|
| 518 | if (!(arc = SendXWPShellCommand(pCommand)))
|
|---|
| 519 | *puid = pUnion->QueryProcessOwner.uid;
|
|---|
| 520 |
|
|---|
| 521 | FreeXWPShellCommand(pCommand);
|
|---|
| 522 | }
|
|---|
| 523 |
|
|---|
| 524 | return arc;
|
|---|
| 525 | }
|
|---|
| 526 |
|
|---|
| 527 | /*
|
|---|
| 528 | *@@ xsecCreateUser:
|
|---|
| 529 | * creates a new user in the user database.
|
|---|
| 530 | *
|
|---|
| 531 | * Required authority: XWPPERM_CREATEUSER.
|
|---|
| 532 | *
|
|---|
| 533 | * Command-specific error codes in addition to those
|
|---|
| 534 | * returned by CreateXWPShellCommand and
|
|---|
| 535 | * SendXWPShellCommand:
|
|---|
| 536 | *
|
|---|
| 537 | * -- ERROR_INVALID_PARAMETER
|
|---|
| 538 | *
|
|---|
| 539 | * -- ERROR_FILENAME_EXCED_RANGE: one of the given
|
|---|
| 540 | * strings is too long.
|
|---|
| 541 | *
|
|---|
| 542 | * -- XWPSEC_INSUFFICIENT_AUTHORITY
|
|---|
| 543 | *
|
|---|
| 544 | * -- XWPSEC_USER_EXISTS
|
|---|
| 545 | *
|
|---|
| 546 | *@@added V0.9.19 (2002-04-02) [umoeller]
|
|---|
| 547 | */
|
|---|
| 548 |
|
|---|
| 549 | APIRET xsecCreateUser(PCSZ pcszUserName, // in: user name
|
|---|
| 550 | PCSZ pcszFullName, // in: user's descriptive name
|
|---|
| 551 | PCSZ pcszPassword, // in: user's password
|
|---|
| 552 | XWPSECID gid, // in: group of the new user
|
|---|
| 553 | XWPSECID *puid) // out: user ID that was created
|
|---|
| 554 | {
|
|---|
| 555 | APIRET arc = NO_ERROR;
|
|---|
| 556 | PXWPSHELLCOMMAND pCommand;
|
|---|
| 557 |
|
|---|
| 558 | if (!(arc = CreateXWPShellCommand(QUECMD_CREATEUSER,
|
|---|
| 559 | &pCommand)))
|
|---|
| 560 | {
|
|---|
| 561 | PQUEUEUNION pUnion = &pCommand->pShared->Data;
|
|---|
| 562 |
|
|---|
| 563 | if ( (!(arc = strhCopyBuf(pUnion->CreateUser.szUserName,
|
|---|
| 564 | pcszUserName,
|
|---|
| 565 | sizeof(pUnion->CreateUser.szUserName))))
|
|---|
| 566 | && (!(arc = strhCopyBuf(pUnion->CreateUser.szFullName,
|
|---|
| 567 | pcszFullName,
|
|---|
| 568 | sizeof(pUnion->CreateUser.szFullName))))
|
|---|
| 569 | && (!(arc = strhCopyBuf(pUnion->CreateUser.szPassword,
|
|---|
| 570 | pcszPassword,
|
|---|
| 571 | sizeof(pUnion->CreateUser.szPassword))))
|
|---|
| 572 | && (!(arc = SendXWPShellCommand(pCommand)))
|
|---|
| 573 | )
|
|---|
| 574 | {
|
|---|
| 575 | // alright:
|
|---|
| 576 | *puid = pUnion->CreateUser.uidCreated;
|
|---|
| 577 | }
|
|---|
| 578 |
|
|---|
| 579 | FreeXWPShellCommand(pCommand);
|
|---|
| 580 | }
|
|---|
| 581 |
|
|---|
| 582 | return arc;
|
|---|
| 583 | }
|
|---|
| 584 |
|
|---|
| 585 | /*
|
|---|
| 586 | *@@ xsecSetUserData:
|
|---|
| 587 | * updates the user data for the given UID.
|
|---|
| 588 | *
|
|---|
| 589 | * Required authority: XWPPERM_CHANGEUSER.
|
|---|
| 590 | *
|
|---|
| 591 | * Command-specific error codes in addition to those
|
|---|
| 592 | * returned by CreateXWPShellCommand and
|
|---|
| 593 | * SendXWPShellCommand:
|
|---|
| 594 | *
|
|---|
| 595 | * -- ERROR_INVALID_PARAMETER
|
|---|
| 596 | *
|
|---|
| 597 | * -- ERROR_FILENAME_EXCED_RANGE: one of the given
|
|---|
| 598 | * strings is too long.
|
|---|
| 599 | *
|
|---|
| 600 | * -- XWPSEC_INSUFFICIENT_AUTHORITY
|
|---|
| 601 | *
|
|---|
| 602 | *@@added V1.0.1 (2003-01-05) [umoeller]
|
|---|
| 603 | */
|
|---|
| 604 |
|
|---|
| 605 | APIRET xsecSetUserData(XWPSECID uid,
|
|---|
| 606 | PCSZ pcszUserName,
|
|---|
| 607 | PCSZ pcszFullName)
|
|---|
| 608 | {
|
|---|
| 609 | APIRET arc = NO_ERROR;
|
|---|
| 610 | PXWPSHELLCOMMAND pCommand;
|
|---|
| 611 |
|
|---|
| 612 | if (!(arc = CreateXWPShellCommand(QUECMD_SETUSERDATA,
|
|---|
| 613 | &pCommand)))
|
|---|
| 614 | {
|
|---|
| 615 | PQUEUEUNION pUnion = &pCommand->pShared->Data;
|
|---|
| 616 |
|
|---|
| 617 | pUnion->SetUserData.uid = uid;
|
|---|
| 618 |
|
|---|
| 619 | if ( (!(arc = strhCopyBuf(pUnion->SetUserData.szUserName,
|
|---|
| 620 | pcszUserName,
|
|---|
| 621 | sizeof(pUnion->SetUserData.szUserName))))
|
|---|
| 622 | && (!(arc = strhCopyBuf(pUnion->SetUserData.szFullName,
|
|---|
| 623 | pcszFullName,
|
|---|
| 624 | sizeof(pUnion->SetUserData.szFullName))))
|
|---|
| 625 | && (!(arc = SendXWPShellCommand(pCommand)))
|
|---|
| 626 | )
|
|---|
| 627 | {
|
|---|
| 628 | }
|
|---|
| 629 |
|
|---|
| 630 | FreeXWPShellCommand(pCommand);
|
|---|
| 631 | }
|
|---|
| 632 |
|
|---|
| 633 | return arc;
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| 636 | /*
|
|---|
| 637 | *@@ xsecDeleteUser:
|
|---|
| 638 | * deletes the user account for the given UID.
|
|---|
| 639 | *
|
|---|
| 640 | * Required authority: XWPPERM_DELETEUSER.
|
|---|
| 641 | *
|
|---|
| 642 | * Command-specific error codes in addition to those
|
|---|
| 643 | * returned by CreateXWPShellCommand and
|
|---|
| 644 | * SendXWPShellCommand:
|
|---|
| 645 | *
|
|---|
| 646 | * -- XWPSEC_INSUFFICIENT_AUTHORITY
|
|---|
| 647 | *
|
|---|
| 648 | *@@added V1.0.1 (2003-01-05) [umoeller]
|
|---|
| 649 | */
|
|---|
| 650 |
|
|---|
| 651 | APIRET xsecDeleteUser(XWPSECID uid)
|
|---|
| 652 | {
|
|---|
| 653 | APIRET arc = NO_ERROR;
|
|---|
| 654 | PXWPSHELLCOMMAND pCommand;
|
|---|
| 655 |
|
|---|
| 656 | if (!(arc = CreateXWPShellCommand(QUECMD_DELETEUSER,
|
|---|
| 657 | &pCommand)))
|
|---|
| 658 | {
|
|---|
| 659 | PQUEUEUNION pUnion = &pCommand->pShared->Data;
|
|---|
| 660 |
|
|---|
| 661 | pUnion->uidDelete = uid;
|
|---|
| 662 |
|
|---|
| 663 | arc = SendXWPShellCommand(pCommand);
|
|---|
| 664 |
|
|---|
| 665 | FreeXWPShellCommand(pCommand);
|
|---|
| 666 | }
|
|---|
| 667 |
|
|---|
| 668 | return arc;
|
|---|
| 669 | }
|
|---|
| 670 |
|
|---|
| 671 | /*
|
|---|
| 672 | *@@ xsecQueryPermissions:
|
|---|
| 673 | * returns the permissions that the user on whose
|
|---|
| 674 | * behalf the calling process runs has on the
|
|---|
| 675 | * given resource. *pflAccess receives the ORed
|
|---|
| 676 | * XWPACCESS_* flags that represent these
|
|---|
| 677 | * permissions.
|
|---|
| 678 | *
|
|---|
| 679 | * This performs a full authorization on the given
|
|---|
| 680 | * resource according to the general authorization
|
|---|
| 681 | * rules.
|
|---|
| 682 | *
|
|---|
| 683 | * Required authority: none.
|
|---|
| 684 | *
|
|---|
| 685 | * Command-specific error codes in addition to those
|
|---|
| 686 | * returned by CreateXWPShellCommand and
|
|---|
| 687 | * SendXWPShellCommand:
|
|---|
| 688 | *
|
|---|
| 689 | * -- ERROR_INVALID_PARAMETER
|
|---|
| 690 | *
|
|---|
| 691 | * -- ERROR_FILENAME_EXCED_RANGE
|
|---|
| 692 | *
|
|---|
| 693 | *@@added V1.0.1 (2003-01-10) [umoeller]
|
|---|
| 694 | */
|
|---|
| 695 |
|
|---|
| 696 | APIRET xsecQueryPermissions(PCSZ pcszFilename,
|
|---|
| 697 | PULONG pflAccess)
|
|---|
| 698 | {
|
|---|
| 699 | APIRET arc = NO_ERROR;
|
|---|
| 700 | PXWPSHELLCOMMAND pCommand;
|
|---|
| 701 |
|
|---|
| 702 | if (!(arc = CreateXWPShellCommand(QUECMD_QUERYPERMISSIONS,
|
|---|
| 703 | &pCommand)))
|
|---|
| 704 | {
|
|---|
| 705 | PQUEUEUNION pUnion = &pCommand->pShared->Data;
|
|---|
| 706 |
|
|---|
| 707 | if ( (!(arc = strhCopyBuf(pUnion->QueryPermissions.szResource,
|
|---|
| 708 | pcszFilename,
|
|---|
| 709 | sizeof(pUnion->QueryPermissions.szResource))))
|
|---|
| 710 | && (!(arc = SendXWPShellCommand(pCommand)))
|
|---|
| 711 | )
|
|---|
| 712 | {
|
|---|
| 713 | *pflAccess = pUnion->QueryPermissions.flAccess;
|
|---|
| 714 | }
|
|---|
| 715 |
|
|---|
| 716 | FreeXWPShellCommand(pCommand);
|
|---|
| 717 | }
|
|---|
| 718 |
|
|---|
| 719 | return arc;
|
|---|
| 720 | }
|
|---|
| 721 |
|
|---|
| 722 | /*
|
|---|
| 723 | *@@ xsecSwitchUser:
|
|---|
| 724 | * switches the credentials for the current (calling)
|
|---|
| 725 | * process. This allows a process to switch to a different
|
|---|
| 726 | * user, for example to implement a "su" command, since
|
|---|
| 727 | * subprocesses started after the switch will inherit the
|
|---|
| 728 | * new credentials.
|
|---|
| 729 | *
|
|---|
| 730 | * Note that switching the user does not make the new
|
|---|
| 731 | * user a "local" user. Neither will switching users
|
|---|
| 732 | * adjust the environment of the current process; to
|
|---|
| 733 | * implement shell-like behavior, the caller must adjust
|
|---|
| 734 | * the environment variables such as "USER" and "HOME"
|
|---|
| 735 | * by itself.
|
|---|
| 736 | *
|
|---|
| 737 | * Required authority: none.
|
|---|
| 738 | *
|
|---|
| 739 | * Command-specific error codes in addition to those
|
|---|
| 740 | * returned by CreateXWPShellCommand and
|
|---|
| 741 | * SendXWPShellCommand:
|
|---|
| 742 | *
|
|---|
| 743 | * -- ERROR_INVALID_PARAMETER
|
|---|
| 744 | *
|
|---|
| 745 | * -- ERROR_FILENAME_EXCED_RANGE
|
|---|
| 746 | *
|
|---|
| 747 | * -- XWPSEC_NOT_AUTHENTICATED: pUserInfo->szUserName
|
|---|
| 748 | * is unknown, or pUserInfo->szPassword doesn't
|
|---|
| 749 | * match the entry in the userdb.
|
|---|
| 750 | *
|
|---|
| 751 | * If NO_ERROR is returned, the credentials of the current
|
|---|
| 752 | * process have been switched.
|
|---|
| 753 | */
|
|---|
| 754 |
|
|---|
| 755 | APIRET xsecSwitchUser(PCSZ pcszUserName,
|
|---|
| 756 | PCSZ pcszPassword)
|
|---|
| 757 | {
|
|---|
| 758 | APIRET arc = NO_ERROR;
|
|---|
| 759 | PXWPSHELLCOMMAND pCommand;
|
|---|
| 760 |
|
|---|
| 761 | if (!(arc = CreateXWPShellCommand(QUECMD_SWITCHUSER,
|
|---|
| 762 | &pCommand)))
|
|---|
| 763 | {
|
|---|
| 764 | PQUEUEUNION pUnion = &pCommand->pShared->Data;
|
|---|
| 765 |
|
|---|
| 766 | if ( (!(arc = strhCopyBuf(pUnion->SwitchUser.szUserName,
|
|---|
| 767 | pcszUserName,
|
|---|
| 768 | sizeof(pUnion->SwitchUser.szUserName))))
|
|---|
| 769 | && (!(arc = strhCopyBuf(pUnion->SwitchUser.szPassword,
|
|---|
| 770 | pcszPassword,
|
|---|
| 771 | sizeof(pUnion->SwitchUser.szPassword))))
|
|---|
| 772 | && (!(arc = SendXWPShellCommand(pCommand)))
|
|---|
| 773 | )
|
|---|
| 774 | {
|
|---|
| 775 |
|
|---|
| 776 | }
|
|---|
| 777 |
|
|---|
| 778 | FreeXWPShellCommand(pCommand);
|
|---|
| 779 | }
|
|---|
| 780 |
|
|---|
| 781 | return arc;
|
|---|
| 782 | }
|
|---|