2 * Registry processing routines. Routines, common for registry
3 * processing frontends.
5 * Copyright 1999 Sylvain St-Germain
6 * Copyright 2002 Andriy Palamarchuk
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #define REG_VAL_BUF_SIZE 4096
33 /* maximal number of characters in hexadecimal data line,
34 not including '\' character */
35 #define REG_FILE_HEX_LINE_LEN 76
37 static const CHAR
*reg_class_names
[] = {
38 "HKEY_LOCAL_MACHINE", "HKEY_USERS", "HKEY_CLASSES_ROOT",
39 "HKEY_CURRENT_CONFIG", "HKEY_CURRENT_USER", "HKEY_DYN_DATA"
42 #define REG_CLASS_NUMBER (sizeof(reg_class_names) / sizeof(reg_class_names[0]))
44 static HKEY reg_class_keys
[REG_CLASS_NUMBER
] = {
45 HKEY_LOCAL_MACHINE
, HKEY_USERS
, HKEY_CLASSES_ROOT
,
46 HKEY_CURRENT_CONFIG
, HKEY_CURRENT_USER
, HKEY_DYN_DATA
50 #define NOT_ENOUGH_MEMORY 1
53 /* processing macros */
55 /* common check of memory allocation results */
56 #define CHECK_ENOUGH_MEMORY(p) \
59 fprintf(stderr,"%s: file %s, line %d: Not enough memory\n", \
60 getAppName(), __FILE__, __LINE__); \
61 exit(NOT_ENOUGH_MEMORY); \
64 /******************************************************************************
65 * Converts a hex representation of a DWORD into a DWORD.
67 static BOOL
convertHexToDWord(char* str
, DWORD
*dw
)
70 if (strlen(str
) > 8 || sscanf(str
, "%x%c", dw
, &dummy
) != 1) {
71 fprintf(stderr
,"%s: ERROR, invalid hex value\n", getAppName());
77 /******************************************************************************
78 * Converts a hex comma separated values list into a binary string.
80 static BYTE
* convertHexCSVToHex(char *str
, DWORD
*size
)
85 /* The worst case is 1 digit + 1 comma per byte */
86 *size
=(strlen(str
)+1)/2;
87 data
=HeapAlloc(GetProcessHeap(), 0, *size
);
88 CHECK_ENOUGH_MEMORY(data
);
97 if (s
[1] != ',' && s
[1] != '\0' && s
[2] != ',' && s
[2] != '\0') {
98 fprintf(stderr
,"%s: ERROR converting CSV hex stream. Invalid sequence at '%s'\n",
100 HeapFree(GetProcessHeap(), 0, data
);
103 if (sscanf(s
, "%x%c", &wc
, &dummy
) < 1 || dummy
!= ',') {
104 fprintf(stderr
,"%s: ERROR converting CSV hex stream. Invalid value at '%s'\n",
106 HeapFree(GetProcessHeap(), 0, data
);
112 /* Skip one or two digits and any comma */
113 while (*s
&& *s
!=',') s
++;
120 /******************************************************************************
121 * This function returns the HKEY associated with the data type encoded in the
122 * value. It modifies the input parameter (key value) in order to skip this
123 * "now useless" data type information.
125 * Note: Updated based on the algorithm used in 'server/registry.c'
127 static DWORD
getDataType(LPSTR
*lpValue
, DWORD
* parse_type
)
129 struct data_type
{ const char *tag
; int len
; int type
; int parse_type
; };
131 static const struct data_type data_types
[] = { /* actual type */ /* type to assume for parsing */
132 { "\"", 1, REG_SZ
, REG_SZ
},
133 { "str:\"", 5, REG_SZ
, REG_SZ
},
134 { "str(2):\"", 8, REG_EXPAND_SZ
, REG_SZ
},
135 { "hex:", 4, REG_BINARY
, REG_BINARY
},
136 { "dword:", 6, REG_DWORD
, REG_DWORD
},
137 { "hex(", 4, -1, REG_BINARY
},
141 const struct data_type
*ptr
;
144 for (ptr
= data_types
; ptr
->tag
; ptr
++) {
145 if (memcmp( ptr
->tag
, *lpValue
, ptr
->len
))
149 *parse_type
= ptr
->parse_type
;
154 /* "hex(xx):" is special */
155 type
= (int)strtoul( *lpValue
, &end
, 16 );
156 if (**lpValue
=='\0' || *end
!=')' || *(end
+1)!=':') {
164 *parse_type
=REG_NONE
;
168 /******************************************************************************
169 * Replaces escape sequences with the characters.
171 static void REGPROC_unescape_string(LPSTR str
)
173 int str_idx
= 0; /* current character under analysis */
174 int val_idx
= 0; /* the last character of the unescaped string */
175 int len
= strlen(str
);
176 for (str_idx
= 0; str_idx
< len
; str_idx
++, val_idx
++) {
177 if (str
[str_idx
] == '\\') {
179 switch (str
[str_idx
]) {
185 str
[val_idx
] = str
[str_idx
];
188 fprintf(stderr
,"Warning! Unrecognized escape sequence: \\%c'\n",
190 str
[val_idx
] = str
[str_idx
];
194 str
[val_idx
] = str
[str_idx
];
200 /******************************************************************************
201 * Parses HKEY_SOME_ROOT\some\key\path to get the root key handle and
202 * extract the key path (what comes after the first '\').
204 static BOOL
parseKeyName(LPSTR lpKeyName
, HKEY
*hKey
, LPSTR
*lpKeyPath
)
209 if (lpKeyName
== NULL
)
212 lpSlash
= strchr(lpKeyName
, '\\');
215 len
= lpSlash
-lpKeyName
;
219 len
= strlen(lpKeyName
);
220 lpSlash
= lpKeyName
+len
;
223 for (i
= 0; i
< REG_CLASS_NUMBER
; i
++) {
224 if (strncmp(lpKeyName
, reg_class_names
[i
], len
) == 0 &&
225 len
== strlen(reg_class_names
[i
])) {
226 *hKey
= reg_class_keys
[i
];
233 if (*lpSlash
!= '\0')
235 *lpKeyPath
= lpSlash
;
239 /* Globals used by the setValue() & co */
240 static LPSTR currentKeyName
;
241 static HKEY currentKeyHandle
= NULL
;
243 /******************************************************************************
244 * Sets the value with name val_name to the data in val_data for the currently
248 * val_name - name of the registry value
249 * val_data - registry value data
251 static LONG
setValue(LPSTR val_name
, LPSTR val_data
)
254 DWORD dwDataType
, dwParseType
;
258 if ( (val_name
== NULL
) || (val_data
== NULL
) )
259 return ERROR_INVALID_PARAMETER
;
261 if (strcmp(val_data
, "-") == 0)
263 res
=RegDeleteValue(currentKeyHandle
,val_name
);
264 return (res
== ERROR_FILE_NOT_FOUND
? ERROR_SUCCESS
: res
);
267 /* Get the data type stored into the value field */
268 dwDataType
= getDataType(&val_data
, &dwParseType
);
270 if (dwParseType
== REG_SZ
) /* no conversion for string */
272 REGPROC_unescape_string(val_data
);
273 /* Compute dwLen after REGPROC_unescape_string because it may
274 * have changed the string length and we don't want to store
275 * the extra garbage in the registry.
277 dwLen
= strlen(val_data
);
278 if (dwLen
>0 && val_data
[dwLen
-1]=='"')
281 val_data
[dwLen
]='\0';
283 lpbData
= (BYTE
*) val_data
;
285 else if (dwParseType
== REG_DWORD
) /* Convert the dword types */
287 if (!convertHexToDWord(val_data
, &dwData
))
288 return ERROR_INVALID_DATA
;
289 lpbData
= (BYTE
*)&dwData
;
290 dwLen
= sizeof(dwData
);
292 else if (dwParseType
== REG_BINARY
) /* Convert the binary data */
294 lpbData
= convertHexCSVToHex(val_data
, &dwLen
);
296 return ERROR_INVALID_DATA
;
298 else /* unknown format */
300 fprintf(stderr
,"%s: ERROR, unknown data format\n", getAppName());
301 return ERROR_INVALID_DATA
;
311 if (dwParseType
== REG_BINARY
)
312 HeapFree(GetProcessHeap(), 0, lpbData
);
316 /******************************************************************************
317 * A helper function for processRegEntry() that opens the current key.
318 * That key must be closed by calling closeKey().
320 static LONG
openKey(LPSTR stdInput
)
328 if (stdInput
== NULL
)
329 return ERROR_INVALID_PARAMETER
;
331 /* Get the registry class */
332 if (!parseKeyName(stdInput
, &keyClass
, &keyPath
))
333 return ERROR_INVALID_PARAMETER
;
335 res
= RegCreateKeyEx(
336 keyClass
, /* Class */
337 keyPath
, /* Sub Key */
339 NULL
, /* object type */
340 REG_OPTION_NON_VOLATILE
, /* option, REG_OPTION_NON_VOLATILE ... */
341 KEY_ALL_ACCESS
, /* access mask, KEY_ALL_ACCESS */
342 NULL
, /* security attribute */
343 ¤tKeyHandle
, /* result */
344 &dwDisp
); /* disposition, REG_CREATED_NEW_KEY or
345 REG_OPENED_EXISTING_KEY */
347 if (res
== ERROR_SUCCESS
)
349 currentKeyName
= HeapAlloc(GetProcessHeap(), 0, strlen(stdInput
)+1);
350 CHECK_ENOUGH_MEMORY(currentKeyName
);
351 strcpy(currentKeyName
, stdInput
);
355 currentKeyHandle
= NULL
;
362 /******************************************************************************
363 * Close the currently opened key.
365 static void closeKey(void)
367 if (currentKeyHandle
)
369 HeapFree(GetProcessHeap(), 0, currentKeyName
);
370 RegCloseKey(currentKeyHandle
);
371 currentKeyHandle
= NULL
;
375 /******************************************************************************
376 * This function is a wrapper for the setValue function. It prepares the
377 * land and cleans the area once completed.
378 * Note: this function modifies the line parameter.
380 * line - registry file unwrapped line. Should have the registry value name and
381 * complete registry value data.
383 static void processSetValue(LPSTR line
)
385 LPSTR val_name
; /* registry value name */
386 LPSTR val_data
; /* registry value data */
388 int line_idx
= 0; /* current character under analysis */
392 if (line
[line_idx
] == '@' && line
[line_idx
+ 1] == '=') {
393 line
[line_idx
] = '\0';
396 } else if (line
[line_idx
] == '\"') {
398 val_name
= line
+ line_idx
;
400 if (line
[line_idx
] == '\\') /* skip escaped character */
404 if (line
[line_idx
] == '\"') {
405 line
[line_idx
] = '\0';
413 if (line
[line_idx
] != '=') {
414 line
[line_idx
] = '\"';
415 fprintf(stderr
,"Warning! unrecognized line:\n%s\n", line
);
420 fprintf(stderr
,"Warning! unrecognized line:\n%s\n", line
);
423 line_idx
++; /* skip the '=' character */
424 val_data
= line
+ line_idx
;
426 REGPROC_unescape_string(val_name
);
427 res
= setValue(val_name
, val_data
);
428 if ( res
!= ERROR_SUCCESS
)
429 fprintf(stderr
,"%s: ERROR Key %s not created. Value: %s, Data: %s\n",
436 /******************************************************************************
437 * This function receives the currently read entry and performs the
438 * corresponding action.
440 static void processRegEntry(LPSTR stdInput
)
443 * We encountered the end of the file, make sure we
444 * close the opened key and exit
446 if (stdInput
== NULL
) {
451 if ( stdInput
[0] == '[') /* We are reading a new key */
454 closeKey(); /* Close the previous key */
456 /* Get rid of the square brackets */
458 keyEnd
= strrchr(stdInput
, ']');
462 /* delete the key if we encounter '-' at the start of reg key */
463 if ( stdInput
[0] == '-')
464 delete_registry_key(stdInput
+1);
465 else if ( openKey(stdInput
) != ERROR_SUCCESS
)
466 fprintf(stderr
,"%s: setValue failed to open key %s\n",
467 getAppName(), stdInput
);
468 } else if( currentKeyHandle
&&
469 (( stdInput
[0] == '@') || /* reading a default @=data pair */
470 ( stdInput
[0] == '\"'))) /* reading a new value=data pair */
472 processSetValue(stdInput
);
475 /* Since we are assuming that the file format is valid we must be
476 * reading a blank line which indicates the end of this key processing
482 /******************************************************************************
483 * Processes a registry file.
484 * Correctly processes comments (in # form), line continuation.
487 * in - input stream to read from
489 void processRegLines(FILE *in
)
491 LPSTR line
= NULL
; /* line read from input stream */
492 ULONG lineSize
= REG_VAL_BUF_SIZE
;
494 line
= HeapAlloc(GetProcessHeap(), 0, lineSize
);
495 CHECK_ENOUGH_MEMORY(line
);
498 LPSTR s
; /* The pointer into line for where the current fgets should read */
501 size_t size_remaining
;
503 char *s_eol
; /* various local uses */
505 /* Do we need to expand the buffer ? */
506 assert (s
>= line
&& s
<= line
+ lineSize
);
507 size_remaining
= lineSize
- (s
-line
);
508 if (size_remaining
< 2) /* room for 1 character and the \0 */
511 size_t new_size
= lineSize
+ REG_VAL_BUF_SIZE
;
512 if (new_size
> lineSize
) /* no arithmetic overflow */
513 new_buffer
= HeapReAlloc (GetProcessHeap(), 0, line
, new_size
);
516 CHECK_ENOUGH_MEMORY(new_buffer
);
518 s
= line
+ lineSize
- size_remaining
;
520 size_remaining
= lineSize
- (s
-line
);
523 /* Get as much as possible into the buffer, terminated either by
524 * eof, error, eol or getting the maximum amount. Abort on error.
526 size_to_get
= (size_remaining
> INT_MAX
? INT_MAX
: size_remaining
);
527 if (NULL
== fgets (s
, size_to_get
, in
)) {
529 perror ("While reading input");
534 /* It is not clear to me from the definition that the
535 * contents of the buffer are well defined on detecting
536 * an eof without managing to read anything.
541 /* If we didn't read the eol nor the eof go around for the rest */
542 s_eol
= strchr (s
, '\n');
543 if (!feof (in
) && !s_eol
) {
544 s
= strchr (s
, '\0');
545 /* It should be s + size_to_get - 1 but this is safer */
549 /* If it is a comment line then discard it and go around again */
550 if (line
[0] == '#') {
555 /* Remove any line feed. Leave s_eol on the \0 */
558 if (s_eol
> line
&& *(s_eol
-1) == '\r')
561 s_eol
= strchr (s
, '\0');
563 /* If there is a concatenating \\ then go around again */
564 if (s_eol
> line
&& *(s_eol
-1) == '\\') {
567 /* The following error protection could be made more self-
568 * correcting but I thought it not worth trying.
570 if ((c
= fgetc (in
)) == EOF
|| c
!= ' ' ||
571 (c
= fgetc (in
)) == EOF
|| c
!= ' ')
572 fprintf(stderr
,"%s: ERROR - invalid continuation.\n",
577 break; /* That is the full virtual line */
580 processRegEntry(line
);
582 processRegEntry(NULL
);
584 HeapFree(GetProcessHeap(), 0, line
);
587 /****************************************************************************
588 * REGPROC_print_error
590 * Print the message for GetLastError
593 static void REGPROC_print_error(void)
599 error_code
= GetLastError ();
600 status
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
601 NULL
, error_code
, 0, (LPTSTR
) &lpMsgBuf
, 0, NULL
);
603 fprintf(stderr
,"%s: Cannot display message for error %d, status %d\n",
604 getAppName(), error_code
, GetLastError());
608 LocalFree((HLOCAL
)lpMsgBuf
);
612 /******************************************************************************
613 * Checks whether the buffer has enough room for the string or required size.
614 * Resizes the buffer if necessary.
617 * buffer - pointer to a buffer for string
618 * len - current length of the buffer in characters.
619 * required_len - length of the string to place to the buffer in characters.
620 * The length does not include the terminating null character.
622 static void REGPROC_resize_char_buffer(CHAR
**buffer
, DWORD
*len
, DWORD required_len
)
625 if (required_len
> *len
) {
628 *buffer
= HeapAlloc(GetProcessHeap(), 0, *len
* sizeof(**buffer
));
630 *buffer
= HeapReAlloc(GetProcessHeap(), 0, *buffer
, *len
* sizeof(**buffer
));
631 CHECK_ENOUGH_MEMORY(*buffer
);
635 /******************************************************************************
636 * Prints string str to file
638 static void REGPROC_export_string(FILE *file
, CHAR
*str
)
640 size_t len
= strlen(str
);
643 /* escaping characters */
644 for (i
= 0; i
< len
; i
++) {
663 /******************************************************************************
664 * Writes contents of the registry key to the specified file stream.
667 * file - writable file stream to export registry branch to.
668 * key - registry branch to export.
669 * reg_key_name_buf - name of the key with registry class.
670 * Is resized if necessary.
671 * reg_key_name_len - length of the buffer for the registry class in characters.
672 * val_name_buf - buffer for storing value name.
673 * Is resized if necessary.
674 * val_name_len - length of the buffer for storing value names in characters.
675 * val_buf - buffer for storing values while extracting.
676 * Is resized if necessary.
677 * val_size - size of the buffer for storing values in bytes.
679 static void export_hkey(FILE *file
, HKEY key
,
680 CHAR
**reg_key_name_buf
, DWORD
*reg_key_name_len
,
681 CHAR
**val_name_buf
, DWORD
*val_name_len
,
682 BYTE
**val_buf
, DWORD
*val_size
)
684 DWORD max_sub_key_len
;
685 DWORD max_val_name_len
;
692 /* get size information and resize the buffers if necessary */
693 if (RegQueryInfoKey(key
, NULL
, NULL
, NULL
, NULL
,
694 &max_sub_key_len
, NULL
,
695 NULL
, &max_val_name_len
, &max_val_size
, NULL
, NULL
696 ) != ERROR_SUCCESS
) {
697 REGPROC_print_error();
699 curr_len
= strlen(*reg_key_name_buf
);
700 REGPROC_resize_char_buffer(reg_key_name_buf
, reg_key_name_len
,
701 max_sub_key_len
+ curr_len
+ 1);
702 REGPROC_resize_char_buffer(val_name_buf
, val_name_len
,
704 if (max_val_size
> *val_size
) {
705 *val_size
= max_val_size
;
706 if (!*val_buf
) *val_buf
= HeapAlloc(GetProcessHeap(), 0, *val_size
);
707 else *val_buf
= HeapReAlloc(GetProcessHeap(), 0, *val_buf
, *val_size
);
708 CHECK_ENOUGH_MEMORY(val_buf
);
711 /* output data for the current key */
713 fputs(*reg_key_name_buf
, file
);
715 /* print all the values */
720 DWORD val_name_len1
= *val_name_len
;
721 DWORD val_size1
= *val_size
;
722 ret
= RegEnumValue(key
, i
, *val_name_buf
, &val_name_len1
, NULL
,
723 &value_type
, *val_buf
, &val_size1
);
724 if (ret
!= ERROR_SUCCESS
) {
726 if (ret
!= ERROR_NO_MORE_ITEMS
) {
727 REGPROC_print_error();
732 if ((*val_name_buf
)[0]) {
734 REGPROC_export_string(file
, *val_name_buf
);
740 switch (value_type
) {
744 REGPROC_export_string(file
, (char*) *val_buf
);
749 fprintf(file
, "dword:%08x\n", *((DWORD
*)*val_buf
));
753 fprintf(stderr
,"%s: warning - unsupported registry format '%d', "
755 getAppName(), value_type
);
756 fprintf(stderr
,"key name: \"%s\"\n", *reg_key_name_buf
);
757 fprintf(stderr
,"value name:\"%s\"\n\n", *val_name_buf
);
763 const CHAR
*hex_prefix
;
767 if (value_type
== REG_BINARY
) {
771 sprintf(buf
, "hex(%d):", value_type
);
774 /* position of where the next character will be printed */
775 /* NOTE: yes, strlen("hex:") is used even for hex(x): */
776 cur_pos
= strlen("\"\"=") + strlen("hex:") +
777 strlen(*val_name_buf
);
779 fputs(hex_prefix
, file
);
780 for (i1
= 0; i1
< val_size1
; i1
++) {
781 fprintf(file
, "%02x", (unsigned int)(*val_buf
)[i1
]);
782 if (i1
+ 1 < val_size1
) {
788 if (cur_pos
> REG_FILE_HEX_LINE_LEN
) {
789 fputs("\\\n ", file
);
802 (*reg_key_name_buf
)[curr_len
] = '\\';
804 DWORD buf_len
= *reg_key_name_len
- curr_len
;
806 ret
= RegEnumKeyEx(key
, i
, *reg_key_name_buf
+ curr_len
+ 1, &buf_len
,
807 NULL
, NULL
, NULL
, NULL
);
808 if (ret
!= ERROR_SUCCESS
&& ret
!= ERROR_MORE_DATA
) {
810 if (ret
!= ERROR_NO_MORE_ITEMS
) {
811 REGPROC_print_error();
817 if (RegOpenKey(key
, *reg_key_name_buf
+ curr_len
+ 1,
818 &subkey
) == ERROR_SUCCESS
) {
819 export_hkey(file
, subkey
, reg_key_name_buf
, reg_key_name_len
,
820 val_name_buf
, val_name_len
, val_buf
, val_size
);
823 REGPROC_print_error();
827 (*reg_key_name_buf
)[curr_len
] = '\0';
830 /******************************************************************************
831 * Open file for export.
833 static FILE *REGPROC_open_export_file(CHAR
*file_name
)
837 if (strcmp(file_name
,"-")==0)
841 file
= fopen(file_name
, "w");
844 fprintf(stderr
,"%s: Can't open file \"%s\"\n", getAppName(), file_name
);
848 fputs("REGEDIT4\n", file
);
852 /******************************************************************************
853 * Writes contents of the registry key to the specified file stream.
856 * file_name - name of a file to export registry branch to.
857 * reg_key_name - registry branch to export. The whole registry is exported if
858 * reg_key_name is NULL or contains an empty string.
860 BOOL
export_registry_key(CHAR
*file_name
, CHAR
*reg_key_name
)
862 CHAR
*reg_key_name_buf
;
865 DWORD reg_key_name_len
= KEY_MAX_LEN
;
866 DWORD val_name_len
= KEY_MAX_LEN
;
867 DWORD val_size
= REG_VAL_BUF_SIZE
;
870 reg_key_name_buf
= HeapAlloc(GetProcessHeap(), 0,
871 reg_key_name_len
* sizeof(*reg_key_name_buf
));
872 val_name_buf
= HeapAlloc(GetProcessHeap(), 0,
873 val_name_len
* sizeof(*val_name_buf
));
874 val_buf
= HeapAlloc(GetProcessHeap(), 0, val_size
);
875 CHECK_ENOUGH_MEMORY(reg_key_name_buf
&& val_name_buf
&& val_buf
);
877 if (reg_key_name
&& reg_key_name
[0]) {
882 REGPROC_resize_char_buffer(®_key_name_buf
, ®_key_name_len
,
883 strlen(reg_key_name
));
884 strcpy(reg_key_name_buf
, reg_key_name
);
886 /* open the specified key */
887 if (!parseKeyName(reg_key_name
, ®_key_class
, &branch_name
)) {
888 fprintf(stderr
,"%s: Incorrect registry class specification in '%s'\n",
889 getAppName(), reg_key_name
);
892 if (!branch_name
[0]) {
893 /* no branch - registry class is specified */
894 file
= REGPROC_open_export_file(file_name
);
895 export_hkey(file
, reg_key_class
,
896 ®_key_name_buf
, ®_key_name_len
,
897 &val_name_buf
, &val_name_len
,
898 &val_buf
, &val_size
);
899 } else if (RegOpenKey(reg_key_class
, branch_name
, &key
) == ERROR_SUCCESS
) {
900 file
= REGPROC_open_export_file(file_name
);
901 export_hkey(file
, key
,
902 ®_key_name_buf
, ®_key_name_len
,
903 &val_name_buf
, &val_name_len
,
904 &val_buf
, &val_size
);
907 fprintf(stderr
,"%s: Can't export. Registry key '%s' does not exist!\n",
908 getAppName(), reg_key_name
);
909 REGPROC_print_error();
914 /* export all registry classes */
915 file
= REGPROC_open_export_file(file_name
);
916 for (i
= 0; i
< REG_CLASS_NUMBER
; i
++) {
917 /* do not export HKEY_CLASSES_ROOT */
918 if (reg_class_keys
[i
] != HKEY_CLASSES_ROOT
&&
919 reg_class_keys
[i
] != HKEY_CURRENT_USER
&&
920 reg_class_keys
[i
] != HKEY_CURRENT_CONFIG
&&
921 reg_class_keys
[i
] != HKEY_DYN_DATA
) {
922 strcpy(reg_key_name_buf
, reg_class_names
[i
]);
923 export_hkey(file
, reg_class_keys
[i
],
924 ®_key_name_buf
, ®_key_name_len
,
925 &val_name_buf
, &val_name_len
,
926 &val_buf
, &val_size
);
934 HeapFree(GetProcessHeap(), 0, reg_key_name
);
935 HeapFree(GetProcessHeap(), 0, val_buf
);
939 /******************************************************************************
940 * Reads contents of the specified file into the registry.
942 BOOL
import_registry_file(LPTSTR filename
)
944 FILE* reg_file
= fopen(filename
, "r");
947 processRegLines(reg_file
);
953 /******************************************************************************
954 * Removes the registry key with all subkeys. Parses full key name.
957 * reg_key_name - full name of registry branch to delete. Ignored if is NULL,
958 * empty, points to register key class, does not exist.
960 void delete_registry_key(CHAR
*reg_key_name
)
965 if (!reg_key_name
|| !reg_key_name
[0])
968 if (!parseKeyName(reg_key_name
, &key_class
, &key_name
)) {
969 fprintf(stderr
,"%s: Incorrect registry class specification in '%s'\n",
970 getAppName(), reg_key_name
);
974 fprintf(stderr
,"%s: Can't delete registry class '%s'\n",
975 getAppName(), reg_key_name
);
979 RegDeleteTreeA(key_class
, key_name
);