#include #define _XOPEN_SOURCE #include #include #include #include "cgilib.h" /* This is ``salts'', the shared secret, it would need changing on a per- installation basis */ char salts[]="abcdefghijklmnopqrstuvwxyz"; /* Structure for memoizing transformations of outgoing CGI variables, when we need to print a variable, we must make sure to print memogrify() */ struct memo { char *str, *token; struct memo *next; } *memobase = NULL; /* This is the "heavy lifter" tranformation code */ char *transmogrify (char *str, int rv) { if (rv<0) rv=rand()%(sizeof(salts)-2); return crypt(str, salts+rv); } /* Memogrify finds a previously-transformed name, if available, otherwise generates a new transformation and caches it. */ char *memogrify (char *str) { struct memo *tmp; for (tmp=memobase;tmp;tmp=tmp->next) { if (strcmp(str, tmp->str) == 0) { return tmp->token; } } tmp=malloc(sizeof(struct memo)); tmp->str=strdup(str); tmp->token=strdup(transmogrify(str, -1)); tmp->next=memobase; memobase=tmp; return memobase->token; } /* This interfaces with and has the same signature as find_param from cgilib. It will try all possibly-generated transformations of a parameter name and return whatever it finds */ struct fieldval *find_param_crypto (char *name) { int c; struct fieldval *rv; for (c=0;c