work on versioning; new log_fn function

svn:r288
This commit is contained in:
Nick Mathewson 2003-05-09 02:25:37 +00:00
parent 9f38ba196c
commit 0957ffeb83
6 changed files with 38 additions and 24 deletions

View File

@ -9,6 +9,9 @@
/* /*
* Changes : * Changes :
* $Log$ * $Log$
* Revision 1.2 2003/05/09 02:25:37 nickm
* work on versioning; new log_fn function
*
* Revision 1.1 2002/09/03 18:43:50 nickm * Revision 1.1 2002/09/03 18:43:50 nickm
* Add function to fake a poll call using select * Add function to fake a poll call using select
* *
@ -17,7 +20,6 @@
#define __FAKEPOLL_H #define __FAKEPOLL_H
#include "orconfig.h" #include "orconfig.h"
#undef VERSION
#ifndef HAVE_POLL_H #ifndef HAVE_POLL_H
#ifndef HAVE_SYS_POLL_H #ifndef HAVE_SYS_POLL_H

View File

@ -8,8 +8,11 @@
/* /*
* Changes : * Changes :
* $Log$ * $Log$
* Revision 1.1 2002/06/26 22:45:50 arma * Revision 1.2 2003/05/09 02:25:37 nickm
* Initial revision * work on versioning; new log_fn function
*
* Revision 1.1.1.1 2002/06/26 22:45:50 arma
* initial commit: current code
* *
* Revision 1.5 2002/01/26 18:52:00 mp292 * Revision 1.5 2002/01/26 18:52:00 mp292
* Reviewed according to Secure-Programs-HOWTO. * Reviewed according to Secure-Programs-HOWTO.
@ -36,5 +39,12 @@
/* Outputs a message to stdout and also logs the same message using syslog. */ /* Outputs a message to stdout and also logs the same message using syslog. */
void log(int severity, const char *format, ...); void log(int severity, const char *format, ...);
#ifdef __GNUCC__
#define log_fn(severity, format, args...) \
log((severity), __PRETTY_FUNCTION__ # "(): " # format, ##args)
#else
#define log_fn log
#endif
# define __LOG_H # define __LOG_H
#endif #endif

View File

@ -708,8 +708,7 @@ dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir,
eos = s+maxlen; eos = s+maxlen;
strncpy(s, strncpy(s,
"signed-directory\n" "signed-directory\n"
"client-software x y z\n" /* XXX make this real */ "recommended-software 0.0.2pre4,0.0.2pre5,0.0.2pre6\n" /* XXX make this real */
"server-software a b c\n\n" /* XXX make this real */
, maxlen); , maxlen);
i = strlen(s); i = strlen(s);

View File

@ -330,6 +330,7 @@ typedef struct {
typedef struct { typedef struct {
routerinfo_t **routers; routerinfo_t **routers;
int n_routers; int n_routers;
char *software_versions;
} directory_t; } directory_t;
struct crypt_path_t { struct crypt_path_t {

View File

@ -44,20 +44,20 @@ int learn_my_address(struct sockaddr_in *me) {
/* obtain local host information */ /* obtain local host information */
if(gethostname(localhostname,512) < 0) { if(gethostname(localhostname,512) < 0) {
log(LOG_ERR,"Error obtaining local hostname."); log_fn(LOG_ERR,"Error obtaining local hostname.");
return -1; return -1;
} }
log(LOG_DEBUG,"learn_my_address(): localhostname is '%s'.",localhostname); log_fn(LOG_DEBUG,"localhostname is '%s'.",localhostname);
localhost = gethostbyname(localhostname); localhost = gethostbyname(localhostname);
if (!localhost) { if (!localhost) {
log(LOG_ERR,"Error obtaining local host info."); log_fn(LOG_ERR,"Error obtaining local host info.");
return -1; return -1;
} }
memset(me,0,sizeof(struct sockaddr_in)); memset(me,0,sizeof(struct sockaddr_in));
me->sin_family = AF_INET; me->sin_family = AF_INET;
memcpy((void *)&me->sin_addr,(void *)localhost->h_addr,sizeof(struct in_addr)); memcpy((void *)&me->sin_addr,(void *)localhost->h_addr,sizeof(struct in_addr));
me->sin_port = htons(options.ORPort); me->sin_port = htons(options.ORPort);
log(LOG_DEBUG,"learn_my_address(): chose address as '%s'.",inet_ntoa(me->sin_addr)); log_fn(LOG_DEBUG,"chose address as '%s'.",inet_ntoa(me->sin_addr));
return 0; return 0;
} }
@ -69,7 +69,7 @@ void router_retry_connections(void) {
for (i=0;i<directory->n_routers;i++) { for (i=0;i<directory->n_routers;i++) {
router = directory->routers[i]; router = directory->routers[i];
if(!connection_exact_get_by_addr_port(router->addr,router->or_port)) { /* not in the list */ if(!connection_exact_get_by_addr_port(router->addr,router->or_port)) { /* not in the list */
log(LOG_DEBUG,"retry_all_connections(): connecting to OR %s:%u.",router->address,router->or_port); log_fn(LOG_DEBUG,"connecting to OR %s:%u.",router->address,router->or_port);
connection_or_connect_as_or(router); connection_or_connect_as_or(router);
} }
} }
@ -199,19 +199,19 @@ int router_get_list_from_file(char *routerfile)
assert(routerfile); assert(routerfile);
if (strcspn(routerfile,CONFIG_LEGAL_FILENAME_CHARACTERS) != 0) { if (strcspn(routerfile,CONFIG_LEGAL_FILENAME_CHARACTERS) != 0) {
log(LOG_ERR,"router_get_list_from_file(): Filename %s contains illegal characters.",routerfile); log_fn(LOG_ERR,"Filename %s contains illegal characters.",routerfile);
return -1; return -1;
} }
if(stat(routerfile, &statbuf) < 0) { if(stat(routerfile, &statbuf) < 0) {
log(LOG_ERR,"router_get_list_from_file(): Could not stat %s.",routerfile); log_fn(LOG_ERR,"Could not stat %s.",routerfile);
return -1; return -1;
} }
/* open the router list */ /* open the router list */
fd = open(routerfile,O_RDONLY,0); fd = open(routerfile,O_RDONLY,0);
if (fd<0) { if (fd<0) {
log(LOG_ERR,"router_get_list_from_file(): Could not open %s.",routerfile); log_fn(LOG_ERR,"Could not open %s.",routerfile);
return -1; return -1;
} }
@ -244,11 +244,10 @@ int router_get_list_from_file(char *routerfile)
typedef enum { typedef enum {
K_ACCEPT, K_ACCEPT,
K_CLIENT_SOFTWARE,
K_DIRECTORY_SIGNATURE, K_DIRECTORY_SIGNATURE,
K_RECOMMENDED_SOFTWARE,
K_REJECT, K_REJECT,
K_ROUTER, K_ROUTER,
K_SERVER_SOFTWARE,
K_SIGNED_DIRECTORY, K_SIGNED_DIRECTORY,
K_SIGNING_KEY, K_SIGNING_KEY,
_SIGNATURE, _SIGNATURE,
@ -261,11 +260,10 @@ struct token_table_ent { char *t; int v; };
static struct token_table_ent token_table[] = { static struct token_table_ent token_table[] = {
{ "accept", K_ACCEPT }, { "accept", K_ACCEPT },
{ "client-software", K_CLIENT_SOFTWARE },
{ "directory-signature", K_DIRECTORY_SIGNATURE }, { "directory-signature", K_DIRECTORY_SIGNATURE },
{ "reject", K_REJECT }, { "reject", K_REJECT },
{ "router", K_ROUTER }, { "router", K_ROUTER },
{ "server-software", K_SERVER_SOFTWARE }, { "recommended-software", K_RECOMMENDED_SOFTWARE },
{ "signed-directory", K_SIGNED_DIRECTORY }, { "signed-directory", K_SIGNED_DIRECTORY },
{ "signing-key", K_SIGNING_KEY }, { "signing-key", K_SIGNING_KEY },
{ NULL, -1 } { NULL, -1 }
@ -395,11 +393,10 @@ router_dump_token(directory_token_t *tok) {
puts("EOF"); puts("EOF");
return; return;
case K_ACCEPT: printf("Accept"); break; case K_ACCEPT: printf("Accept"); break;
case K_CLIENT_SOFTWARE: printf("Client-Software"); break;
case K_DIRECTORY_SIGNATURE: printf("Directory-Signature"); break; case K_DIRECTORY_SIGNATURE: printf("Directory-Signature"); break;
case K_REJECT: printf("Reject"); break; case K_REJECT: printf("Reject"); break;
case K_RECOMMENDED_SOFTWARE: printf("Server-Software"); break;
case K_ROUTER: printf("Router"); break; case K_ROUTER: printf("Router"); break;
case K_SERVER_SOFTWARE: printf("Server-Software"); break;
case K_SIGNED_DIRECTORY: printf("Signed-Directory"); break; case K_SIGNED_DIRECTORY: printf("Signed-Directory"); break;
case K_SIGNING_KEY: printf("Signing-Key"); break; case K_SIGNING_KEY: printf("Signing-Key"); break;
default: default:
@ -518,6 +515,7 @@ int router_get_dir_from_string(char *s, crypto_pk_env_t *pkey)
log(LOG_ERR, "Error resolving directory"); log(LOG_ERR, "Error resolving directory");
return -1; return -1;
} }
/* XXXX Check version number */
return 0; return 0;
} }
@ -528,6 +526,7 @@ int router_get_dir_from_string_impl(char *s, directory_t **dest,
char digest[20]; char digest[20];
char signed_digest[128]; char signed_digest[128];
directory_t *new_dir = NULL; directory_t *new_dir = NULL;
char *versions;
#define NEXT_TOK() \ #define NEXT_TOK() \
do { \ do { \
@ -551,16 +550,19 @@ int router_get_dir_from_string_impl(char *s, directory_t **dest,
TOK_IS(K_SIGNED_DIRECTORY, "signed-directory"); TOK_IS(K_SIGNED_DIRECTORY, "signed-directory");
NEXT_TOK(); NEXT_TOK();
TOK_IS(K_CLIENT_SOFTWARE, "client-software"); TOK_IS(K_RECOMMENDED_SOFTWARE, "recommended-software");
if (tok.val.cmd.n_args != 1) {
NEXT_TOK(); log(LOG_ERR, "Invalid recommded-software line");
TOK_IS(K_SERVER_SOFTWARE, "server-software"); return -1;
}
versions = strdup(tok.val.cmd.args[0]);
NEXT_TOK(); NEXT_TOK();
if (router_get_list_from_string_tok(&s, &new_dir, &tok)) { if (router_get_list_from_string_tok(&s, &new_dir, &tok)) {
log(LOG_ERR, "Error reading routers from directory"); log(LOG_ERR, "Error reading routers from directory");
return -1; return -1;
} }
new_dir->software_versions = versions;
TOK_IS(K_DIRECTORY_SIGNATURE, "directory-signature"); TOK_IS(K_DIRECTORY_SIGNATURE, "directory-signature");
NEXT_TOK(); NEXT_TOK();