[pan2] https://bugzilla.gnome.org/show_bug.cgi?id=680295
- From: Heinrich MÃller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2] https://bugzilla.gnome.org/show_bug.cgi?id=680295
- Date: Sun, 16 Dec 2012 21:25:58 +0000 (UTC)
commit f7ba6478bf24858c712d53cc2566a4f40bc8a9b3
Author: Heinrich MÃller <henmull src gnome org>
Date: Sun Dec 16 22:25:38 2012 +0100
https://bugzilla.gnome.org/show_bug.cgi?id=680295
pan/data-impl/groups.cc | 19 ++---------------
pan/data-impl/server.cc | 4 +-
pan/data/cert-store.cc | 49 +++++++++++++++++++++++----------------------
pan/data/cert-store.h | 2 -
pan/general/debug.h | 4 +-
pan/general/file-util.cc | 15 +++++++++++++-
pan/general/file-util.h | 5 ++++
pan/gui/pan.cc | 2 +-
8 files changed, 52 insertions(+), 48 deletions(-)
---
diff --git a/pan/data-impl/groups.cc b/pan/data-impl/groups.cc
index b9ef49c..6286f01 100644
--- a/pan/data-impl/groups.cc
+++ b/pan/data-impl/groups.cc
@@ -155,20 +155,6 @@ DataImpl :: load_newsrc (const Quark & server,
}
}
-namespace {
- inline std::string newsrc_fn(const std::string &base)
- {
- const char *fn = base.c_str();
- if (g_path_is_absolute(fn))
- return base;
- const char *ph = file::get_pan_home().c_str();
- char *temp = g_build_filename(ph, fn, NULL);
- std::string out(temp);
- g_free(temp);
- return out;
- }
-}
-
void
DataImpl :: load_newsrc_files (const DataIO& data_io)
{
@@ -180,7 +166,7 @@ DataImpl :: load_newsrc_files (const DataIO& data_io)
foreach_const (servers_t, _servers, sit) {
const Quark key (sit->first);
- const std::string filename = newsrc_fn (sit->second.newsrc_filename);
+ const std::string filename = file::absolute_fn("", sit->second.newsrc_filename);
if (file::file_exists (filename.c_str())) {
LineReader * in (data_io.read_file (filename));
load_newsrc (key, in, s, u);
@@ -227,7 +213,8 @@ DataImpl :: save_newsrc_files (DataIO& data_io) const
const Quark& server (sit->first);
// write this server's newsrc
- const std::string filename = newsrc_fn (sit->second.newsrc_filename);
+ const std::string filename = file::absolute_fn("", sit->second.newsrc_filename);
+
std::ostream& out (*data_io.write_file (filename));
std::string newsrc_string;
alpha_groups_t::const_iterator sub_it (_subscribed.begin());
diff --git a/pan/data-impl/server.cc b/pan/data-impl/server.cc
index 40f27c0..c227d03 100644
--- a/pan/data-impl/server.cc
+++ b/pan/data-impl/server.cc
@@ -468,10 +468,10 @@ DataImpl :: load_server_properties (const DataIO& source)
s.username = kv["username"];
#ifndef HAVE_GKR
s.password = kv["password"];
-#endif
+#else
if (!_prefs.get_flag("use-gnome-keyring", false))
s.password = kv["password"];
-
+#endif
s.port = to_int (kv["port"], STD_NNTP_PORT);
s.max_connections = to_int (kv["connection-limit"], 2);
s.article_expiration_age = to_int(kv["expire-articles-n-days-old"], 31);
diff --git a/pan/data/cert-store.cc b/pan/data/cert-store.cc
index 65ee25e..8a33d32 100644
--- a/pan/data/cert-store.cc
+++ b/pan/data/cert-store.cc
@@ -208,12 +208,12 @@ namespace pan
{
size_t filelen;
- char * buf;
Data::Server* s(_data.find_server(server));
if (!s) return false;
+ if (s->cert.empty()) return false;
- const char* filename(fn ? fn : s->cert.c_str());
+ const char* filename(fn ? fn : file::absolute_fn("ssl_certs", s->cert).c_str());
if (!filename) return false;
FILE * fp = fopen(filename, "rb");
@@ -222,7 +222,7 @@ namespace pan
fseek (fp, 0, SEEK_END);
filelen = ftell (fp);
fseek (fp, 0, SEEK_SET);
- buf = new char[filelen];
+ char * buf = new char[filelen];
size_t dummy (fread (buf, sizeof(char), filelen, fp)); // silence compiler
gnutls_datum_t in;
@@ -258,7 +258,17 @@ namespace pan
GError* err(NULL);
foreach_const(quarks_t, servers, it)
- if (import_from_file(*it)) ++cnt;
+ {
+ if (import_from_file(*it))
+ {
+ ++cnt;
+ }
+ else
+ {
+ Data::Server* s(_data.find_server(*it));
+ s->cert.clear();
+ }
+ }
// get certs from ssl certs directory
char * ssldir(0);
@@ -320,14 +330,12 @@ namespace pan
CertStore :: CertStore (Data& data): _data(data)
{
- char buf[2048];
- g_snprintf(buf,sizeof(buf),"%s%cssl_certs",file::get_pan_home().c_str(), G_DIR_SEPARATOR);
- _path = buf;
- if (!file::ensure_dir_exists (buf))
+ _path = file::absolute_fn("ssl_certs", "");
+ if (!file::ensure_dir_exists (_path))
{
std::cerr<<_("Error initializing Certificate Store. Check that the permissions for the folders "
"~/.pan2 and ~/.pan2/ssl_certs are set correctly. Fatal, exiting.");
- file::print_file_info(std::cerr, buf);
+ file::print_file_info(std::cerr, _path.c_str());
exit(EXIT_FAILURE);
}
@@ -355,17 +363,21 @@ namespace pan
_data.get_server_addr(server, addr, port);
_cert_to_server[server] = cert;
- const char* buf(build_cert_name(addr).c_str());
+ std::stringstream buffer;
+ buffer << addr << ".pem";
+ const char* buf (buffer.str().c_str());
+
+ std::cerr<<"adding cert "<<buf<<"\n";
+
+ FILE * fp = fopen(file::absolute_fn("ssl_certs", buf).c_str(), "wb");
+ if (!fp) return false;
_data.set_server_cert(server, buf);
SaveCBStruct* cbstruct = new SaveCBStruct(*this, server, _data);
g_idle_add (save_server_props_cb, cbstruct);
- FILE * fp = fopen(buf, "wb");
- if (!fp) return false;
size_t outsize;
-
/* make up for dumbness of this function */
gnutls_x509_crt_export (cert, GNUTLS_X509_FMT_PEM, NULL, &outsize);
char* out = new char[outsize];
@@ -389,17 +401,6 @@ namespace pan
return true;
}
-
- std::string
- CertStore :: build_cert_name(std::string& host)
- {
- char buf[2048];
- g_snprintf(buf,sizeof(buf),"%s%cssl_certs%c%s.pem",file::get_pan_home().c_str(),
- G_DIR_SEPARATOR,G_DIR_SEPARATOR, host.c_str());
- return std::string(buf);
- }
-
-
} // namespace pan
diff --git a/pan/data/cert-store.h b/pan/data/cert-store.h
index aa391fa..891f93e 100644
--- a/pan/data/cert-store.h
+++ b/pan/data/cert-store.h
@@ -97,8 +97,6 @@ namespace pan
void remove (const Quark&);
bool exist (const Quark& q) { return (_cert_to_server.count(q) > 0); }
- static std::string build_cert_name(std::string& host);
-
gnutls_certificate_credentials_t get_creds() { return _creds; }
struct Listener
diff --git a/pan/general/debug.h b/pan/general/debug.h
index 23fada3..265658f 100644
--- a/pan/general/debug.h
+++ b/pan/general/debug.h
@@ -56,13 +56,13 @@ namespace pan
#define debug_SSL(A) \
do { \
if (_dbg_ssl) \
- _dbg_file<< LINE_ID << ' ' << A << '\n'; \
+ std::cout << A << '\n'; \
} while (0)
#define debug_SSL_verbatim(A) \
do { \
if (_dbg_ssl) \
- _dbg_file<< A ; \
+ std::cout << A << '\n'; \
} while (0)
#ifndef UNUSED
diff --git a/pan/general/file-util.cc b/pan/general/file-util.cc
index c49f590..4ea2e77 100644
--- a/pan/general/file-util.cc
+++ b/pan/general/file-util.cc
@@ -97,6 +97,19 @@ file :: get_pan_home ()
return pan_home;
}
+std::string
+file :: absolute_fn(const std::string &dir, const std::string &base)
+{
+const char *fn = base.c_str();
+if (g_path_is_absolute(fn))
+ return base;
+const char *ph = file::get_pan_home().c_str();
+char *temp = g_build_filename(ph, dir.empty() ? "" : dir.c_str(), fn, NULL);
+std::string out(temp);
+g_free(temp);
+return out;
+}
+
const char*
file :: pan_strerror (int error_number)
{
@@ -119,7 +132,7 @@ namespace
if (stat (d, &sb) == -1) return EX_NOFILE;
const char* user(g_get_user_name());
struct passwd* pw(getpwnam(user));
- if (sb.st_mode & S_IXUSR || ((sb.st_mode & S_IXGRP ) && pw->pw_gid == sb.st_gid))
+ if ((sb.st_mode & S_IXUSR) || ((sb.st_mode & S_IXGRP ) && pw->pw_gid == sb.st_gid))
return EX_SUCCESS;
return EX_BIT;
#else
diff --git a/pan/general/file-util.h b/pan/general/file-util.h
index 51744ac..7c211a8 100644
--- a/pan/general/file-util.h
+++ b/pan/general/file-util.h
@@ -62,6 +62,11 @@ namespace pan
std::string get_pan_home ();
/**
+ * Returns an absolute filename of a file
+ */
+ std::string absolute_fn(const std::string &dir, const std::string &base);
+
+ /**
* If the specified directory doesn't exist, Pan tries to create it.
* @param path
* @return true if the directory already existed or was created; false otherwise
diff --git a/pan/gui/pan.cc b/pan/gui/pan.cc
index cbf903c..85cf7f6 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -906,7 +906,7 @@ main (int argc, char *argv[])
url = tok;
else if (!strcmp(tok,"--no-gui") || !strcmp(tok,"--nogui"))
gui = false;
- else if (!strcmp (tok, "--debug")) { // do --debug --debug for verbose debug
+ else if (!strcmp (tok, "--debug")) { // use --debug --debug for verbose debug
console();
if (_debug_flag) _debug_verbose_flag = true;
else _debug_flag = true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]