/[winpt]/trunk/Src/wptRegistry.cpp
ViewVC logotype

Contents of /trunk/Src/wptRegistry.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 129 - (show annotations)
Fri Dec 30 13:56:10 2005 UTC (19 years, 2 months ago) by twoaday
File size: 18765 byte(s)
2005-12-27  Timo Schulz  <ts@g10code.com>
                                                                                
        * wptListView.cpp (listview_set_view): New.
        (listview_del_column): New.
        * wptW32API.cpp (get_locale_date): New.
        (get_menu_state): New.
        (force_foreground_window): New.
        * wptVerifyList.cpp (strtimestamp): Support for
        locale date formats.
        * wptGPGUtil.cpp (gpg_revoke_cert): Handle bad
        passphrases.
        * wptKeyEditCB.cpp (editkey_command_handler): Immediately
        return when a bad passphrase was submitted.
        * wptKeyRevokersDlg.cpp (keyrevokers_dlg_proc): Change
        column order.
        * wptKeylist.cpp (keylist_upd_col): New.
        * wptKeyManagerDlg.cpp (update_ui_items): Deactivate
        'Revocation' for public keys.
        (translate_menu_strings): s/Revoke/Revoke Cert.
        (modify_listview_columns): New.


1 /* wptRegistry.cpp - W32 Registry access
2 * Copyright (C) 2000-2005 Timo Schulz
3 *
4 * This file is part of WinPT.
5 *
6 * WinPT is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * WinPT is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with WinPT; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <windows.h>
26 #include <stdio.h>
27
28 #include "wptErrors.h"
29 #include "wptW32API.h"
30 #include "wptGPG.h"
31 #include "wptRegistry.h"
32 #include "wptKeyserver.h"
33 #include "wptTypes.h"
34 #include "wptNLS.h"
35 #include "wptVersion.h"
36
37 #define rc_ok(rc) ((rc) == ERROR_SUCCESS)
38
39
40
41 struct reg_hotkey_s reg_hotkeys[] = {
42 {"ClipEncrypt", "", 0},
43 {"ClipDecrypt", "", 0},
44 {"ClipSign", "", 0},
45 {"ClipSignEnc", "", 0},
46 {"CwsEncrypt", "", 0},
47 {"CwsDecrypt", "", 0},
48 {"CwsSign", "", 0},
49 {"CwsSignEnc", "", 0},
50 {NULL, "", 0}
51 };
52
53 winpt_reg_prefs_s reg_prefs;
54
55 #define WINPT_REG "Software\\WinPT"
56
57
58 /* Return != 0 if GPG4win is installed. */
59 int
60 is_gpg4win_installed (void)
61 {
62 char *p;
63
64 p = get_reg_entry_gpg4win (NULL);
65 if (!p)
66 return 0;
67 if (dir_exist_check (p)) {
68 free_if_alloc (p);
69 return 0;
70 }
71 free_if_alloc (p);
72 return -1;
73 }
74
75
76 /* Return != 0 if GPGee is installed. */
77 int
78 is_gpgee_installed (void)
79 {
80 HKEY hk;
81 LONG ec;
82
83 ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\GPGee", 0, KEY_READ, &hk);
84 if (ec == ERROR_SUCCESS) {
85 RegCloseKey (hk);
86 return -1;
87 }
88
89 return 0;
90 }
91
92
93 /* Free all members in the registry preference struct. */
94 void
95 free_reg_prefs (void)
96 {
97 free_if_alloc (reg_prefs.backup.path);
98 free_if_alloc (reg_prefs.kserv_conf);
99 free_if_alloc (reg_prefs.homedir);
100 memset (&reg_prefs, 0, sizeof reg_prefs);
101 }
102
103
104 /* Register the given WinPT filetype. */
105 static int
106 regist_single_filetype (gpg_filetype *gfile)
107 {
108 char icon[256];
109 char prog[256];
110
111 memset (&icon, 0, sizeof (icon));
112 GetModuleFileName (glob_hinst, prog, sizeof (prog)-1);
113 _snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon);
114 return create_file_type (prog, gfile->ext, gfile->descr, icon);
115 }
116
117
118 /* Install the GPG related into the W32 resgistry, if the entry already
119 exists the function returns immediately. */
120 int
121 regist_inst_gnupg (int create_mokey)
122 {
123 int rc;
124 HKEY reg;
125
126 rc = RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", 0, KEY_READ, &reg );
127 if( rc_ok( rc ) ) {
128 RegCloseKey( reg );
129 return 0;
130 }
131 rc = RegCreateKey( HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", &reg );
132 if( !rc_ok( rc ) )
133 return WPTERR_REGISTRY;
134 RegCloseKey( reg );
135 if( create_mokey ) {
136 rc = RegOpenKeyEx( HKEY_CURRENT_USER, "Control Panel\\MingW32\\NLS", 0, KEY_READ, &reg );
137 if( rc_ok( rc ) ) {
138 RegCloseKey( reg );
139 return 0;
140 }
141 rc = RegCreateKey( HKEY_CURRENT_USER, "Control Panel\\MingW32\\NLS", &reg );
142 if( !rc_ok( rc ) )
143 return WPTERR_REGISTRY;
144 RegCloseKey( reg );
145 }
146
147 return 0;
148 }
149
150
151 /* Install WinPT into the W32 registry, if the entry already
152 exists the function returns immediately. @with_ext can be
153 used to register some file types (if 1). @created contains
154 1 if the registry key was created.
155 Return value: 0 on success. */
156 int
157 regist_inst_winpt (int with_ext, int *created)
158 {
159 HKEY reg;
160 char *p = NULL;
161 char modpath[MAX_PATH+1];
162 int rc, i, id, n = 0;
163
164 gpg_filetype gpg_filetypes[] = {
165 {_("GPG Detached Signature"), ".sig", 1},
166 {_("GPG Encrypted Data"), ".gpg", 2},
167 {_("GPG Armored Data"), ".asc", 2},
168 {0}
169 };
170
171 if (created)
172 *created = 0;
173
174 p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions");
175 if ((p && *p == '1') || is_gpgee_installed ())
176 with_ext = 0;
177 free_if_alloc (p);
178
179 if (with_ext) {
180 id = msg_box (NULL, _("WinPT can register some GPG file types for you so they can "
181 "be processed with a double click in the explorer.\n"
182 "Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO);
183 if (id == IDNO) {
184 set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
185 goto start;
186 }
187 for (i = 0; gpg_filetypes[i].ext; i++) {
188 rc = RegOpenKeyEx (HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, &reg);
189 if (rc_ok (rc)) {
190 RegCloseKey (reg);
191 id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO,
192 _("It seems there was already a '%s' file type registered by another application.\n"
193 "Do you want to overwrite it?"), gpg_filetypes[i].ext);
194 if (id == IDNO)
195 continue;
196 }
197 regist_single_filetype (&gpg_filetypes[i]);
198 n++;
199 }
200 }
201
202 start:
203 rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, &reg);
204 if (rc_ok (rc)) {
205 RegCloseKey (reg);
206 rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, &reg);
207 if( !rc_ok (rc)) {
208 RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", &reg);
209 RegCloseKey (reg);
210 }
211 p = get_reg_entry_keyserver ("Default");
212 if (!p) {
213 char buf[16];
214 sprintf (buf, "%d", HKP_PORT);
215 set_reg_entry_keyserver ("Default_Port", buf);
216 set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER);
217 }
218 free_if_alloc (p);
219 if (n)
220 set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" );
221 return 0;
222 }
223 rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, &reg);
224 if (!rc_ok (rc))
225 return WPTERR_REGISTRY;
226 if (created)
227 *created = 1;
228 RegCloseKey (reg);
229 if (n > 0 || is_gpgee_installed ())
230 set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1");
231 if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {
232 while (n-- > 0) {
233 if (modpath[n] == '\\') {
234 modpath[n] = 0;
235 break;
236 }
237 }
238 set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Install Directory", modpath);
239 }
240 return 0;
241 }
242
243
244 /* Create a new filetype in the W32 registry.
245 We should really care of errors! Otherwise we can damage the registry! */
246 int
247 create_file_type (const char *exefile, const char *ext,
248 const char *extname, char *iconfile)
249 {
250 int rc;
251 HKEY reg = NULL;
252 char deficon[256], defexec[256], p_exefile[256];
253
254
255 rc = RegCreateKey( HKEY_CLASSES_ROOT, ext, &reg );
256 if( rc_ok( rc ) )
257 rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)extname, strlen( extname ) );
258 if( rc_ok( rc ) )
259 rc = RegCloseKey( reg );
260 if( rc_ok( rc ) )
261 rc = RegCreateKey( HKEY_CLASSES_ROOT, extname, &reg );
262 if( rc_ok( rc ) )
263 rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *) extname, strlen( extname ) );
264 if( rc_ok( rc ) )
265 rc = RegCloseKey( reg );
266 if( !rc_ok( rc ) ) {
267 rc = WPTERR_REGISTRY;
268 goto leave;
269 }
270
271 memset( &deficon, 0, sizeof deficon );
272 _snprintf( deficon, sizeof deficon - 1, "%s\\DefaultIcon", extname );
273 memset( &defexec, 0, sizeof defexec );
274 _snprintf( defexec, sizeof defexec - 1, "%s\\shell\\open\\command", extname );
275 memset( &p_exefile, 0, sizeof p_exefile );
276 _snprintf( p_exefile, sizeof p_exefile - 1, "%s %%1", exefile );
277
278 rc = RegCreateKey( HKEY_CLASSES_ROOT, deficon, &reg );
279 if( rc_ok( rc ) )
280 rc = RegSetValueEx(reg, NULL, 0, REG_SZ, (byte *)iconfile, strlen( iconfile ) );
281 if( rc_ok( rc ) )
282 rc = RegCloseKey( reg );
283 if( rc_ok( rc ) )
284 rc = RegCreateKey( HKEY_CLASSES_ROOT, defexec, &reg );
285 if( rc_ok( rc ) )
286 rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)p_exefile, strlen( exefile ) );
287 if( rc_ok( rc ) )
288 rc = RegCloseKey( reg );
289 if( !rc_ok( rc ) ) {
290 rc = WPTERR_REGISTRY;
291 goto leave;
292 }
293
294 leave:
295 if( reg )
296 RegCloseKey( reg );
297 return rc;
298 } /* create_file_type */
299
300
301 /* Expand a string with %foo% entries so that %foo% will
302 be replaced with its actual value. */
303 static char *
304 expand_path (const char *path)
305 {
306 DWORD len;
307 char *p;
308
309 len = ExpandEnvironmentStrings (path, NULL, 0);
310 if (!len)
311 return NULL;
312 len += 1;
313 p = new char[len+1];
314 if (!p)
315 return NULL;
316 len = ExpandEnvironmentStrings (path, p, len);
317 if (!len) {
318 free_if_alloc (p);
319 return NULL;
320 }
321 return p;
322 }
323
324
325 /* Retrieve a registry entry with the directory given in @dir
326 and the key given in @key.
327 Return value is the value or NULL otherwise. */
328 char*
329 get_reg_entry (HKEY root_key, const char * dir, const char * key)
330 {
331 int rc;
332 char text[384] = {0};
333 DWORD nbytes, type;
334 HKEY reg_key = NULL;
335 char * p = NULL;
336
337 rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, &reg_key);
338 if( !rc_ok( rc ) )
339 goto leave;
340 nbytes = sizeof (text) - 1;
341 type = REG_SZ;
342
343 rc = RegQueryValueEx (reg_key, key, 0, &type, (BYTE *)&text, &nbytes);
344 if (!rc_ok (rc) || !nbytes)
345 goto leave;
346
347 if (type == REG_EXPAND_SZ && strchr (text, '%'))
348 p = expand_path (text);
349 else {
350 p = new char[nbytes + 1];
351 if (!p)
352 BUG (0);
353 memcpy (p, text, nbytes);
354 p[nbytes] = '\0';
355 }
356
357 leave:
358 if (reg_key)
359 RegCloseKey (reg_key);
360 return p;
361 }
362
363
364 /* XXX: use REG_EXPAND_SZ to support multi user environments.
365 keep this type and do not overwrite it with REG_SZ. */
366
367 /* Set a registry entry. */
368 int
369 set_reg_entry (HKEY root_key, const char *dir, const char *key,
370 const char *value)
371 {
372 int rc = 0;
373 HKEY reg_key;
374
375 rc = RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, &reg_key );
376 if( !rc_ok( rc ) )
377 return WPTERR_REGISTRY;
378 rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) );
379 if( !rc_ok( rc ) )
380 rc = WPTERR_REGISTRY;
381 RegCloseKey( reg_key );
382 return rc;
383 } /* set_reg_entry */
384
385
386 int
387 set_reg_key( HKEY root_key, const char * dir, const char * key,
388 const char * value )
389 {
390 int rc = 0;
391 HKEY reg_key;
392
393 rc = RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, &reg_key );
394 if( !rc_ok( rc ) )
395 return WPTERR_REGISTRY;
396
397 rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) );
398 if( !rc_ok( rc ) ) {
399 if ( RegCreateKey( root_key, key, &reg_key ) != ERROR_SUCCESS ) {
400 rc = WPTERR_REGISTRY;
401 goto leave;
402 }
403 rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) );
404 if ( !rc_ok( rc ) )
405 rc = WPTERR_REGISTRY;
406 }
407
408 leave:
409 RegCloseKey( reg_key );
410 return rc;
411 } /* set_reg_key */
412
413
414 int
415 set_reg_entry_gpg (const char * key, const char * value)
416 {
417 return set_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key, value);
418 }
419
420
421 int
422 set_reg_entry_mo (const char * value)
423 {
424 return set_reg_entry (HKEY_CURRENT_USER, "Control Panel\\Mingw32\\NLS",
425 "MODir", value);
426 }
427
428
429 char *
430 get_reg_entry_gpg (const char *key)
431 {
432 return get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key);
433 }
434
435
436 /* Return if possible the GPG4Win installation directory concatenated
437 with the string in @path if given. */
438 char*
439 get_reg_entry_gpg4win (const char *path)
440 {
441 char *p, *pp;
442 p = get_reg_entry (HKEY_LOCAL_MACHINE,
443 "Software\\GNU\\GnuPG", "Install Directory");
444 if (!p)
445 return NULL;
446 if (!path)
447 return p;
448 pp = new char[strlen (p) + strlen (path) + 4];
449 if (!pp)
450 BUG (NULL);
451 sprintf (pp, "%s\\%s", p, path);
452 free_if_alloc (p);
453 return pp;
454 }
455
456
457 char*
458 get_reg_entry_mo (void)
459 {
460 char *p, *pp;
461 const char *lang;
462
463 p = get_reg_entry (HKEY_CURRENT_USER,
464 "Control Panel\\Mingw32\\NLS", "MODir");
465 if (p)
466 return p;
467
468 lang = get_gettext_langid ();
469 if (!lang)
470 return NULL;
471 pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8];
472 if (!pp)
473 BUG (NULL);
474 sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang);
475 p = get_reg_entry_gpg4win (pp);
476 free_if_alloc (pp);
477 return p;
478 }
479
480
481 /* All valid configuration commands. */
482 static const char * cfg [] = {
483 NULL,
484 "CacheTime",
485 "WordWrap",
486 "FastMode",
487 "Viewer",
488 "KeylistMode",
489 "WipeMode",
490 "AlwaysTrust",
491 "AutoBackup",
492 "BackupMode",
493 "DisableHotkeys",
494 "NoCompressMultiMedia",
495 "Expert",
496 "FMProgressBar",
497 };
498
499
500 int
501 set_reg_winpt_single (int id, int val)
502 {
503 char buf[64];
504 int rc;
505
506 sprintf (buf, "%d", val);
507 rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id], buf);
508 return rc;
509 }
510
511
512 int
513 get_reg_winpt_single (int id)
514 {
515 char * buf = NULL;
516 int val = 0;
517
518 buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]);
519 if (buf && *buf != ' ')
520 val = 1;
521 else if (!buf)
522 val = -1;
523 free_if_alloc (buf);
524 return val;
525 }
526
527
528 /* Saves the winpt preferences in the registry. */
529 int
530 set_reg_winpt_prefs (winpt_reg_prefs_s * opt)
531 {
532 char buf[128];
533 size_t i;
534 int rc = 0;
535
536 for (i=1; i < DIM (cfg); i++) {
537 switch (i) {
538 case CFG_CACHETIME:
539 sprintf (buf, "%d", opt->cache_time);
540 break;
541 case CFG_WORDWRAP:
542 sprintf (buf, "%d", opt->word_wrap);
543 break;
544 case CFG_WIPEMODE:
545 sprintf (buf, "%d", opt->wipe_mode);
546 break;
547 case CFG_FASTMODE:
548 sprintf (buf, "%d", opt->use_tmpfiles);
549 break;
550 case CFG_NOZIP_MMEDIA:
551 sprintf (buf, "%d", opt->no_zip_mmedia);
552 break;
553 case CFG_VIEWER:
554 sprintf (buf, "%d", opt->use_viewer);
555 break;
556 case CFG_KEYLISTMODE:
557 sprintf (buf, "%d", opt->keylist_mode);
558 break;
559 case CFG_ALWAYSTRUST:
560 sprintf (buf, "%d", opt->always_trust);
561 break;
562 case CFG_AUTOBACKUP:
563 sprintf (buf, "%d", opt->auto_backup);
564 break;
565 case CFG_AUTOBAKMODE:
566 sprintf (buf, "%d", opt->backup.mode);
567 break;
568 case CFG_DISHOTKEYS:
569 sprintf (buf, "%d", opt->no_hotkeys);
570 break;
571 case CFG_EXPERT:
572 sprintf (buf, "%d", opt->expert);
573 break;
574
575 case CFG_FM_PROGRESS:
576 sprintf (buf, "%d", opt->fm.progress);
577 break;
578 }
579 rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i], buf);
580 if (rc)
581 goto leave;
582 }
583
584 if (opt->backup.path) {
585 rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "BackupPath",
586 opt->backup.path);
587 if (rc)
588 goto leave;
589 }
590 if (opt->kserv_conf) {
591 rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig",
592 opt->kserv_conf);
593 if (rc)
594 goto leave;
595 }
596
597 for (i=0; reg_hotkeys[i].reg_entry; i++) {
598 strcpy (buf, " ");
599 if (reg_hotkeys[i].enabled)
600 strcpy (buf, reg_hotkeys[i].key);
601 rc = set_reg_key (HKEY_CURRENT_USER, WINPT_REG,
602 reg_hotkeys[i].reg_entry, buf);
603 if (rc)
604 break;
605 }
606
607 leave:
608 if (rc) {
609 msg_box (NULL, _("Could not write to Registry."), _("Preferences"), MB_ERR);
610 return rc;
611 }
612 return 0;
613 }
614
615
616 int
617 set_reg_winpt_flag (const char * name, int val)
618 {
619 return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name, val? "1" : "0");
620 } /* set_reg_winpt_flag */
621
622
623 int
624 get_reg_winpt_flag (const char * name)
625 {
626 char * buf;
627 int flag = 0;
628
629 buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name);
630 if (buf && buf[0] == '1')
631 flag = 1;
632 else if (!buf || buf && buf[0] != '0')
633 flag = -1;
634 free_if_alloc (buf);
635 return flag;
636 } /* get_reg_winpt_flag */
637
638
639 /* Retrieve the winpt preferences from the registry. */
640 int
641 get_reg_winpt_prefs (winpt_reg_prefs_s * opt)
642 {
643 char *val = NULL;
644 size_t i;
645
646 for (i=1; i < DIM (cfg); i++) {
647 val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]);
648 if (!val || *val == ' ') {
649 free_if_alloc (val);
650 continue;
651 }
652 switch (i) {
653 case CFG_CACHETIME:
654 opt->cache_time = atol (val);
655 /* We do NOT support passphrase caching for more than an hour.
656 * Perhaps we should allow it, but for now we silently drop this.
657 */
658 if (opt->cache_time > 3600)
659 opt->cache_time = 3600;
660 break;
661 case CFG_WORDWRAP:
662 opt->word_wrap = atol (val);
663 break;
664 case CFG_FASTMODE:
665 opt->use_tmpfiles = atol (val);
666 break;
667 case CFG_NOZIP_MMEDIA:
668 opt->no_zip_mmedia = atol (val);
669 break;
670 case CFG_VIEWER:
671 opt->use_viewer = atol (val);
672 break;
673 case CFG_KEYLISTMODE:
674 opt->keylist_mode = atol (val);
675 break;
676 case CFG_WIPEMODE:
677 opt->wipe_mode = atol (val);
678 break;
679 case CFG_DISHOTKEYS:
680 opt->no_hotkeys = atol (val);
681 break;
682 case CFG_ALWAYSTRUST:
683 opt->always_trust = atol (val);
684 break;
685 case CFG_AUTOBACKUP:
686 opt->auto_backup = atol (val);
687 break;
688 case CFG_AUTOBAKMODE:
689 opt->backup.mode = atol (val);
690 break;
691 case CFG_EXPERT:
692 opt->expert = atol (val);
693 break;
694
695 case CFG_FM_PROGRESS:
696 opt->fm.progress = atol (val);
697 break;
698 }
699 free_if_alloc (val);
700 }
701
702 val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "BackupPath");
703 if (val && val[0] != ' ')
704 opt->backup.path = m_strdup (val);
705 free_if_alloc (val);
706
707 val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig");
708 if (val && val[0] != ' ')
709 opt->kserv_conf = m_strdup (val);
710 free_if_alloc (val);
711
712 for (i=0; reg_hotkeys[i].reg_entry; i++) {
713 val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, reg_hotkeys[i].reg_entry);
714 if (val && val[0] != ' ') {
715 reg_hotkeys[i].key[0] = *val;
716 reg_hotkeys[i].enabled = 1;
717 }
718 else
719 reg_hotkeys[i].enabled = 0;
720 free_if_alloc (val);
721 }
722 return 0;
723 } /* get_reg_winpt_prefs */
724
725
726 char*
727 get_reg_entry_keyserver (const char *name)
728 {
729 char * p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name);
730 if (p && !strcmp (p, "")) {
731 free_if_alloc (p);
732 return NULL;
733 }
734 return p;
735 }
736
737
738 void
739 get_reg_proxy_prefs (char ** host, int * port, char ** user, char ** pass)
740 {
741 if (host)
742 *host = get_reg_entry_keyserver ("Host");
743 if (user)
744 *user = get_reg_entry_keyserver ("User");
745 if (pass)
746 *pass = get_reg_entry_keyserver ("Pass");
747 if (port) {
748 char * p = get_reg_entry_keyserver ("Port");
749 if (p) {
750 *port = atol (p);
751 free_if_alloc (p);
752 }
753 }
754 } /* get_reg_proxy_prefs */
755
756
757 int
758 set_reg_entry_keyserver( const char * name, const char * val )
759 {
760 return set_reg_entry( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val );
761 } /* set_reg_entry_keyserver */
762
763
764 int
765 set_reg_proxy_prefs( const char * host, int port, const char * user, const char * pass )
766 {
767 int rc;
768
769 rc = set_reg_entry_keyserver( "Host", host? host : "" );
770 if( !rc ) {
771 char buf[32];
772 sprintf( buf, "%d", port );
773 rc = set_reg_entry_keyserver( "Port", buf );
774 }
775 if( !rc )
776 rc = set_reg_entry_keyserver( "User", user? user : "" );
777 if( !rc )
778 rc = set_reg_entry_keyserver( "Pass", pass? pass : "" );
779 return rc;
780 } /* set_reg_proxy_prefs */

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26