diff options
| author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-18 10:50:46 +0100 |
|---|---|---|
| committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-18 10:50:46 +0100 |
| commit | a053a6580b09f1d22eed54f4ebcc09ccfd0f62cd (patch) | |
| tree | 3a90692eb9340fda72865e71fea4009a104ca962 /database | |
| parent | 720ba766f16af0b071b0008468cace1ea794fb65 (diff) | |
| download | eurephia-a053a6580b09f1d22eed54f4ebcc09ccfd0f62cd.tar.gz eurephia-a053a6580b09f1d22eed54f4ebcc09ccfd0f62cd.tar.xz eurephia-a053a6580b09f1d22eed54f4ebcc09ccfd0f62cd.zip | |
Added pwhash attribute in fieldMapping XML for password fields.
This attribute can be "sha512" if the contents of the field is already
hashed with SHA512. The other official value is "none", which will then
tell eDBxmlMapping(...) to hash the value. Unknown values will be
treated like 'none'.
Diffstat (limited to 'database')
| -rw-r--r-- | database/eurephiadb_mapping.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/database/eurephiadb_mapping.c b/database/eurephiadb_mapping.c index cd222c7..9b33f74 100644 --- a/database/eurephiadb_mapping.c +++ b/database/eurephiadb_mapping.c @@ -48,6 +48,7 @@ const char *TABLE_NAME[] = { // in eurephia_xml.h, which would then cause multiple declarations of these functions if that // include file gets included here. char *xmlGetAttrValue(xmlAttr *properties, const char *key); +char *xmlExtractContent(xmlNode *n); void eDBfreeMapping(eDBfieldMap *p) { @@ -157,14 +158,20 @@ eDBfieldMap *eDBxmlMapping(eurephiaCTX *ctx, eDBfieldMap *dbmap, const char *tbl if( nptr->name != NULL ) { int setnull = 0; xmlAttr *atr; + char *pwhash = NULL; // Check if we have the "setnull" attribute set to "1" for( atr = nptr->properties; atr != NULL; atr = atr->next ) { - if( (atr->name != NULL) && (xmlStrcmp(atr->name, (xmlChar *)"setnull") == 0) ) { + if( atr->name == NULL ) { + // Skip nodes without name (just in case) + continue; + } + if( xmlStrcmp(atr->name, (xmlChar *)"setnull") == 0 ) { xmlNode *n = atr->children; setnull = (((n != NULL) && (n->content != NULL) && (xmlStrcmp(n->content,(xmlChar *)"1") == 0)) ? 1 : 0); - break; + } else if( xmlStrcmp(atr->name, (xmlChar *)"pwhash") == 0 ) { + pwhash = xmlExtractContent(atr->children); } } @@ -184,9 +191,16 @@ eDBfieldMap *eDBxmlMapping(eurephiaCTX *ctx, eDBfieldMap *dbmap, const char *tbl break; case ft_PASSWD: // If it is a password field type, hash the value - ptr->value = (nptr->children != NULL - ? passwdhash((char *)nptr->children->content) - : strdup("")); + if( strcmp(pwhash, "sha512") == 0 ) { + ptr->value = (nptr->children != NULL + ? (char *)nptr->children->content + : strdup("")); + } else { + // Hash value if it is not hashed or not approved hashing + ptr->value = (nptr->children != NULL + ? passwdhash((char *)nptr->children->content) + : strdup("")); + } break; default: |
