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

Annotation of /trunk/Src/wptRegistry.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 73 - (hide annotations)
Tue Nov 8 07:15:13 2005 UTC (19 years, 3 months ago) by twoaday
File size: 17565 byte(s)
2005-11-08  Timo Schulz  <ts@g10code.com>
 
        More minor changes to avoid GCC warnings.
         
        * wptGPG.cpp (check_homedir): Free memory in case of errors.
        (multi_gnupg_path): Add strict mode. If non-strict mode return
        the folder even if it does not exist.
        (check_for_gpgwin): New.
        * wptKeyserverDlg.cpp (hkp_recv_key): Make sure import_res is
        initialized.
        * wptRegistry.cpp (get_reg_entry_gpg4win): New.
        (get_reg_entry_mo): Support for gpg4win.
         
For complete changes see ChangeLogs.

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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26