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

Contents of /trunk/Src/wptRegistry.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 117 - (show annotations)
Thu Dec 8 09:26:32 2005 UTC (19 years, 2 months ago) by twoaday
File size: 18498 byte(s)
2005-12-07  Timo Schulz  <ts@g10code.com>
 
        * wptOwnertrustDlg.cpp (ownertrust_dlg_proc):
        Use 'Close' instead of 'Exit'.
        * wptKeyEditDlgs.cpp (keyedit_dlg_proc): Likewise.
        * wptGPG.cpp (gnupg_backup_keyrings): Use $APPDATA
        as the destination dir. Thanks to Werner.
        * wptRegistry.cpp (is_gpgee_installed): New.
        (regist_inst_winpt): Do not register file extensions
        if GPGee is available.
        * wptGPGPrefsDlg.cpp (gpgprefs_dlg_proc): Limit
        use of local vars.
        * wptPreferencesDlg.cpp (prefs_dlg_proc): Make sure
        no illegal backup mode is saved.
        * wptKeyserverDlg.cpp (show_imported_key): New.
        (hkp_recv_key2): Show imported keys if the blob
        contained more than one.
         


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26