Ignore:
Timestamp:
Aug 18, 2000, 4:01:27 AM (25 years ago)
Author:
phaller
Message:

Synchronized shell32 with wine

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/shell32/shpolicy.cpp

    r3243 r4032  
    1 /* $Id: shpolicy.cpp,v 1.2 2000-03-26 16:34:55 cbratschi Exp $ */
     1/* $Id: shpolicy.cpp,v 1.3 2000-08-18 02:01:26 phaller Exp $ */
    22
    33/*
     
    3535#include <string.h>
    3636
     37#include "windef.h"
     38#include "wingdi.h"
     39#include "winerror.h"
     40#include "winreg.h"
     41#include "debugtools.h"
    3742#include "wine/winuser16.h"
    38 #include "shpolicy.h"
     43
     44#define SHELL_MAX_POLICIES 57
     45
     46#define SHELL_NO_POLICY 0xffffffff
     47
     48typedef struct tagPOLICYDAT
     49{
     50  DWORD polflags;        /* flags value passed to SHRestricted */
     51  LPSTR appstr;          /* application str such as "Explorer" */
     52  LPSTR keystr;          /* name of the actual registry key / policy */
     53  DWORD cache;           /* cached value or 0xffffffff for invalid */
     54} POLICYDATA, *LPPOLICYDATA;
     55
     56// #include "shpolicy.h" PH: Strange ... ?
    3957
    4058/* application strings */
     
    451469  }
    452470};
     471
     472/*************************************************************************
     473 * SHRestricted                         [SHELL32.100]
     474 *
     475 * walks through policy table, queries <app> key, <type> value, returns
     476 * queried (DWORD) value, and caches it between called to SHInitRestricted
     477 * to prevent unnecessary registry access.
     478 *
     479 * NOTES
     480 *     exported by ordinal
     481 *
     482 * REFERENCES:
     483 *     MS System Policy Editor
     484 *     98Lite 2.0 (which uses many of these policy keys) http://www.98lite.net/
     485 *     "The Windows 95 Registry", by John Woram, 1996 MIS: Press
     486 */
     487DWORD WINAPI SHRestricted (DWORD pol) {
     488        char regstr[256];
     489        HKEY    xhkey;
     490        DWORD   retval, polidx, i, datsize = 4;
     491
     492        TRACE("(%08lx)\n",pol);
     493
     494        polidx = -1;
     495
     496        /* scan to see if we know this policy ID */
     497        for (i = 0; i < SHELL_MAX_POLICIES; i++)
     498        {
     499             if (pol == sh32_policy_table[i].polflags)
     500             {
     501                 polidx = i;
     502                 break;
     503             }
     504        }
     505
     506        if (polidx == -1)
     507        {
     508            /* we don't know this policy, return 0 */
     509            TRACE("unknown policy: (%08lx)\n", pol);
     510                return 0;
     511        }
     512
     513        /* we have a known policy */
     514        strcpy(regstr, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\");
     515        strcat(regstr, sh32_policy_table[polidx].appstr);
     516
     517        /* first check if this policy has been cached, return it if so */
     518        if (sh32_policy_table[polidx].cache != SHELL_NO_POLICY)
     519        {
     520            return sh32_policy_table[polidx].cache;
     521        }
     522
     523        /* return 0 and don't set the cache if any registry errors occur */
     524        retval = 0;
     525        if (RegOpenKeyA(HKEY_CURRENT_USER, regstr, &xhkey) == ERROR_SUCCESS)
     526        {
     527            if (RegQueryValueExA(xhkey, sh32_policy_table[polidx].keystr, NULL, NULL, (LPBYTE)&retval, &datsize) == ERROR_SUCCESS)
     528            {
     529                sh32_policy_table[polidx].cache = retval;
     530            }
     531
     532        RegCloseKey(xhkey);
     533}
     534
     535        return retval;
     536}
     537
     538/*************************************************************************
     539 *      SHInitRestricted                         [SHELL32.244]
     540 *
     541 * Win98+ by-ordinal only routine called by Explorer and MSIE 4 and 5.
     542 * Inits the policy cache used by SHRestricted to avoid excess
     543 * registry access.
     544 *
     545 * INPUTS
     546 * Two inputs: one is a string or NULL.  If non-NULL the pointer
     547 * should point to a string containing the following exact text:
     548 * "Software\Microsoft\Windows\CurrentVersion\Policies".
     549 * The other input is unused.
     550 *
     551 * NOTES
     552 * If the input is non-NULL and does not point to a string containing
     553 * that exact text the routine will do nothing.
     554 *
     555 * If the text does match or the pointer is NULL, then the routine
     556 * will init SHRestricted()'s policy cache to all 0xffffffff and
     557 * returns 0xffffffff as well.
     558 *
     559 * I haven't yet run into anything calling this with inputs other than
     560 * (NULL, NULL), so I may have the inputs reversed.
     561 */
     562
     563BOOL WINAPI SHInitRestricted(LPSTR inpRegKey, LPSTR parm2)
     564{
     565     int i;
     566
     567     TRACE("(%p, %p)\n", inpRegKey, parm2);
     568
     569     /* first check - if input is non-NULL and points to the secret
     570        key string, then pass.  Otherwise return 0.
     571     */
     572
     573     if (inpRegKey != (LPSTR)NULL)
     574     {
     575         if (lstrcmpiA(inpRegKey, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies"))
     576         {
     577             /* doesn't match, fail */
     578             return 0;
     579         }
     580     }                               
     581
     582     /* check passed, init all policy cache entries with SHELL_NO_POLICY */
     583     for (i = 0; i < SHELL_MAX_POLICIES; i++)
     584     {
     585          sh32_policy_table[i].cache = SHELL_NO_POLICY;
     586     }
     587
     588     return SHELL_NO_POLICY;
     589}
Note: See TracChangeset for help on using the changeset viewer.