[gq-commit] gq/src common.h,1.16,1.17 configfile.c,1.25,1.26 configfile.h,1.16,1.17 prefs.c,1.24,1.2
Status: Beta
Brought to you by:
sur5r
From: <sta...@us...> - 2002-07-23 13:50:11
|
Update of /cvsroot/gqclient/gq/src In directory usw-pr-cvs1:/tmp/cvs-serv15276 Modified Files: common.h configfile.c configfile.h prefs.c Log Message: * Passwords will be now be encoded in the config file. gq askes if it should upgrade the configuration file to a new version (which will hold encoded passwords) Index: common.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/common.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** common.h 15 Jul 2002 18:44:03 -0000 1.16 --- common.h 23 Jul 2002 13:50:06 -0000 1.17 *************** *** 70,73 **** --- 70,74 ---- char binddn[MAX_DN_LEN]; char bindpw[MAX_BINDPW_LEN]; + char pwencoding[32]; /* split the "configuration" password from the one entered by hand. This simplifies the handling of the configured password *************** *** 89,93 **** statistical number */ int missing_closes; /* incremented on every open_connection, ! decrementen on each close, close_connection really closes only if this drops to zero */ struct server_schema *ss; --- 90,94 ---- statistical number */ int missing_closes; /* incremented on every open_connection, ! decremented on each close, close_connection really closes only if this drops to zero */ struct server_schema *ss; Index: configfile.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/configfile.c,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** configfile.c 15 Jul 2002 18:44:03 -0000 1.25 --- configfile.c 23 Jul 2002 13:50:06 -0000 1.26 *************** *** 33,36 **** --- 33,37 ---- #include <ctype.h> #include <signal.h> + #include <time.h> #include <glib.h> *************** *** 44,47 **** --- 45,49 ---- #include "debug.h" #include "i18n.h" + #include "ldif.h" /* for b64_encode */ *************** *** 53,56 **** --- 55,61 ---- /* global options */ + { "config-version", T_CONFIG_VERSION, NEEDS_CLOSE }, + { "asked-config-version", T_ASKED_CONFIG_VERSION, NEEDS_CLOSE }, + { "last-asked", T_LAST_ASKED, NEEDS_CLOSE }, { "confirm-mod", T_CONFIRM_MOD, NEEDS_CLOSE }, { "search-argument", T_SEARCH_ARGUMENT, NEEDS_CLOSE }, *************** *** 70,73 **** --- 75,79 ---- { "binddn", T_BINDDN, NEEDS_CLOSE|NEEDS_DATA }, { "bindpw", T_BINDPW, NEEDS_CLOSE|NEEDS_DATA }, + { "pw-encoding", T_PWENCODING, NEEDS_CLOSE|NEEDS_DATA }, { "bindtype", T_BINDTYPE, NEEDS_CLOSE|NEEDS_DATA }, { "search-attribute",T_SEARCHATTR, NEEDS_CLOSE|NEEDS_DATA }, *************** *** 256,259 **** --- 262,283 ---- } + /* parses and returns an integer value from the configfile */ + long config_get_long(struct configfile *f) + { + char errstr[256]; + char *ep; + long l; + + l = strtol(f->cur_string, &ep, 0); + if (ep && *ep) { + snprintf(errstr, sizeof(errstr), + _("line %d: could not parse integer value '%s'. Should be decimal integer"), + f->line, f->cur_string); + error_push(f->err_context, errstr); + return 0; + } + + return l; + } void config_id_string(struct configfile *f) *************** *** 339,342 **** --- 363,367 ---- struct configfile *f; char errstr[256]; + struct ldapserver *s; /* DEBUG *************** *** 378,381 **** --- 403,415 ---- /* global settings */ switch(f->stack[f->sp - 1]) { + case T_CONFIG_VERSION: + config.config_version = config_get_long(f); + break; + case T_ASKED_CONFIG_VERSION: + config.asked_version = config_get_long(f); + break; + case T_LAST_ASKED: + config.last_asked = config_get_long(f); + break; case T_CONFIRM_MOD: config.confirm_mod = config_get_bool(f); *************** *** 427,431 **** break; case T_LDAPPORT: ! f->cur_ldapserver->ldapport = atoi(f->cur_string); break; case T_BASEDN: --- 461,465 ---- break; case T_LDAPPORT: ! f->cur_ldapserver->ldapport = config_get_long(f); break; case T_BASEDN: *************** *** 441,444 **** --- 475,483 ---- sizeof(f->cur_ldapserver->bindpw) - 1); break; + case T_PWENCODING: + strncpy(f->cur_ldapserver->pwencoding, + f->cur_string, + sizeof(f->cur_ldapserver->pwencoding) - 1); + break; case T_BINDTYPE: f->cur_ldapserver->bindtype = tokenize(token_bindtype, f->cur_string); *************** *** 448,452 **** break; case T_MAXENTRIES: ! f->cur_ldapserver->maxentries = atoi(f->cur_string); break; case T_CACHECONN: --- 487,491 ---- break; case T_MAXENTRIES: ! f->cur_ldapserver->maxentries = config_get_long(f); break; case T_CACHECONN: *************** *** 457,461 **** break; case T_LOCAL_CACHE_TIMEOUT: ! f->cur_ldapserver->local_cache_timeout = atoi(f->cur_string); break; case T_ASK_PW: --- 496,500 ---- break; case T_LOCAL_CACHE_TIMEOUT: ! f->cur_ldapserver->local_cache_timeout = config_get_long(f); break; case T_ASK_PW: *************** *** 569,575 **** } error_flush(f->err_context); FREE(f, "struct configfile"); - } --- 608,628 ---- } + /* walk the list of ldapservers and decode the passwords */ + + for ( s = config.ldapservers ; s ; s = s->next ) { + if (strcasecmp(s->pwencoding, "Base64") == 0 && s->bindpw[0]) { + GByteArray *o = g_byte_array_new(); + b64_decode(o, s->bindpw, strlen(s->bindpw)); + + memset(s->bindpw, 0, sizeof(s->bindpw)); + strncpy(s->bindpw, o->data, MAX(o->len, sizeof(s->bindpw) - 1)); + } else if (s->bindpw[0] && s->pwencoding[0]) { + error_push(f->err_context, + _("Unsupported password encoding")); + } + } + error_flush(f->err_context); FREE(f, "struct configfile"); } *************** *** 611,614 **** --- 664,671 ---- if(stat(rcpath, &sfile) == -1 || !sfile.st_size) { error_flush(load_context); + /* If there is no configuration file, we start with the + current configuration file version */ + config.config_version = CURRENT_CONFIG_VERSION; + config.asked_version = CURRENT_CONFIG_VERSION; return; } *************** *** 723,726 **** --- 780,790 ---- write_context = error_new_context(_("Error writing configfile")); + if (config.config_version > CURRENT_CONFIG_VERSION) { + error_push(write_context, + _("Configuration file version too high - saving the configuration is not possible")); + error_flush(write_context); + return; + } + server = config.ldapservers; wc = MALLOC(sizeof(struct writeconfig), "struct writeconfig"); *************** *** 749,752 **** --- 813,823 ---- /* global settings */ wc->indent++; + + if (config.config_version > 0) { + config_write_int(wc, config.config_version, "config-version"); + config_write_int(wc, config.config_version, "asked-config-version"); + config_write_int(wc, config.config_version, "last-asked"); + } + config_write_bool(wc, config.confirm_mod, "confirm-mod"); config_write_string(wc, detokenize(token_searchargument, config.search_argument), *************** *** 773,783 **** config_write_string_ne(wc, server->basedn, "basedn"); config_write_string_ne(wc, server->binddn, "binddn"); ! config_write_string_ne(wc, server->bindpw, "bindpw"); ! #if 0 ! b64_encode(pw, server->bindpw, strlen(server->bindpw)); ! config_write_string_ne(wc, pw->str, "bindpw"); ! config_write_string_ne(wc, "Base64", "pw-encoding"); ! g_string_free(pw); ! #endif if(server->bindtype != DEFAULT_BINDTYPE) --- 844,859 ---- config_write_string_ne(wc, server->basedn, "basedn"); config_write_string_ne(wc, server->binddn, "binddn"); ! ! if (config.config_version == 0) { ! config_write_string_ne(wc, server->bindpw, "bindpw"); ! } else { ! GString *pw = g_string_sized_new(32); ! ! b64_encode(pw, server->bindpw, strlen(server->bindpw)); ! config_write_string_ne(wc, pw->str, "bindpw"); ! config_write_string_ne(wc, "Base64", "pw-encoding"); ! ! g_string_free(pw, TRUE); ! } if(server->bindtype != DEFAULT_BINDTYPE) *************** *** 868,871 **** --- 944,948 ---- server->binddn[0] = '\0'; server->bindpw[0] = '\0'; + server->pwencoding[0] = '\0'; server->enteredpw[0] = '\0'; server->bindtype = DEFAULT_BINDTYPE; *************** *** 892,896 **** --- 969,977 ---- { struct ldapserver *default_server; + gboolean dosave = FALSE; + config.config_version = 0; + config.asked_version = 0; + config.last_asked = 0; config.ldapservers = NULL; config.templates = NULL; *************** *** 907,910 **** --- 988,1014 ---- load_config(); + + if (config.config_version > CURRENT_CONFIG_VERSION) { + /* incompatible configuration file version (version too high!) */ + + single_warning_popup(_("Incompatible configuration file version\n (version of configuration file is too high).\nTrying the best, but changing the configuration is not possible.")); + } + + if (config.config_version < CURRENT_CONFIG_VERSION + && (config.asked_version < CURRENT_CONFIG_VERSION || + (config.asked_version == CURRENT_CONFIG_VERSION && + (time(NULL) - config.last_asked) > 31*86400))) { + int rc = question_popup(_("Upgrade configuration?"), + _("Do you want to upgrade to the lastest configuration file version?\nIf you say no you may not be able to use all functionalities.\nIf you say yes you may not be able to use your configuration with older versions of gq.\n")); + + config.asked_version = CURRENT_CONFIG_VERSION; + config.last_asked = time(NULL); + + if (rc) { + config.config_version = CURRENT_CONFIG_VERSION; + dosave = TRUE; + } + } + if(!config.ldapservers) { /* no ldapserver defined in configfile */ *************** *** 920,923 **** --- 1024,1029 ---- } + /* actually do the upgrade if requested */ + if (dosave) save_config(); } Index: configfile.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/configfile.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** configfile.h 17 Jul 2002 21:42:49 -0000 1.16 --- configfile.h 23 Jul 2002 13:50:06 -0000 1.17 *************** *** 31,34 **** --- 31,35 ---- #include <glib.h> + #define CURRENT_CONFIG_VERSION 1 #define CONFIG_INDENT_STRING " " *************** *** 36,39 **** --- 37,42 ---- #define RCFILE ".gq" + /* do not forget to set T_HIGHEST to the highest used token value below */ + /* tokens for config file */ #define T_UNKNOWN 0 *************** *** 51,54 **** --- 54,61 ---- #define T_SCHEMASERVER 18 + #define T_CONFIG_VERSION 51 + #define T_ASKED_CONFIG_VERSION 52 + #define T_LAST_ASKED 53 + /* per-server tokens */ #define T_LDAPSERVER 20 *************** *** 69,72 **** --- 76,80 ---- #define T_HIDE_INTERNAL 35 #define T_SHOW_REF 36 + #define T_PWENCODING 37 /* template tokens */ *************** *** 83,86 **** --- 91,96 ---- #define T_DATA 50 + #define T_HIGHEST 53 + /* bitwise flags used in keywordlist.flags */ #define NEEDS_CLOSE 1 *************** *** 114,117 **** --- 124,138 ---- struct gq_config { /* persistent */ + long config_version; /* 0 for old-style configuration file format + 1 introduces password encoding */ + long asked_version; /* holds the highest config file version for + which gq has already asked if it should + upgrade to. This is to avoid that on every + start of gq the used gets asked if he + wants to upgrade to a newer configfile + version */ + long last_asked; /* timestamp of lask asking for upgrade to a + newer confiig file. */ + struct ldapserver *ldapservers; GList *templates; Index: prefs.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/prefs.c,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** prefs.c 12 Jul 2002 20:27:52 -0000 1.24 --- prefs.c 23 Jul 2002 13:50:06 -0000 1.25 *************** *** 2,5 **** --- 2,6 ---- GQ -- a GTK-based LDAP client Copyright (C) 1998-2001 Bert Vermeulen + Parts: Copyright (C) 2002 Peter Stamfest and Bert Vermeulen This program is released under the Gnu General Public License with |