File: getregkey.c

package info (click to toggle)
dpm-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,788 kB
  • ctags: 10,782
  • sloc: ansic: 146,136; sh: 13,362; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 955; fortran: 113
file content (87 lines) | stat: -rw-r--r-- 2,149 bytes parent folder | download | duplicates (8)
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
/*
 * Copyright (C) 1990-1999 by CERN IT-PDP/IP
 * All rights reserved
 */

#ifndef lint
static char sccsid[] =  "@(#)$RCSfile: getregkey.c,v $ $Revision: 1.1 $ $Date: 2005/04/13 17:00:29 $ CERN IT-PDP/IP Aneta Baran";
#endif /* not lint */

/* getregkey.c - get registry key value (equivalent of getconfent())              */
#if defined(_WIN32)
#include <windows.h>
#include "syslog.h"
#include "log.h"

#undef DEBUG

/* It is assumed that SHIFT configuration resides at HKEY_LOCAL_MACHINE\Software\Shift.
   The subkeys have names identical to the categories in shift.conf. Parameters category
   and name are the same as those used in getconfent() call. */ 

#define REG_KEY_NAME "Software\\Shift"

__declspec(thread) static char value[80];

char *getregkey(category, name)
char *category;
char *name;
{
   int	rcode;
   HKEY	key_handle;
   char value_name[80];
   int	name_size, value_size;
   int 	n;
   char key_name[80];
   int 	found = 0;

   openlog("rfiod", LOG_DEBUG, LOG_DAEMON);

   sprintf(key_name, "%s\\%s", REG_KEY_NAME, category);
#ifdef DEBUG 
   log(LOG_DEBUG, "getregkey(%s, %s)\n", category, name );
   log(LOG_DEBUG, "getregkey: opening key %s\n", key_name);
#endif /* DEBUG */ 

/* open the key to enumerate */
   rcode =  RegOpenKeyEx(HKEY_LOCAL_MACHINE, key_name, 0, KEY_QUERY_VALUE, &key_handle);
   if( rcode != ERROR_SUCCESS ) {
      log(LOG_ERR, "Unable to open registry key %s", key_name);
      return NULL;
   }
#ifdef DEBUG 
   log(LOG_DEBUG, "Searching for value name %s\n", name);
#endif
   n = 0;
   do {
      name_size = value_size = 80;
      rcode = RegEnumValue(key_handle, n, value_name, &name_size, NULL, NULL, value, &value_size);
      if( rcode == ERROR_SUCCESS )  {
	 if( strcmp(name, value_name) == 0 ) {
#ifdef DEBUG 
	    log(LOG_DEBUG, "Value %s = %s found in registry", value_name, value);
#endif
	    found = 1;
	 }
	 n++; 
      }
   }  while( rcode == ERROR_SUCCESS && !found );

   rcode = RegCloseKey(key_handle);
   if( rcode != ERROR_SUCCESS )  {
      log(LOG_ERR, "Unable to close registry key %s", key_name );
   }
   if( found ) return value;
   else return NULL;
}
#endif