summaryrefslogtreecommitdiffstats
path: root/ldap/libraries/libutil/ntreg.c
blob: 6c2a8f4e88fc7651dcb263d541c0dd281084a448 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/** BEGIN COPYRIGHT BLOCK
 * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
 * Copyright (C) 2005 Red Hat, Inc.
 * All rights reserved.
 * END COPYRIGHT BLOCK **/

#ifdef _WIN32

#include <windows.h>
#include <stdio.h>
#include "ldap.h"

int SlapdGetRegSZ( LPTSTR lpszRegKey, LPSTR lpszValueName, LPTSTR lpszValue )
{
	HKEY hKey;
	DWORD dwType, dwNumBytes;
	LONG lResult;

	/* Open the registry, get the required key handle. */	
	lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE, lpszRegKey, 
				0L,	KEY_QUERY_VALUE, &hKey );
	if (lResult == ERROR_SUCCESS) 
	{ 
		dwNumBytes = sizeof( DWORD );
		lResult = RegQueryValueEx( hKey, lpszValueName, 0, 
					&dwType, NULL, &dwNumBytes );
		if( lResult == ERROR_SUCCESS ) 
		{
			RegQueryValueEx( hKey, lpszValueName, 0, &dwType, 
							(LPBYTE)lpszValue, &dwNumBytes );
			*(lpszValue+dwNumBytes) = 0;

			/*  Close the Registry. */
			RegCloseKey(hKey);
			return 0;
		}
		else
		{
			/* No config file location stored in the Registry. */
			RegCloseKey(hKey);
			return 1;
		}
	}
	else
	{
  		return 1;
	}
}	/* SlapdGetRegSZ */


int SlapdSetRegSZ( LPTSTR lpszKey, LPSTR lpszValueName, LPTSTR lpszValue )
{
	HKEY hKey;
	LONG lResult;

	/* Open the registry, get a handle to the desired key. */	
	lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE, lpszKey, 0, 
				KEY_ALL_ACCESS, &hKey );
	if (lResult == ERROR_SUCCESS) 
	{ 
		/* Set the value to the value-name at the key location. */
		RegSetValueEx( hKey, lpszValueName, 0, REG_SZ, 
					   (CONST BYTE*)lpszValue, strlen(lpszValue) );

		/* Close the registry */
		RegCloseKey(hKey);
		return 0;
	} 
	else 
	{
		return 1;
	}
}	/* SlapdSetRegSZ */

/* converts '/' chars to '\' */
void
unixtodospath(char *szText)
{
    if(szText)
    {
        while(*szText)
        {
            if( *szText == '/' )
                *szText = '\\';
            szText++;
        }
    }
}

/* converts '\' chars to '/' */
void
dostounixpath(char *szText)
{
    if(szText)
    {
        while(*szText)
        {
            if( *szText == '\\' )
                *szText = '/';
            szText++;
        }
    }
}

#endif /* _WIN32 */