[Winpt-commits] r119 - in trunk: . Include Src
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Fri Dec 9 09:04:52 CET 2005
Author: twoaday
Date: 2005-12-09 09:04:51 +0100 (Fri, 09 Dec 2005)
New Revision: 119
Modified:
trunk/Include/ChangeLog
trunk/Include/wptFileManager.h
trunk/Include/wptKeyEdit.h
trunk/README-0.11.txt
trunk/Src/ChangeLog
trunk/Src/wptFileCBS.cpp
trunk/Src/wptFileManager.cpp
trunk/Src/wptKeyEdit.cpp
trunk/Src/wptKeyEditCB.cpp
trunk/Src/wptKeyManagerDlg.cpp
trunk/Src/wptKeyserver.cpp
trunk/Src/wptMDSumDlg.cpp
trunk/TODO
Log:
2005-12-08 Timo Schulz <ts at g10code.com>
* wptKeyserverDlg.cpp (show_imported_keys): Enhanced.
(hkp_recv_key2): Show user-id of the imported key instead
of just the pattern.
* wptFileCBS.cpp (read_cb): Changed to W32 API.
(write_cb): Likewise. Create output file on demand.
(gpg_file_data_new): Adjusted code for new API.
* wptKeyEdit.cpp (cleanKey): New.
* wptKeyEditCB.cpp (cmd_clean_handler): New.
(editkey_command_handler): Call clean handler.
* wptKeyManagerDlg.cpp (keymanager_dlg_proc): Sort
keylist after inserting items.
* wptFileManager.cpp (fm_set_status): Take care of
cleartext sigs.
Modified: trunk/Include/ChangeLog
===================================================================
--- trunk/Include/ChangeLog 2005-12-08 13:21:52 UTC (rev 118)
+++ trunk/Include/ChangeLog 2005-12-09 08:04:51 UTC (rev 119)
@@ -1,3 +1,7 @@
+2005-12-08 Timo Schulz <ts at g10code.com>
+
+ * wptKeyEdit.h (cleanKey): New.
+
2005-12-02 Werner Koch <wk at g10code.com>
* wptW32API.h (html_help_dispatch, html_help_deinit)
Modified: trunk/Include/wptFileManager.h
===================================================================
--- trunk/Include/wptFileManager.h 2005-12-08 13:21:52 UTC (rev 118)
+++ trunk/Include/wptFileManager.h 2005-12-09 08:04:51 UTC (rev 119)
@@ -68,25 +68,27 @@
};
typedef struct fm_state_s * fm_state_t;
+
enum file_data_flag_t {
F_DATA_WRITE = 0,
- F_DATA_READ = 1,
- F_DATA_NOMAP = 2
+ F_DATA_READ = 1,
+ F_DATA_NOMAP = 2
};
-
+
/* Gpg file handle. */
struct file_data_s {
- struct gpgme_data_cbs cbs;
- FILE *handle;
+ struct gpgme_data_cbs cbs;
+ HANDLE handle;
gpgme_data_t dat;
unsigned long size;
unsigned long off;
void *cb_value;
+ char *name;
};
typedef struct file_data_s *file_data_t;
/*-- wptFileCBS.cpp --*/
-gpgme_error_t gpg_file_data_new (const char *fname, int for_read,
+gpgme_error_t gpg_file_data_new (const char *fname, int flags,
file_data_t *r_cb);
void gpg_file_data_release (file_data_t cb);
void gpg_file_data_set_cb (file_data_t ctx,
Modified: trunk/Include/wptKeyEdit.h
===================================================================
--- trunk/Include/wptKeyEdit.h 2005-12-08 13:21:52 UTC (rev 118)
+++ trunk/Include/wptKeyEdit.h 2005-12-09 08:04:51 UTC (rev 119)
@@ -46,7 +46,8 @@
GPG_EDITKEY_SETPREF = 18,
GPG_EDITKEY_DELSIG = 21,
GPG_EDITKEY_KEYSERV = 23,
- GPG_EDITKEY_REVUID = 24
+ GPG_EDITKEY_REVUID = 24,
+ GPG_EDITKEY_CLEAN = 25
};
/* Reasons for revocations. */
@@ -157,6 +158,7 @@
gpgme_error_t setUseridPreferences (int uid_index, const char *new_prefs);
gpgme_error_t delUseridSignature (int uid_index, int sig_index);
gpgme_error_t setPreferredKeyserver (int uid_index, const char *url);
+ gpgme_error_t cleanKey (void);
gpgme_error_t getUseridInfo (gpg_uid_info_t *r_uinf);
Modified: trunk/README-0.11.txt
===================================================================
--- trunk/README-0.11.txt 2005-12-08 13:21:52 UTC (rev 118)
+++ trunk/README-0.11.txt 2005-12-09 08:04:51 UTC (rev 119)
@@ -24,7 +24,7 @@
- A card reader that is PC/SC compatible
- An OpenPGP card (either a test card <= 0.9 or the release version 1.0)
-- GnuPG 1.4.0 or later and WinPT 0.11.x
+- GnuPG 1.4.2 or later and WinPT 0.11.x
Feel free to ask on gnupg-users at gnupg.org or
winpt-users at wald.intevation.org for more information.
Modified: trunk/Src/ChangeLog
===================================================================
--- trunk/Src/ChangeLog 2005-12-08 13:21:52 UTC (rev 118)
+++ trunk/Src/ChangeLog 2005-12-09 08:04:51 UTC (rev 119)
@@ -3,6 +3,16 @@
* wptKeyserverDlg.cpp (show_imported_keys): Enhanced.
(hkp_recv_key2): Show user-id of the imported key instead
of just the pattern.
+ * wptFileCBS.cpp (read_cb): Changed to W32 API.
+ (write_cb): Likewise. Create output file on demand.
+ (gpg_file_data_new): Adjusted code for new API.
+ * wptKeyEdit.cpp (cleanKey): New.
+ * wptKeyEditCB.cpp (cmd_clean_handler): New.
+ (editkey_command_handler): Call clean handler.
+ * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Sort
+ keylist after inserting items.
+ * wptFileManager.cpp (fm_set_status): Take care of
+ cleartext sigs.
2005-12-07 Timo Schulz <ts at g10code.com>
Modified: trunk/Src/wptFileCBS.cpp
===================================================================
--- trunk/Src/wptFileCBS.cpp 2005-12-08 13:21:52 UTC (rev 118)
+++ trunk/Src/wptFileCBS.cpp 2005-12-09 08:04:51 UTC (rev 119)
@@ -1,4 +1,4 @@
-/* wptFileCBS.cpp
+/* wptFileCBS.cpp - Customized I/O callbacks for GPGME
* Copyright (C) 2005 Timo Schulz
* Copyright (C) 2005 g10 Code GmbH
*
@@ -24,10 +24,8 @@
#include <windows.h>
#include <stdio.h>
+#include <errno.h>
#include <malloc.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/stat.h>
#include "gpgme.h"
#include "wptListView.h"
@@ -36,7 +34,8 @@
#include "wptErrors.h"
#include "wptTypes.h"
-void progress_callback (void *opaque, const char *what, int type, int off, int max);
+void progress_callback (void *opaque, const char *what, int type,
+ int off, int max);
/* Predefined read callback. */
@@ -45,13 +44,15 @@
{
file_data_t cb = (file_data_t)handle;
struct progress_filter_s *pfx = (struct progress_filter_s *)cb->cb_value;
- int n = fread (buffer, 1, size, cb->handle);
+ DWORD nread = 0;
+ ReadFile (cb->handle, buffer, size, &nread, NULL);
+
/* XXX: there is a sync problem with the progress dialog. */
if (pfx)
progress_callback (pfx, NULL, 0, cb->off, cb->size);
- cb->off += n;
- return n;
+ cb->off += nread;
+ return (long)nread;
}
@@ -60,9 +61,22 @@
write_cb (void *handle, const void *buffer, size_t size)
{
file_data_t cb = (file_data_t)handle;
- int n = fwrite (buffer, 1, size, cb->handle);
+ DWORD nwritten;
- return n;
+ /* XXX: check if fd == INVALID_HANDLE_VALUE. */
+
+ if (!cb->handle) {
+ SECURITY_ATTRIBUTES sec_attr;
+
+ memset (&sec_attr, 0, sizeof (sec_attr));
+ sec_attr.bInheritHandle = FALSE;
+ sec_attr.nLength = sizeof (sec_attr);
+ cb->handle = CreateFile (cb->name, GENERIC_WRITE, FILE_SHARE_WRITE,
+ &sec_attr, CREATE_ALWAYS, 0, NULL);
+ }
+
+ WriteFile (cb->handle, buffer, size, &nwritten, NULL);
+ return (long)nwritten;
}
@@ -72,34 +86,40 @@
@for_read is 1 if the file is opened for read only.
Return value: 0 on success. */
gpgme_error_t
-gpg_file_data_new (const char *fname, int for_read, file_data_t *r_cb)
+gpg_file_data_new (const char *fname, int flags, file_data_t *r_cb)
{
gpgme_error_t err;
file_data_t cb;
- FILE *f;
+ HANDLE fd = NULL;
+ SECURITY_ATTRIBUTES sec_attr;
- f = fopen (fname, for_read?"rb" : "wb");
- if (!f)
- return gpgme_err_code_from_errno (errno);
-
+ memset (&sec_attr, 0, sizeof (sec_attr));
+ sec_attr.bInheritHandle = FALSE;
+ sec_attr.nLength = sizeof (sec_attr);
+ if (flags & F_DATA_READ) {
+ fd = CreateFile (fname, GENERIC_READ, FILE_SHARE_READ,
+ &sec_attr, OPEN_EXISTING, 0, NULL);
+ if (fd == INVALID_HANDLE_VALUE)
+ return gpgme_err_code_from_errno (ENOENT);
+ }
cb = (file_data_t)calloc (1, sizeof *cb);
if (!cb)
- abort ();
+ BUG (NULL);
+ cb->name = strdup (fname);
+ if (!cb->name)
+ BUG (NULL);
cb->cbs.read = read_cb;
cb->cbs.write = write_cb;
- cb->handle = f;
- if (for_read) {
- struct stat st;
- if (fstat (fileno (f), &st))
- BUG (NULL);
- cb->size = st.st_size;
+ if (flags & F_DATA_READ) {
+ cb->handle = fd;
+ cb->size = GetFileSize (fd, NULL);
cb->off = 0;
}
err = gpgme_data_new_from_cbs (&cb->dat, &cb->cbs, cb);
if (err) {
- fclose (f);
+ CloseHandle (fd);
free (cb);
return err;
}
@@ -124,10 +144,11 @@
if (!cb)
return;
if (cb->handle) {
- FILE *f = (FILE *)cb->handle;
- fclose (f);
+ CloseHandle (cb->handle);
+ cb->handle = NULL;
}
if (cb->dat)
gpgme_data_release (cb->dat);
- free (cb);
+ safe_free (cb->name);
+ safe_free (cb);
}
Modified: trunk/Src/wptFileManager.cpp
===================================================================
--- trunk/Src/wptFileManager.cpp 2005-12-08 13:21:52 UTC (rev 118)
+++ trunk/Src/wptFileManager.cpp 2005-12-09 08:04:51 UTC (rev 119)
@@ -763,6 +763,8 @@
case FM_SIGN:
if (sigmode == GPGME_SIG_MODE_DETACH)
strcpy (status, "SIGNED-DETACH");
+ else if (sigmode == GPGME_SIG_MODE_CLEAR)
+ strcpy (status, "SIGNED-CLEAR");
else
strcpy (status, "SIGNED");
break;
@@ -773,11 +775,9 @@
default: strcpy (status, "UNKNOWN"); break;
}
- if (success) {
- if (update) {
- listview_add_sub_item (lv, pos, 0, status);
- listview_add_sub_item (lv, pos, 1, output);
- }
+ if (success && update) {
+ listview_add_sub_item (lv, pos, 0, status);
+ listview_add_sub_item (lv, pos, 1, output);
}
listview_add_sub_item( lv, pos, 2, operat );
}
@@ -913,23 +913,24 @@
if (!confirm.yes)
goto leave;
}
-
+
if (fm_cmd == FM_ENCRYPT_ZIP)
fm_encrypt_into_zip (ctx, lv);
for (i = 0; i < listview_count_items (lv, 0); i++) {
if( !listview_get_item_state( lv, i ) )
continue;
- listview_get_item_text( lv, i, 1, fname, sizeof (fname) - 1 );
- if( file_exist_check( fname ) && !is_directory( fname ) ) {
- log_box( _("File Manager"), MB_ERR, _("\"%s\" does not exist"), fname );
+ listview_get_item_text(lv, i, 1, fname, sizeof (fname) - 1);
+ if( file_exist_check (fname) && !is_directory (fname)) {
+ log_box (_("File Manager"), MB_ERR,
+ _("\"%s\" does not exist"), fname);
continue;
}
- if( is_directory( fname ) )
+ if (is_directory (fname))
fm_cmd = FM_ENCRYPT_DIR;
- if( !fm_check_file_type( lv, i, fm_cmd ) )
+ if (!fm_check_file_type (lv, i, fm_cmd))
continue;
- sig_detached = fm_check_detached_sig( lv, i );
+ sig_detached = fm_check_detached_sig (lv, i);
switch (fm_cmd) {
case FM_LIST: rc = fm_list( fname, dlg ); break;
case FM_WIPE: rc = fm_wipe( fname ); break;
@@ -1263,10 +1264,10 @@
int rc = 0;
if (!c->init_cb || !c->cache_cb) {
- set_gpg_passphrase_cb (&c->pass_cb, c->ctx, GPG_CMD_DECRYPT,
+ set_gpg_passphrase_cb (&c->pass_cb, c->ctx, GPG_CMD_DECRYPT,
c->dlg, _("Decryption"));
- c->init_cb = 1;
- }
+ c->init_cb = 1;
+ }
c->output = m_strdup (name);
if (!c->output)
@@ -1343,6 +1344,7 @@
gpg_file_data_release (in);
if (out)
gpg_file_data_release (out);
+
return rc;
}
@@ -1357,7 +1359,8 @@
int rc = 0;
if (!c->init_cb || !c->cache_cb) {
- set_gpg_passphrase_cb (&c->pass_cb, c->ctx, GPG_CMD_SIGN, c->dlg, _("Signing"));
+ set_gpg_passphrase_cb (&c->pass_cb, c->ctx,
+ GPG_CMD_SIGN, c->dlg, _("Signing"));
c->init_cb = 1;
}
Modified: trunk/Src/wptKeyEdit.cpp
===================================================================
--- trunk/Src/wptKeyEdit.cpp 2005-12-08 13:21:52 UTC (rev 118)
+++ trunk/Src/wptKeyEdit.cpp 2005-12-09 08:04:51 UTC (rev 119)
@@ -701,6 +701,18 @@
}
+/* Remove unusable parts from a key. */
+gpgme_error_t
+GpgKeyEdit::cleanKey (void)
+{
+ if (!this->key)
+ return gpg_error (GPG_ERR_INV_OBJ);
+ type = GPG_EDITKEY_CLEAN;
+ return gpg_editkey (this->ctx, this->key, this);
+
+}
+
+
/* Update the user-ID preferences of the user-ID with the
index @uid_index to the prefs given in @new_prefs.
Return value: 0 on success. */
Modified: trunk/Src/wptKeyEditCB.cpp
===================================================================
--- trunk/Src/wptKeyEditCB.cpp 2005-12-08 13:21:52 UTC (rev 118)
+++ trunk/Src/wptKeyEditCB.cpp 2005-12-09 08:04:51 UTC (rev 119)
@@ -18,12 +18,12 @@
* along with WinPT; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
-#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
@@ -66,6 +66,7 @@
}
+/* 'sign' command handler. */
static const char*
cmd_sign_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
{
@@ -559,13 +560,13 @@
/* 'addrevoker' command handler. */
static const char *
cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
- const char * key, int * r_step)
+ const char *key, int *r_step)
{
int step = *r_step;
/* If the isuser already signed the key, send an empty
- string and jump to quit. */
- if (ctx->getResult () & GPG_EDITRES_ALREADY_SIGNED
+ string and jump to quit. */
+ if (ctx->getResult () & GPG_EDITRES_ALREADY_SIGNED
&& *r_step != -1 && *r_step != 4) {
*r_step = step = -1;
return "";
@@ -573,7 +574,7 @@
if (*r_step == -1) {
*r_step = step = 4;
return ""; /* empty value to abort. */
- }
+ }
if (step == 0 && !strcmp (key, "keyedit.prompt")) {
*r_step = step = 1;
return "addrevoker";
@@ -621,6 +622,23 @@
return NULL;
}
+
+/* 'clean' command handler. */
+static const char*
+cmd_clean_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
+{
+ if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {
+ ctx->cmd_sent = 1;
+ return "clean";
+ }
+ if (!strcmp (key, "keyedit.prompt")) {
+ ctx->reset ();
+ return "save";
+ }
+ return NULL;
+}
+
+
/* 'enable' and 'disable' command handler. */
static const char *
cmd_enable_disable_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
@@ -659,10 +677,11 @@
case GPGME_STATUS_ALREADY_SIGNED:
ke->setResult (GPG_EDITRES_ALREADY_SIGNED);
break;
+
case GPGME_STATUS_BAD_PASSPHRASE:
ke->setResult (GPG_EDITRES_BAD_PASSPHRASE);
break;
-
+
default:
break;
}
@@ -741,6 +760,10 @@
out = cmd_addphoto_handler (ke, code, key);
break;
+ case GPG_EDITKEY_CLEAN:
+ out = cmd_clean_handler (ke, code, key);
+ break;
+
case GPG_EDITKEY_ENABLE:
case GPG_EDITKEY_DISABLE:
out = cmd_enable_disable_handler (ke, code, key,
Modified: trunk/Src/wptKeyManagerDlg.cpp
===================================================================
--- trunk/Src/wptKeyManagerDlg.cpp 2005-12-08 13:21:52 UTC (rev 118)
+++ trunk/Src/wptKeyManagerDlg.cpp 2005-12-09 08:04:51 UTC (rev 119)
@@ -1224,8 +1224,10 @@
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYGEN, dlg,
keygen_dlg_proc, (LPARAM)&genkey, _("Key Generation"),
IDS_WINPT_KEYGEN);
- if (genkey.newkey != NULL)
+ if (genkey.newkey != NULL) {
keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey);
+ keylist_sort (kmi->lv, KEY_SORT_USERID);
+ }
return TRUE;
case ID_KEYMISC_CARDNEW:
@@ -1246,8 +1248,10 @@
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, dlg,
keygen_wizard_dlg_proc, (LPARAM)&genkey, _("Key Generation Wizard"),
IDS_WINPT_KEYWIZARD);
- if (genkey.newkey != NULL)
+ if (genkey.newkey != NULL) {
keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey);
+ keylist_sort (kmi->lv, KEY_SORT_USERID);
+ }
return TRUE;
case ID_KEYMISC_SENDRECV:
@@ -1255,8 +1259,10 @@
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYSERVER, dlg,
keyserver_dlg_proc, (LPARAM)&genkey,
_("Keyserver Access"), IDS_WINPT_KEYSERVER);
- if (genkey.newkey != NULL)
- keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey);
+ if (genkey.newkey != NULL) {
+ keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey);
+ keylist_sort (kmi->lv, KEY_SORT_USERID);
+ }
return TRUE;
case ID_KEYMISC_GPGPREFS:
Modified: trunk/Src/wptKeyserver.cpp
===================================================================
--- trunk/Src/wptKeyserver.cpp 2005-12-08 13:21:52 UTC (rev 118)
+++ trunk/Src/wptKeyserver.cpp 2005-12-09 08:04:51 UTC (rev 119)
@@ -37,12 +37,14 @@
#include "wptGPG.h"
#include "wptRegistry.h"
+#define net_errno ((int)WSAGetLastError ())
+
static char base64code[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
keyserver server[MAX_KEYSERVERS] = {0};
static keyserver_proxy_ctx proxy = {0};
-static const char * server_list[] = {
+static const char *server_list[] = {
"hkp://wwwkeys.nl.pgp.net",
"hkp://wwwkeys.pl.pgp.net",
"hkp://wwwkeys.at.pgp.net",
@@ -59,19 +61,24 @@
"ldap://keyserver.pgp.com",
NULL
};
-static char hkp_errmsg[1024];
-static int hkp_err = 0;
-static u32 conf_timestamp = 0;
-char * default_keyserver = NULL;
-unsigned short default_keyserver_port = 0;
+static char hkp_errmsg[1024]; /* Holds the error message from the server */
+static int hkp_err = 0; /* != 0 indicates an error occurred. */
+static DWORD conf_timestamp = 0;/* timestamp of the configuration fiele. */
+
+char *default_keyserver = NULL;
+WORD default_keyserver_port = 0;
+
+
+/* Basic64 encode the input @inputstr to @outputstr. */
static void
-base64_encode( const char *inputstr, char *outputstr, int maxlen )
+base64_encode (const char *inputstr, char *outputstr, int maxlen)
{
int index = 0, temp = 0, res = 0, i = 0, inputlen = 0, len = 0;
- inputlen = strlen (inputstr); /* fixme: check if len > maxlen */
+ /* XXX: check len < maxlen. */
+ inputlen = strlen (inputstr);
for (i = 0; i <inputlen; i++) {
res = temp;
res = (res << 8) | (inputstr[i] & 0xFF);
@@ -84,7 +91,7 @@
temp = res;
}
- switch( index ) {
+ switch (index) {
case 0: break;
case 2: outputstr[len++] = base64code[temp << 2 & 0x3F];
outputstr[len++] = '='; break;
@@ -94,12 +101,12 @@
}
outputstr[len] = '\0';
-} /* base64_encode */
+}
/* Skip the URL schema and return only the host part of it. */
-static const char *
-skip_type_prefix (const char * hostname)
+static const char*
+skip_type_prefix (const char *hostname)
{
if (hostname && !strncmp (hostname, "http://", 7))
hostname += 7;
@@ -117,9 +124,9 @@
Return 0 on success. */
static int
check_hkp_response (const char *resp, int recv)
-{
+{
+ char *p, *end;
int ec, len;
- char *p, * end;
ec = recv ? WPTERR_WINSOCK_RECVKEY : WPTERR_WINSOCK_SENDKEY;
if (!strstr (resp, "HTTP/1.0 200 OK") &&
@@ -132,6 +139,7 @@
if (p && strlen (p) < sizeof (hkp_errmsg)) {
end = strstr (p, "</p>");
len = end? (end - p + 1) : strlen (p);
+ memset (hkp_errmsg, 0, sizeof (hkp_errmsg));
strncpy (hkp_errmsg, p, len);
hkp_err = 1;
}
@@ -155,6 +163,7 @@
while (recv (fd, &ch, 1, 0) > 0) {
*buf++ = ch;
count++;
+ /* XXX: remove the '\r' */
if (ch == '\n' || count == (buflen - 1)) {
*buf = 0;
if (nbytes)
@@ -177,20 +186,24 @@
FD_ZERO (&rfd);
FD_SET (fd, &rfd);
- if (select (fd + 1, &rfd, NULL, NULL, &tv) == SOCKET_ERROR)
+ if (select (fd + 1, &rfd, NULL, NULL, &tv) == SOCKET_ERROR) {
+ log_debug ("sock_select: select() failed ec=%d.\r\n", net_errno);
return SOCKET_ERROR;
+ }
if (FD_ISSET (fd, &rfd))
return 1;
return 0;
}
-/* Read from a socket with a fixed timeout of 10 seconds.
+/* Read from a socket @fd to buffer @buf with a fixed timeout
+ of 10 seconds. The amount of bytes which were read are
+ returned in @nbytes.
Return value: 0 on success. */
static int
sock_read (int fd, char *buf, int buflen, int *nbytes)
{
- int nread;
+ DWORD nread;
int nleft = buflen;
int rc, n = 0;
@@ -199,13 +212,15 @@
return WPTERR_WINSOCK_TIMEOUT;
rc = sock_select (fd, 1);
if (rc == SOCKET_ERROR)
- return SOCKET_ERROR;
- else if( !rc )
+ return rc;
+ else if (!rc)
n++;
else {
nread = recv (fd, buf, nleft, 0);
- if (nread == SOCKET_ERROR)
+ if (nread == SOCKET_ERROR) {
+ log_debug ("sock_read: recv() failed ec=%d.\r\n", net_errno);
return SOCKET_ERROR;
+ }
else if (!nread)
break;
nleft -= nread;
@@ -219,17 +234,19 @@
}
-/* Write @buf to a socket @fd. */
+/* Write the buffer @buf with the length @buflen to a socket @fd. */
static int
sock_write (int fd, const char *buf, int buflen)
{
- int nwritten;
+ DWORD nwritten;
int nleft = buflen;
while (nleft > 0) {
nwritten = send (fd, buf, nleft, 0);
- if (nwritten == SOCKET_ERROR)
+ if (nwritten == SOCKET_ERROR) {
+ log_debug ("sock_write: send() failed ec=%d\r\n", net_errno);
return SOCKET_ERROR;
+ }
nleft -= nwritten;
buf += nwritten;
}
@@ -238,15 +255,16 @@
}
+/* Set the default keyserver. */
void
set_default_kserver (void)
{
- char * p = get_reg_entry_keyserver ("Default");
+ char *p = get_reg_entry_keyserver ("Default");
free_if_alloc (default_keyserver);
default_keyserver = p && *p != ' ' ? p : m_strdup (DEF_HKP_KEYSERVER);
p = get_reg_entry_keyserver ("Default_Port");
if (p && *p) {
- default_keyserver_port = (u16)strtoul (p, NULL, 10);
+ default_keyserver_port = (WORD)strtoul (p, NULL, 10);
free_if_alloc (p);
}
else
@@ -260,8 +278,10 @@
{
WSADATA wsa;
- if (WSAStartup (0x202, &wsa))
+ if (WSAStartup (0x202, &wsa)) {
+ log_debug ("wsock_init: WSAStartup failed ec=%d\r\n", net_errno);
return WPTERR_WINSOCK_INIT;
+ }
set_default_kserver ();
return 0;
}
@@ -291,13 +311,13 @@
int ec = WSAGetLastError ();
switch (ec) {
- case WSAENETDOWN:
- return _("The network subsystem has failed");
- case WSAHOST_NOT_FOUND:
+ case WSAENETDOWN:
+ return _("The network subsystem has failed");
+ case WSAHOST_NOT_FOUND:
return _("Authoritative Answer Host not found");
- case WSAETIMEDOUT:
+ case WSAETIMEDOUT:
return _("The connection has been dropped because of a network failure");
- default:
+ default:
_snprintf (buf, sizeof (buf) -1, _("Unknown Winsock error ec=%d"),ec);
return buf;
}
@@ -318,7 +338,7 @@
/* Read a keyserver from the list at index @idx.
Return value: keyserver name at the given position. */
const char*
-kserver_get_hostname (int idx, int type, u16 *port)
+kserver_get_hostname (int idx, int type, WORD *port)
{
if (type == -1) {
*port = default_keyserver_port;
@@ -347,16 +367,14 @@
}
-/*
- * If the request contains the keyid, it have to be
- * always postfix with '0x'+keyid. This code checks
- * if the keyid is a decimal value and if so if it contains
- * the '0x'. If not it is inserted.
- */
+/* If the request contains the keyid, it have to be
+ always postfix with '0x'+keyid. This code checks
+ if the keyid is a decimal value and if so if it contains
+ the '0x'. If not it is inserted. */
const char*
kserver_check_keyid (const char *keyid)
{
- static char id[20];
+ static char id[21];
if (strstr (keyid, "@"))
return keyid; /* email address */
@@ -366,9 +384,10 @@
return id;
}
return keyid;
-} /* kserver_check_keyid */
+}
+/* Update the keyserver proxy user. */
static void
kserver_update_proxyuser (const char *proxy_user, const char *proxy_pass)
{
@@ -386,7 +405,7 @@
free_if_alloc (proxy.pass);
proxy.user = m_strdup (proxy_user);
proxy.pass = m_strdup (proxy_pass);
-} /* kserver_update_proxyuser */
+}
/* Check that the given buffer contains a valid keyserver URL. */
@@ -430,7 +449,7 @@
void
-keyserver_set_default (const char * hostname, u16 port)
+keyserver_set_default (const char *hostname, WORD port)
{
if (hostname) {
free_if_alloc (default_keyserver);
@@ -443,19 +462,18 @@
server[0].used = 1;
server[0].port = port;
server[0].proto = proto_from_URL (default_keyserver);
-} /* keyserver_set_default */
+}
-static const char *
-skip_whitespace (const char * str)
+/* Skip all kind of whitespace chars in @str. */
+static const char*
+skip_whitespace (const char *str)
{
- while (str && *str)
- {
+ while (str && *str) {
if (*str == ' ' ||
*str == '\t' ||
*str == '\n' ||
- *str == '\r')
- {
+ *str == '\r') {
str++;
continue;
}
@@ -470,10 +488,10 @@
{
struct stat statbuf;
FILE *fp;
- char buf[1024], * s, *p;
+ char buf[1024], * s, * p;
char *user = NULL, *pass = NULL;
+ int no_config=0, chk_pos=0;
int pos;
- int no_config=0, chk_pos=0;
for (pos = 0; pos < MAX_KEYSERVERS; pos++) {
server[pos].used = 0;
@@ -499,11 +517,11 @@
}
/* check if the host has a http:// prefix and skip it */
if( proxy.host && !strncmp( proxy.host, "http://", 7 ) ) {
- char *pr = m_strdup (proxy.host+7);
- if (!pr)
- BUG (NULL);
+ char *host = m_strdup (proxy.host+7);
+ if (!host)
+ BUG (0);
free_if_alloc (proxy.host);
- proxy.host = pr;
+ proxy.host = host;
}
free_if_alloc (user);
free_if_alloc (pass);
@@ -546,7 +564,8 @@
memcpy (server[pos].name, s, (p-s));
}
pos++;
- if (pos > MAX_KEYSERVERS) {
+ if (pos > MAX_KEYSERVERS)
+ {
msg_box (NULL, _("The keyserver limit is exceeded"), _("Keyserver Warning"), MB_INFO);
break;
}
@@ -566,8 +585,9 @@
} /* kserver_load_conf */
-const char *
-kserver_get_proxy (int * r_port)
+/* Return the proxy host and port if available. Null otherwise. */
+const char*
+kserver_get_proxy (int *r_port)
{
if (proxy.host) {
if (r_port)
@@ -575,10 +595,11 @@
return proxy.host;
}
return NULL;
-} /* kserver_get_proxy */
+}
-const char *
+/* Return a requested item from the proxy environment. */
+const char*
kserver_get_proxy_info (int id)
{
switch (id) {
@@ -586,15 +607,16 @@
case PROXY_PASS: return proxy.pass;
}
return NULL;
-} /* kserver_get_proxy_info */
+}
-/* Connect to the keyserver @hostname. */
+/* Connect to the keyserver @hostname (port @port).
+ Return value: 0 on success */
int
-kserver_connect (const char *hostname, u16 port, int *conn_fd)
+kserver_connect (const char *hostname, WORD port, int *conn_fd)
{
int rc, fd;
- u32 iaddr;
+ DWORD iaddr;
char host[128] = {0};
struct hostent *hp;
struct sockaddr_in sock;
@@ -625,7 +647,7 @@
memcpy (&sock.sin_addr, hp->h_addr, hp->h_length);
}
else {
- log_debug ("gethostbyname: failed.\r\n");
+ log_debug ("gethostbyname: failed ec=%d.\r\n", net_errno);
return WPTERR_WINSOCK_RESOLVE;
}
fd = socket (AF_INET, SOCK_STREAM, 0);
@@ -633,7 +655,7 @@
return WPTERR_WINSOCK_SOCKET;
rc = connect (fd, (struct sockaddr *) &sock, sizeof (sock));
if (rc == SOCKET_ERROR) {
- log_debug ("connect: failed.\r\n");
+ log_debug ("connect: failed ec=%d.\r\n", net_errno);
closesocket (fd);
return WPTERR_WINSOCK_CONNECT;
}
@@ -642,7 +664,7 @@
*conn_fd = fd;
WSASetLastError (0);
return 0;
-} /* kserver_connect */
+}
/* Perform URL-encoding on the given pubkey blob. */
@@ -650,14 +672,14 @@
kserver_urlencode (const char *pubkey, size_t octets, size_t *newlen)
{
char *p, numbuf[5];
- size_t j = 0;
+ size_t j;
size_t i, size;
- p = new char [2*octets];
+ p = new char [2*octets+1];
if (!p)
BUG (0);
- for (size=0, i=0; i < octets; i++) {
+ for (size = 0, i = 0; i < octets; i++) {
if (isalnum (pubkey[i]) || pubkey[i] == '-') {
p[size] = pubkey[i];
size++;
@@ -667,10 +689,10 @@
size++;
}
else {
- sprintf(numbuf, "%%%02X", pubkey[i]);
- for (j = 0; j<strlen(numbuf); j++) {
+ sprintf (numbuf, "%%%02X", pubkey[i]);
+ for (j = 0; j < strlen (numbuf); j++) {
p[size] = numbuf[j];
- size++;
+ size++;
}
}
}
@@ -682,13 +704,15 @@
/* Format a request for the given keyid (send). */
static char*
-kserver_send_request (const char *hostname, u16 port, const char *pubkey, int octets)
+kserver_send_request (const char *hostname, WORD port,
+ const char *pubkey, int octets)
{
- char *request = NULL, *enc_pubkey = NULL;
+ char *request = NULL;
+ char *enc_pubkey = NULL;
+ size_t enc_octets;
int reqlen;
- size_t enc_octets;
- log_debug ("kserver_send_request: %s:%d\n", hostname, port);
+ log_debug ("kserver_send_request: %s:%d\r\n", hostname, port);
if (!port)
port = HKP_PORT;
@@ -728,23 +752,25 @@
"\r\n"
"keytext=%s"
"\n",
- skip_type_prefix (hostname), port, enc_octets+9, enc_pubkey);
+ skip_type_prefix (hostname), port,
+ enc_octets+9, enc_pubkey);
}
free_if_alloc (enc_pubkey);
- log_debug ("%s\n", request);
+ log_debug ("%s\r\n", request);
return request;
-} /* kserver_send_request */
+}
-/* Interface receiving a public key. */
+/* Interface for receiving a public key. */
int
-kserver_recvkey (const char *hostname, u16 port, const char *keyid, char *key, int maxkeylen)
-{
+kserver_recvkey (const char *hostname, WORD port, const char *keyid,
+ char *key, int maxkeylen)
+{
+ char *request = NULL;
+ int conn_fd;
int rc, n;
- int conn_fd;
- char *request = NULL;
-
+
if (!port)
port = HKP_PORT;
hkp_err = 0; /* reset */
@@ -797,17 +823,17 @@
closesocket (conn_fd);
free_if_alloc (request);
return rc;
-} /* kserver_recvkey */
+}
/* Interface to send a public key. */
int
-kserver_sendkey (const char *hostname, u16 port, const char *pubkey, int len )
+kserver_sendkey (const char *hostname, WORD port, const char *pubkey, int len )
{
- int n, rc;
- int conn_fd;
char *request = NULL;
char log[2048];
+ int conn_fd, n;
+ int rc;
hkp_err = 0; /* reset */
rc = kserver_connect (hostname, port, &conn_fd);
@@ -820,22 +846,21 @@
goto leave;
}
- rc = sock_write( conn_fd, request, lstrlen(request) );
- if( rc == SOCKET_ERROR ) {
+ rc = sock_write (conn_fd, request, strlen (request));
+ if (rc == SOCKET_ERROR) {
rc = WPTERR_WINSOCK_SENDKEY;
goto leave;
}
- rc = sock_read( conn_fd, log, sizeof (log)-1, &n );
- if( rc == SOCKET_ERROR ) {
+ rc = sock_read (conn_fd, log, sizeof (log)-1, &n);
+ if (rc == SOCKET_ERROR) {
rc = WPTERR_WINSOCK_SENDKEY;
goto leave;
}
log_debug ("kserver_sendkey:\r\n%s\r\n", log);
-
rc = check_hkp_response (log, 0);
- if( rc )
+ if (rc)
goto leave;
WSASetLastError (0);
@@ -844,16 +869,17 @@
closesocket (conn_fd);
free_if_alloc (request);
return rc;
-} /* kserver_sendkey */
+}
int
-kserver_search_init (const char * hostname, u16 port, const char * keyid, int * conn_fd)
+kserver_search_init (const char *hostname, WORD port,
+ const char *keyid, int *conn_fd)
{
+ char *request = NULL;
+ int n=0;
int rc, sock_fd;
- int n=0;
- char * request = NULL;
-
+
rc = kserver_connect (hostname, port, &sock_fd);
if (rc) {
*conn_fd = 0;
@@ -893,9 +919,10 @@
leave:
free_if_alloc (request);
return rc;
-} /* kserver_search_init */
+}
+/* Check keyserver response. */
int
kserver_search_chkresp (int fd)
{
@@ -912,7 +939,7 @@
if (strncmp (buf+(8+1), "200", 3))
return WPTERR_KEYSERVER_NOTFOUND;
return 0;
-} /* kserver_search_chkresp */
+}
int
@@ -921,12 +948,12 @@
char buf[1024], *p;
int uidlen, nbytes, pos = 0;
- log_debug ("keyserver_search:\n");
+ log_debug ("keyserver_search:\r\n");
if (sock_getline (fd, buf, sizeof (buf) - 1, &nbytes))
return WPTERR_GENERAL;
- log_debug ("%s\n", buf);
+ log_debug ("%s\r\n", buf);
if (!strncmp (buf, "pub", 3)) {
int revoked = strstr (buf, "KEY REVOKED") != NULL? 1 : 0;
@@ -959,7 +986,8 @@
p = strchr (key->uid, '&');
if (p) {
key->uid[(p-key->uid)] = '<';
- memmove (key->uid+(p-key->uid)+1, key->uid+(p-key->uid)+4, strlen (key->uid)-3);
+ memmove (key->uid+(p-key->uid)+1, key->uid+(p-key->uid)+4,
+ strlen (key->uid)-3);
}
return 0;
}
@@ -982,7 +1010,7 @@
return WPTERR_GENERAL;
node = new keyserver_node;
if( !node )
- BUG( NULL );
+ BUG (NULL);
memset( node, 0, sizeof *node );
node->used = 1;
@@ -1084,17 +1112,20 @@
} /* kserver_cfgfile_release */
+/* Release mbmers in the proxy context @ctx. */
void
proxy_release( keyserver_proxy_ctx *ctx )
{
- free_if_alloc( ctx->host );
- free_if_alloc( ctx->pass );
- free_if_alloc( ctx->user );
-} /* proxy_release */
+ free_if_alloc (ctx->host);
+ free_if_alloc (ctx->pass);
+ free_if_alloc (ctx->user);
+}
+/* Receive an key via LDAP from host @host with the keyid @keyid.
+ @key contains the key on success. */
int
-ldap_recvkey (const char * host, const char * keyid, char * key, int maxkeylen)
+ldap_recvkey (const char *host, const char *keyid, char *key, int maxkeylen)
{
const char *s;
char *ksprg = NULL, *p = NULL;
@@ -1186,11 +1217,11 @@
free_if_alloc( p );
free_if_alloc( ksprg );
return rc;
-} /* ldap_recvkey */
+}
static int
-finger_readline (int fd, char * buf, int nbytes)
+finger_readline (int fd, char *buf, int nbytes)
{
char c = 0;
int n, pos = 0;
@@ -1212,8 +1243,10 @@
}
+/* Receive an key via FINGER from host @host with the user @user.
+ On success @key contains the key. */
int
-finger_recvkey (const char * host, const char * user, char * key, int maxkeylen)
+finger_recvkey (const char *host, const char *user, char *key, int maxkeylen)
{
struct hostent * hp;
struct sockaddr_in saddr;
@@ -1271,6 +1304,7 @@
}
+/* Check if the given name @name is a valid hostname. */
int
check_IP_or_hostname (const char *name)
{
Modified: trunk/Src/wptMDSumDlg.cpp
===================================================================
--- trunk/Src/wptMDSumDlg.cpp 2005-12-08 13:21:52 UTC (rev 118)
+++ trunk/Src/wptMDSumDlg.cpp 2005-12-09 08:04:51 UTC (rev 119)
@@ -84,7 +84,7 @@
}
}
SetDlgItemText (dlg, IDC_MDSUM_COPY, _("&Save..."));
- SetDlgItemText (dlg, IDOK, _("&Exit"));
+ SetDlgItemText (dlg, IDOK, _("&Close"));
SetWindowText (dlg, _("Print Message Digest"));
SetForegroundWindow (dlg);
break;
Modified: trunk/TODO
===================================================================
--- trunk/TODO 2005-12-08 13:21:52 UTC (rev 118)
+++ trunk/TODO 2005-12-09 08:04:51 UTC (rev 119)
@@ -1,12 +1,6 @@
Feel free if you think there is missing something to mail me.
-0.11.x-
- * Delete empty files when decryption failed or encryption was
- cancelled.
-
- * Check that the reload keycache flag is set for all keyserver
- operations.
-
* winpt --keymanager aborts when the keyring is empty on the
first start.
More information about the Winpt-commits
mailing list