Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
David Goulet
Tor
Commits
1af630d3
Commit
1af630d3
authored
Dec 14, 2005
by
Nick Mathewson
🎨
Browse files
Bite the bullet and limit all our source lines to 80 characters, the way IBM intended.
svn:r5582
parent
7e632a75
Changes
45
Hide whitespace changes
Inline
Side-by-side
contrib/checkSpace.pl
View file @
1af630d3
...
...
@@ -37,7 +37,7 @@ for $fn (@ARGV) {
}
## Terminals are still 80 columns wide in my world. I refuse to
## accept double-line lines.
if
(
/^.{
15
0}/
)
{
if
(
/^.{
8
0}/
)
{
print
"
Wide:
$fn
:$.
\n
";
}
...
...
doc/TODO
View file @
1af630d3
...
...
@@ -193,7 +193,7 @@ N - Clients use Stable and Fast instead of uptime and bandwidth to
- Make authorities rate-limit logging their complaints about given
servers?
- Is this still necessary?
-
All versions of Tor should get cosmetic changes rate-limited.
o
All versions of Tor should get cosmetic changes rate-limited.
- Pick directories from networkstatus objects, not from routerlist.
- But! We can't do this easily, since we want to know about platform,
and networkstatus doesn't tell us Tor version. Can we solve this?
...
...
src/common/aes.c
View file @
1af630d3
...
...
@@ -51,11 +51,14 @@ typedef uint8_t u8;
#define MAXKB (256/8)
#define MAXNR 14
static
int
rijndaelKeySetupEnc
(
u32
rk
[
/*4*(Nr + 1)*/
],
const
u8
cipherKey
[],
int
keyBits
);
static
int
rijndaelKeySetupEnc
(
u32
rk
[
/*4*(Nr + 1)*/
],
const
u8
cipherKey
[],
int
keyBits
);
#ifdef USE_RIJNDAEL_COUNTER_OPTIMIZATION
static
void
rijndaelEncrypt
(
const
u32
rk
[
/*4*(Nr + 1)*/
],
int
Nr
,
u32
ctr1
,
u32
ctr0
,
u8
ct
[
16
]);
static
void
rijndaelEncrypt
(
const
u32
rk
[
/*4*(Nr + 1)*/
],
int
Nr
,
u32
ctr1
,
u32
ctr0
,
u8
ct
[
16
]);
#else
static
void
rijndaelEncrypt
(
const
u32
rk
[
/*4*(Nr + 1)*/
],
int
Nr
,
const
u8
pt
[
16
],
u8
ct
[
16
]);
static
void
rijndaelEncrypt
(
const
u32
rk
[
/*4*(Nr + 1)*/
],
int
Nr
,
const
u8
pt
[
16
],
u8
ct
[
16
]);
#endif
#endif
...
...
@@ -90,8 +93,10 @@ _aes_fill_buf(aes_cnt_cipher_t *cipher)
* 3) changing the counter position was not trivial, last time I looked.
* None of these issues are insurmountable in principle.
*/
#if !defined(USE_OPENSSL_EVP) && !defined(USE_OPENSSL_AES) && defined(USE_RIJNDAEL_COUNTER_OPTIMIZATION)
rijndaelEncrypt
(
cipher
->
rk
,
cipher
->
nr
,
cipher
->
counter1
,
cipher
->
counter0
,
cipher
->
buf
);
#if (!defined(USE_OPENSSL_EVP) && !defined(USE_OPENSSL_AES) && \
defined(USE_RIJNDAEL_COUNTER_OPTIMIZATION))
rijndaelEncrypt
(
cipher
->
rk
,
cipher
->
nr
,
cipher
->
counter1
,
cipher
->
counter0
,
cipher
->
buf
);
#else
u32
counter0
=
cipher
->
counter0
;
u32
counter1
=
cipher
->
counter1
;
...
...
@@ -176,7 +181,8 @@ aes_free_cipher(aes_cnt_cipher_t *cipher)
* by <b>len</b> bytes as it encrypts.
*/
void
aes_crypt
(
aes_cnt_cipher_t
*
cipher
,
const
char
*
input
,
size_t
len
,
char
*
output
)
aes_crypt
(
aes_cnt_cipher_t
*
cipher
,
const
char
*
input
,
size_t
len
,
char
*
output
)
{
int
c
=
cipher
->
pos
;
if
(
!
len
)
return
;
...
...
src/common/aes.h
View file @
1af630d3
...
...
@@ -22,7 +22,8 @@ typedef struct aes_cnt_cipher aes_cnt_cipher_t;
aes_cnt_cipher_t
*
aes_new_cipher
(
void
);
void
aes_free_cipher
(
aes_cnt_cipher_t
*
cipher
);
void
aes_set_key
(
aes_cnt_cipher_t
*
cipher
,
const
char
*
key
,
int
key_bits
);
void
aes_crypt
(
aes_cnt_cipher_t
*
cipher
,
const
char
*
input
,
size_t
len
,
char
*
output
);
void
aes_crypt
(
aes_cnt_cipher_t
*
cipher
,
const
char
*
input
,
size_t
len
,
char
*
output
);
uint64_t
aes_get_counter
(
aes_cnt_cipher_t
*
cipher
);
void
aes_set_counter
(
aes_cnt_cipher_t
*
cipher
,
uint64_t
counter
);
void
aes_adjust_counter
(
aes_cnt_cipher_t
*
cipher
,
long
delta
);
...
...
src/common/compat.c
View file @
1af630d3
...
...
@@ -2,7 +2,8 @@
* Copyright 2004-2005 Roger Dingledine, Nick Mathewson */
/* See LICENSE for licensing information */
/* $Id$ */
const
char
compat_c_id
[]
=
"$Id$"
;
const
char
compat_c_id
[]
=
"$Id$"
;
/**
* \file compat.c
...
...
@@ -150,13 +151,15 @@ tor_vsnprintf(char *str, size_t size, const char *format, va_list args)
* Requires that nlen be greater than zero.
*/
const
void
*
tor_memmem
(
const
void
*
_haystack
,
size_t
hlen
,
const
void
*
_needle
,
size_t
nlen
)
tor_memmem
(
const
void
*
_haystack
,
size_t
hlen
,
const
void
*
_needle
,
size_t
nlen
)
{
#if defined(HAVE_MEMMEM) && (!defined(__GNUC__) || __GNUC__ >= 2)
tor_assert
(
nlen
);
return
memmem
(
_haystack
,
hlen
,
_needle
,
nlen
);
#else
/* This isn't as fast as the GLIBC implementation, but it doesn't need to be. */
/* This isn't as fast as the GLIBC implementation, but it doesn't need to
* be. */
const
char
*
p
,
*
end
;
const
char
*
haystack
=
(
const
char
*
)
_haystack
;
const
char
*
needle
=
(
const
char
*
)
_needle
;
...
...
@@ -463,7 +466,8 @@ set_max_file_descriptors(unsigned long limit, unsigned long cap)
return
-
1
;
}
if
(
rlim
.
rlim_max
<
limit
)
{
warn
(
LD_CONFIG
,
"We need %lu file descriptors available, and we're limited to %lu. Please change your ulimit -n."
,
warn
(
LD_CONFIG
,
"We need %lu file descriptors available, and we're "
"limited to %lu. Please change your ulimit -n."
,
limit
,
(
unsigned
long
)
rlim
.
rlim_max
);
return
-
1
;
}
...
...
@@ -538,7 +542,8 @@ switch_id(char *user, char *group)
return
0
;
#endif
err
(
LD_CONFIG
,
"User or group specified, but switching users is not supported."
);
err
(
LD_CONFIG
,
"User or group specified, but switching users is not supported."
);
return
-
1
;
}
...
...
@@ -722,9 +727,11 @@ get_uname(void)
{
VER_SUITE_ENTERPRISE
,
" {enterprise}"
},
{
VER_SUITE_EMBEDDEDNT
,
" {embedded}"
},
{
VER_SUITE_PERSONAL
,
" {personal}"
},
{
VER_SUITE_SINGLEUSERTS
,
" {terminal services, single user}"
},
{
VER_SUITE_SINGLEUSERTS
,
" {terminal services, single user}"
},
{
VER_SUITE_SMALLBUSINESS
,
" {small business}"
},
{
VER_SUITE_SMALLBUSINESS_RESTRICTED
,
" {small business, restricted}"
},
{
VER_SUITE_SMALLBUSINESS_RESTRICTED
,
" {small business, restricted}"
},
{
VER_SUITE_TERMINAL
,
" {terminal services}"
},
{
0
,
NULL
},
};
...
...
@@ -751,14 +758,14 @@ get_uname(void)
if
(
info
.
dwMajorVersion
>
6
||
(
info
.
dwMajorVersion
==
6
&&
info
.
dwMinorVersion
>
0
))
tor_snprintf
(
uname_result
,
sizeof
(
uname_result
),
"Very recent version of Windows [major=%d,minor=%d] %s"
,
(
int
)
info
.
dwMajorVersion
,(
int
)
info
.
dwMinorVersion
,
info
.
szCSDVersion
);
"Very recent version of Windows [major=%d,minor=%d] %s"
,
(
int
)
info
.
dwMajorVersion
,(
int
)
info
.
dwMinorVersion
,
info
.
szCSDVersion
);
else
tor_snprintf
(
uname_result
,
sizeof
(
uname_result
),
"Unrecognized version of Windows [major=%d,minor=%d] %s"
,
(
int
)
info
.
dwMajorVersion
,(
int
)
info
.
dwMinorVersion
,
info
.
szCSDVersion
);
"Unrecognized version of Windows [major=%d,minor=%d] %s"
,
(
int
)
info
.
dwMajorVersion
,(
int
)
info
.
dwMinorVersion
,
info
.
szCSDVersion
);
}
if
(
info
.
wProductType
==
VER_NT_DOMAIN_CONTROLLER
)
{
strlcat
(
uname_result
,
" [domain controller]"
,
sizeof
(
uname_result
));
...
...
src/common/compat.h
View file @
1af630d3
...
...
@@ -180,7 +180,8 @@ int network_init(void);
#define ERRNO_IS_EINPROGRESS(e) ((e) == WSAEINPROGRESS)
/** Return true if e is EINPROGRESS or the local equivalent as returned by
* a call to connect(). */
#define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == WSAEINPROGRESS || (e)== WSAEINVAL || (e) == WSAEWOULDBLOCK)
#define ERRNO_IS_CONN_EINPROGRESS(e) \
((e) == WSAEINPROGRESS || (e)== WSAEINVAL || (e) == WSAEWOULDBLOCK)
/** Return true if e is EAGAIN or another error indicating that a call to
* accept() has no pending connections to return. */
#define ERRNO_IS_ACCEPT_EAGAIN(e) ERRNO_IS_EAGAIN(e)
...
...
@@ -232,7 +233,8 @@ void spawn_exit(void);
#if defined(ENABLE_THREADS) && defined(MS_WINDOWS)
#define USE_WIN32_THREADS
#define TOR_IS_MULTITHREADED 1
#elif defined(ENABLE_THREADS) && defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_CREATE)
#elif (defined(ENABLE_THREADS) && defined(HAVE_PTHREAD_H) && \
defined(HAVE_PTHREAD_CREATE))
#define USE_PTHREADS
#define TOR_IS_MULTITHREADED 1
#else
...
...
src/common/container.c
View file @
1af630d3
...
...
@@ -2,7 +2,8 @@
Copyright 2004-2005 Roger Dingledine, Nick Mathewson */
/* See LICENSE for licensing information */
/* $Id$ */
const
char
container_c_id
[]
=
"$Id$"
;
const
char
container_c_id
[]
=
"$Id$"
;
/**
* \file container.c
...
...
@@ -807,8 +808,9 @@ digestmap_iter_done(digestmap_iter_t *iter)
return
iter
==
NULL
;
}
/** Remove all entries from <b>map</b>, and deallocate storage for those entries.
* If free_val is provided, it is invoked on every value in <b>map</b>.
/** Remove all entries from <b>map</b>, and deallocate storage for those
* entries. If free_val is provided, it is invoked on every value in
* <b>map</b>.
*/
void
strmap_free
(
strmap_t
*
map
,
void
(
*
free_val
)(
void
*
))
...
...
src/common/container.h
View file @
1af630d3
...
...
@@ -5,7 +5,8 @@
#ifndef __CONTAINER_H
#define __CONTAINER_H
#define CONTAINER_H_ID "$Id$"
#define CONTAINER_H_ID \
"$Id$"
#include
"compat.h"
#include
"util.h"
...
...
src/common/crypto.c
View file @
1af630d3
...
...
@@ -2,7 +2,8 @@
* Copyright 2004-2005 Roger Dingledine, Nick Mathewson */
/* See LICENSE for licensing information */
/* $Id$ */
const
char
crypto_c_id
[]
=
"$Id$"
;
const
char
crypto_c_id
[]
=
"$Id$"
;
/**
* \file crypto.c
...
...
@@ -167,7 +168,8 @@ crypto_log_errors(int severity, const char *doing)
func
=
(
const
char
*
)
ERR_func_error_string
(
err
);
if
(
!
msg
)
msg
=
"(null)"
;
if
(
doing
)
{
log
(
severity
,
LD_CRYPTO
,
"crypto error while %s: %s (in %s:%s)"
,
doing
,
msg
,
lib
,
func
);
log
(
severity
,
LD_CRYPTO
,
"crypto error while %s: %s (in %s:%s)"
,
doing
,
msg
,
lib
,
func
);
}
else
{
log
(
severity
,
LD_CRYPTO
,
"crypto error: %s (in %s:%s)"
,
msg
,
lib
,
func
);
}
...
...
@@ -456,7 +458,8 @@ crypto_pk_read_private_key_from_string(crypto_pk_env_t *env,
* <b>keyfile</b> into <b>env</b>. Return 0 on success, -1 on failure.
*/
int
crypto_pk_read_private_key_from_filename
(
crypto_pk_env_t
*
env
,
const
char
*
keyfile
)
crypto_pk_read_private_key_from_filename
(
crypto_pk_env_t
*
env
,
const
char
*
keyfile
)
{
char
*
contents
;
int
r
;
...
...
@@ -487,7 +490,8 @@ crypto_pk_read_private_key_from_filename(crypto_pk_env_t *env, const char *keyfi
* failure, return -1.
*/
int
crypto_pk_write_public_key_to_string
(
crypto_pk_env_t
*
env
,
char
**
dest
,
size_t
*
len
)
crypto_pk_write_public_key_to_string
(
crypto_pk_env_t
*
env
,
char
**
dest
,
size_t
*
len
)
{
BUF_MEM
*
buf
;
BIO
*
b
;
...
...
@@ -525,7 +529,8 @@ crypto_pk_write_public_key_to_string(crypto_pk_env_t *env, char **dest, size_t *
* failure.
*/
int
crypto_pk_read_public_key_from_string
(
crypto_pk_env_t
*
env
,
const
char
*
src
,
size_t
len
)
crypto_pk_read_public_key_from_string
(
crypto_pk_env_t
*
env
,
const
char
*
src
,
size_t
len
)
{
BIO
*
b
;
...
...
@@ -770,7 +775,8 @@ crypto_pk_public_checksig(crypto_pk_env_t *env, char *to,
tor_assert
(
env
);
tor_assert
(
from
);
tor_assert
(
to
);
r
=
RSA_public_decrypt
(
fromlen
,
(
unsigned
char
*
)
from
,
(
unsigned
char
*
)
to
,
env
->
key
,
RSA_PKCS1_PADDING
);
r
=
RSA_public_decrypt
(
fromlen
,
(
unsigned
char
*
)
from
,
(
unsigned
char
*
)
to
,
env
->
key
,
RSA_PKCS1_PADDING
);
if
(
r
<
0
)
{
crypto_log_errors
(
LOG_WARN
,
"checking RSA signature"
);
...
...
@@ -830,7 +836,8 @@ crypto_pk_private_sign(crypto_pk_env_t *env, char *to,
/* Not a private key */
return
-
1
;
r
=
RSA_private_encrypt
(
fromlen
,
(
unsigned
char
*
)
from
,
(
unsigned
char
*
)
to
,
env
->
key
,
RSA_PKCS1_PADDING
);
r
=
RSA_private_encrypt
(
fromlen
,
(
unsigned
char
*
)
from
,
(
unsigned
char
*
)
to
,
env
->
key
,
RSA_PKCS1_PADDING
);
if
(
r
<
0
)
{
crypto_log_errors
(
LOG_WARN
,
"generating RSA signature"
);
return
-
1
;
...
...
@@ -950,9 +957,11 @@ crypto_pk_private_hybrid_decrypt(crypto_pk_env_t *env,
pkeylen
=
crypto_pk_keysize
(
env
);
if
(
fromlen
<=
pkeylen
)
{
return
crypto_pk_private_decrypt
(
env
,
to
,
from
,
fromlen
,
padding
,
warnOnFailure
);
return
crypto_pk_private_decrypt
(
env
,
to
,
from
,
fromlen
,
padding
,
warnOnFailure
);
}
outlen
=
crypto_pk_private_decrypt
(
env
,
buf
,
from
,
pkeylen
,
padding
,
warnOnFailure
);
outlen
=
crypto_pk_private_decrypt
(
env
,
buf
,
from
,
pkeylen
,
padding
,
warnOnFailure
);
if
(
outlen
<
0
)
{
log_fn
(
warnOnFailure
?
LOG_WARN
:
LOG_DEBUG
,
LD_CRYPTO
,
"Error decrypting public-key data"
);
...
...
@@ -1397,7 +1406,8 @@ crypto_dh_generate_public(crypto_dh_env_t *dh)
return
-
1
;
}
if
(
tor_check_dh_key
(
dh
->
dh
->
pub_key
)
<
0
)
{
warn
(
LD_CRYPTO
,
"Weird! Our own DH key was invalid. I guess once-in-the-universe chances really do happen. Trying again."
);
warn
(
LD_CRYPTO
,
"Weird! Our own DH key was invalid. I guess once-in-"
"the-universe chances really do happen. Trying again."
);
/* Free and clear the keys, so openssl will actually try again. */
BN_free
(
dh
->
dh
->
pub_key
);
BN_free
(
dh
->
dh
->
priv_key
);
...
...
@@ -1425,7 +1435,8 @@ crypto_dh_get_public(crypto_dh_env_t *dh, char *pubkey, size_t pubkey_len)
bytes
=
BN_num_bytes
(
dh
->
dh
->
pub_key
);
tor_assert
(
bytes
>=
0
);
if
(
pubkey_len
<
(
size_t
)
bytes
)
{
warn
(
LD_CRYPTO
,
"Weird! pubkey_len (%d) was smaller than DH_BYTES (%d)"
,
(
int
)
pubkey_len
,
bytes
);
warn
(
LD_CRYPTO
,
"Weird! pubkey_len (%d) was smaller than DH_BYTES (%d)"
,
(
int
)
pubkey_len
,
bytes
);
return
-
1
;
}
...
...
@@ -1627,7 +1638,8 @@ crypto_seed_rng(void)
#ifdef MS_WINDOWS
if
(
!
provider_set
)
{
if
(
!
CryptAcquireContext
(
&
provider
,
NULL
,
NULL
,
PROV_RSA_FULL
,
CRYPT_VERIFYCONTEXT
))
{
if
(
!
CryptAcquireContext
(
&
provider
,
NULL
,
NULL
,
PROV_RSA_FULL
,
CRYPT_VERIFYCONTEXT
))
{
if
(
GetLastError
()
!=
NTE_BAD_KEYSET
)
{
warn
(
LD_CRYPTO
,
"Can't get CryptoAPI provider [1]"
);
return
rand_poll_status
?
0
:
-
1
;
...
...
@@ -1649,7 +1661,8 @@ crypto_seed_rng(void)
n
=
read_all
(
fd
,
buf
,
sizeof
(
buf
),
0
);
close
(
fd
);
if
(
n
!=
sizeof
(
buf
))
{
warn
(
LD_CRYPTO
,
"Error reading from entropy source (read only %d bytes)."
,
n
);
warn
(
LD_CRYPTO
,
"Error reading from entropy source (read only %d bytes)."
,
n
);
return
-
1
;
}
RAND_seed
(
buf
,
sizeof
(
buf
));
...
...
@@ -1729,7 +1742,8 @@ base64_encode(char *dest, size_t destlen, const char *src, size_t srclen)
return
-
1
;
EVP_EncodeInit
(
&
ctx
);
EVP_EncodeUpdate
(
&
ctx
,
(
unsigned
char
*
)
dest
,
&
len
,
(
unsigned
char
*
)
src
,
srclen
);
EVP_EncodeUpdate
(
&
ctx
,
(
unsigned
char
*
)
dest
,
&
len
,
(
unsigned
char
*
)
src
,
srclen
);
EVP_EncodeFinal
(
&
ctx
,
(
unsigned
char
*
)(
dest
+
len
),
&
ret
);
ret
+=
len
;
return
ret
;
...
...
@@ -1758,7 +1772,8 @@ base64_decode(char *dest, size_t destlen, const char *src, size_t srclen)
return
-
1
;
EVP_DecodeInit
(
&
ctx
);
EVP_DecodeUpdate
(
&
ctx
,
(
unsigned
char
*
)
dest
,
&
len
,
(
unsigned
char
*
)
src
,
srclen
);
EVP_DecodeUpdate
(
&
ctx
,
(
unsigned
char
*
)
dest
,
&
len
,
(
unsigned
char
*
)
src
,
srclen
);
EVP_DecodeFinal
(
&
ctx
,
(
unsigned
char
*
)
dest
,
&
ret
);
ret
+=
len
;
return
ret
;
...
...
src/common/crypto.h
View file @
1af630d3
...
...
@@ -61,7 +61,8 @@ crypto_pk_env_t *crypto_new_pk_env(void);
void
crypto_free_pk_env
(
crypto_pk_env_t
*
env
);
/* convenience function: wraps crypto_create_crypto_env, set_key, and init. */
crypto_cipher_env_t
*
crypto_create_init_cipher
(
const
char
*
key
,
int
encrypt_mode
);
crypto_cipher_env_t
*
crypto_create_init_cipher
(
const
char
*
key
,
int
encrypt_mode
);
crypto_cipher_env_t
*
crypto_new_cipher_env
(
void
);
void
crypto_free_cipher_env
(
crypto_cipher_env_t
*
env
);
...
...
@@ -69,10 +70,14 @@ void crypto_free_cipher_env(crypto_cipher_env_t *env);
/* public key crypto */
int
crypto_pk_generate_key
(
crypto_pk_env_t
*
env
);
int
crypto_pk_read_private_key_from_filename
(
crypto_pk_env_t
*
env
,
const
char
*
keyfile
);
int
crypto_pk_write_public_key_to_string
(
crypto_pk_env_t
*
env
,
char
**
dest
,
size_t
*
len
);
int
crypto_pk_read_public_key_from_string
(
crypto_pk_env_t
*
env
,
const
char
*
src
,
size_t
len
);
int
crypto_pk_write_private_key_to_filename
(
crypto_pk_env_t
*
env
,
const
char
*
fname
);
int
crypto_pk_read_private_key_from_filename
(
crypto_pk_env_t
*
env
,
const
char
*
keyfile
);
int
crypto_pk_write_public_key_to_string
(
crypto_pk_env_t
*
env
,
char
**
dest
,
size_t
*
len
);
int
crypto_pk_read_public_key_from_string
(
crypto_pk_env_t
*
env
,
const
char
*
src
,
size_t
len
);
int
crypto_pk_write_private_key_to_filename
(
crypto_pk_env_t
*
env
,
const
char
*
fname
);
int
crypto_pk_DER64_encode_public_key
(
crypto_pk_env_t
*
env
,
char
**
dest
);
crypto_pk_env_t
*
crypto_pk_DER64_decode_public_key
(
const
char
*
in
);
...
...
src/common/ht.h
View file @
1af630d3
...
...
@@ -333,7 +333,8 @@ ht_string_hash(const char *s)
}
#endif
#define HT_GENERATE(name, type, field, hashfn, eqfn, load, mallocfn, reallocfn, freefn) \
#define HT_GENERATE(name, type, field, hashfn, eqfn, load, mallocfn, \
reallocfn, freefn) \
static unsigned name##_PRIMES[] = { \
53, 97, 193, 389, \
769, 1543, 3079, 6151, \
...
...
src/common/log.c
View file @
1af630d3
...
...
@@ -364,7 +364,8 @@ close_log(logfile_t *victim)
/** Add a log handler to send all messages of severity <b>loglevel</b>
* or higher to <b>stream</b>. */
void
add_stream_log
(
int
loglevelMin
,
int
loglevelMax
,
const
char
*
name
,
FILE
*
stream
)
add_stream_log
(
int
loglevelMin
,
int
loglevelMax
,
const
char
*
name
,
FILE
*
stream
)
{
logfile_t
*
lf
;
lf
=
tor_malloc_zero
(
sizeof
(
logfile_t
));
...
...
src/common/log.h
View file @
1af630d3
...
...
@@ -18,7 +18,8 @@
#include
<syslog.h>
#define LOG_WARN LOG_WARNING
#if LOG_DEBUG < LOG_ERR
#error "Your syslog.h thinks high numbers are more important. We aren't prepared to deal with that."
#error "Your syslog.h thinks high numbers are more important. " \
"We aren't prepared to deal with that."
#endif
#else
/* XXXX Note: The code was originally written to refer to severities,
...
...
@@ -94,7 +95,8 @@ typedef void (*log_callback)(int severity, uint32_t domain, const char *msg);
int
parse_log_level
(
const
char
*
level
);
const
char
*
log_level_to_string
(
int
level
);
void
add_stream_log
(
int
severityMin
,
int
severityMax
,
const
char
*
name
,
FILE
*
stream
);
void
add_stream_log
(
int
severityMin
,
int
severityMax
,
const
char
*
name
,
FILE
*
stream
);
int
add_file_log
(
int
severityMin
,
int
severityMax
,
const
char
*
filename
);
#ifdef HAVE_SYSLOG_H
int
add_syslog_log
(
int
loglevelMin
,
int
loglevelMax
);
...
...
@@ -112,7 +114,8 @@ void change_callback_log_severity(int loglevelMin, int loglevelMax,
log_callback
cb
);
/* Outputs a message to stdout */
void
_log
(
int
severity
,
uint32_t
domain
,
const
char
*
format
,
...)
CHECK_PRINTF
(
3
,
4
);
void
_log
(
int
severity
,
uint32_t
domain
,
const
char
*
format
,
...)
CHECK_PRINTF
(
3
,
4
);
#define log _log
/* hack it so we don't conflict with log() as much */
#ifdef __GNUC__
...
...
src/common/torgzip.c
View file @
1af630d3
...
...
@@ -2,7 +2,8 @@
/* Copyright 2004-2005 Roger Dingledine, Nick Mathewson */
/* See LICENSE for licensing information */
/* $Id$ */
const
char
torgzip_c_id
[]
=
"$Id$"
;
const
char
torgzip_c_id
[]
=
"$Id$"
;
/**
* \file torgzip.c
...
...
src/common/tortls.c
View file @
1af630d3
...
...
@@ -2,7 +2,8 @@
* Copyright 2004-2005 Roger Dingledine, Nick Mathewson */
/* See LICENSE for licensing information */
/* $Id$ */
const
char
tortls_c_id
[]
=
"$Id$"
;
const
char
tortls_c_id
[]
=
"$Id$"
;
/**
* \file tortls.c
...
...
@@ -23,7 +24,8 @@ const char tortls_c_id[] = "$Id$";
#include
<string.h>
/* Copied from or.h */
#define LEGAL_NICKNAME_CHARACTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
#define LEGAL_NICKNAME_CHARACTERS \
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
#include
<assert.h>
#include
<openssl/ssl.h>
...
...
@@ -53,7 +55,8 @@ struct tor_tls_t {
}
state
;
/**< The current SSL state, depending on which operations have
* completed successfully. */
int
isServer
;
size_t
wantwrite_n
;
/**< 0 normally, >0 if we returned wantwrite last time. */
size_t
wantwrite_n
;
/**< 0 normally, >0 if we returned wantwrite last
* time. */
};
static
X509
*
tor_tls_create_certificate
(
crypto_pk_env_t
*
rsa
,
...
...
@@ -91,7 +94,8 @@ tls_log_errors(int severity, const char *doing)
func
=
(
const
char
*
)
ERR_func_error_string
(
err
);
if
(
!
msg
)
msg
=
"(null)"
;
if
(
doing
)
{
log
(
severity
,
LD_NET
,
"TLS error while %s: %s (in %s:%s)"
,
doing
,
msg
,
lib
,
func
);
log
(
severity
,
LD_NET
,
"TLS error while %s: %s (in %s:%s)"
,
doing
,
msg
,
lib
,
func
);
}
else
{
log
(
severity
,
LD_NET
,
"TLS error: %s (in %s:%s)"
,
msg
,
lib
,
func
);
}
...
...
@@ -130,7 +134,8 @@ tor_tls_get_error(tor_tls_t *tls, int r, int extra,
log
(
severity
,
LD_NET
,
"TLS error: unexpected close while %s"
,
doing
);
else
{
int
e
=
tor_socket_errno
(
tls
->
socket
);
log
(
severity
,
LD_NET
,
"TLS error: <syscall error while %s> (errno=%d: %s)"
,
log
(
severity
,
LD_NET
,
"TLS error: <syscall error while %s> (errno=%d: %s)"
,
doing
,
e
,
tor_socket_strerror
(
e
));
}
tls_log_errors
(
severity
,
doing
);
...
...
@@ -226,23 +231,29 @@ tor_tls_create_certificate(crypto_pk_env_t *rsa,
if
(
!
(
name
=
X509_NAME_new
()))
goto
error
;
if
((
nid
=
OBJ_txt2nid
(
"organizationName"
))
==
NID_undef
)
goto
error
;
if
((
nid
=
OBJ_txt2nid
(
"organizationName"
))
==
NID_undef
)
goto
error
;
if
(
!
(
X509_NAME_add_entry_by_NID
(
name
,
nid
,
MBSTRING_ASC
,
(
unsigned
char
*
)
"TOR"
,
-
1
,
-
1
,
0
)))
goto
error
;
(
unsigned
char
*
)
"TOR"
,
-
1
,
-
1
,
0
)))
goto
error
;
if
((
nid
=
OBJ_txt2nid
(
"commonName"
))
==
NID_undef
)
goto
error
;
if
(
!
(
X509_NAME_add_entry_by_NID
(
name
,
nid
,
MBSTRING_ASC
,
(
unsigned
char
*
)
cname
,
-
1
,
-
1
,
0
)))
goto
error
;
(
unsigned
char
*
)
cname
,
-
1
,
-
1
,
0
)))
goto
error
;
if
(
!
(
X509_set_subject_name
(
x509
,
name
)))
goto
error
;
if
(
!
(
name_issuer
=
X509_NAME_new
()))
goto
error
;
if
((
nid
=
OBJ_txt2nid
(
"organizationName"
))
==
NID_undef
)
goto
error
;
if
((
nid
=
OBJ_txt2nid
(
"organizationName"
))
==
NID_undef
)
goto
error
;
if
(
!
(
X509_NAME_add_entry_by_NID
(
name_issuer
,
nid
,
MBSTRING_ASC
,
(
unsigned
char
*
)
"TOR"
,
-
1
,
-
1
,
0
)))
goto
error
;
(
unsigned
char
*
)
"TOR"
,
-
1
,
-
1
,
0
)))
goto
error
;
if
((
nid
=
OBJ_txt2nid
(
"commonName"
))
==
NID_undef
)
goto
error
;
if
(
!
(
X509_NAME_add_entry_by_NID
(
name_issuer
,
nid
,
MBSTRING_ASC
,
(
unsigned
char
*
)
cname_sign
,
-
1
,
-
1
,
0
)))
goto
error
;
(
unsigned
char
*
)
cname_sign
,
-
1
,
-
1
,
0
)))
goto
error
;
if
(
!
(
X509_set_issuer_name
(
x509
,
name_issuer
)))
goto
error
;
...
...
@@ -658,10 +669,11 @@ tor_tls_get_peer_cert_nickname(tor_tls_t *tls, char *buf, size_t buflen)
if
(
lenout
==
-
1
)
goto
error
;
if
(((
int
)
strspn
(
buf
,
LEGAL_NICKNAME_CHARACTERS
))
<
lenout
)
{
warn
(
LD_PROTOCOL
,
"Peer certificate nickname
\"
%s
\"
has illegal characters."
,
buf
);
warn
(
LD_PROTOCOL
,
"Peer certificate nickname
\"
%s
\"
has illegal characters."
,
buf
);
if
(
strchr
(
buf
,
'.'
))
warn
(
LD_PROTOCOL
,
" (Maybe it is not really running Tor at its advertised OR port.)"
);
warn
(
LD_PROTOCOL
,
" (Maybe it is not really running Tor at its "
"advertised OR port.)"
);
goto
error
;
}
...
...
@@ -709,7 +721,9 @@ log_cert_lifetime(X509 *cert, const char *problem)
strftime
(
mytime
,
32
,
"%b %d %H:%M:%S %Y GMT"
,
tor_gmtime_r
(
&
now
,
&
tm
));
warn
(
LD_GENERAL
,
"(certificate lifetime runs from %s through %s. Your time is %s.)"
,
s1
,
s2
,
mytime
);
warn
(
LD_GENERAL
,
"(certificate lifetime runs from %s through %s. Your time is %s.)"
,
s1
,
s2
,
mytime
);
end:
/* Not expected to get invoked */
...
...
@@ -749,7 +763,8 @@ tor_tls_verify(int severity, tor_tls_t *tls, crypto_pk_env_t **identity_key)
* cert and the id_cert.
*/
if
(
num_in_chain
<
1
)
{
log_fn
(
severity
,
LD_PROTOCOL
,
"Unexpected number of certificates in chain (%d)"
,
log_fn
(
severity
,
LD_PROTOCOL
,
"Unexpected number of certificates in chain (%d)"
,
num_in_chain
);
goto
done
;
}
...
...
src/common/util.c
View file @
1af630d3
...
...
@@ -101,10 +101,12 @@ const char util_c_id[] = "$Id$";
#else
#define dmalloc_strdup(file, line, string, xalloc_b) strdup(string)
#define dmalloc_malloc(file, line, size, func_id, alignment, xalloc_b) malloc(size)
#define dmalloc_malloc(file, line, size, func_id, alignment, xalloc_b) \
malloc(size)
#define DMALLOC_FUNC_MALLOC 0
#define dmalloc_realloc(file, line, old_pnt, new_size, func_id, xalloc_b) realloc((old_pnt), (new_size))
#define dmalloc_realloc(file, line, old_pnt, new_size, func_id, xalloc_b) \
realloc((old_pnt), (new_size))
#define DMALLOC_FUNC_REALLOC 0
#define DMALLOC_FN_ARGS
#endif
...
...
@@ -921,7 +923,8 @@ check_private_dir(const char *dirname, cpd_check_t check)
pw
=
getpwuid
(
st
.
st_uid
);
log
(
LOG_WARN
,
LD_FS
,
"%s is not owned by this user (%s, %d) but by %s (%d). Perhaps you are running Tor as the wrong user?"
,
log
(
LOG_WARN
,
LD_FS
,
"%s is not owned by this user (%s, %d) but by "
"%s (%d). Perhaps you are running Tor as the wrong user?"
,
dirname
,
process_ownername
,
(
int
)
getuid
(),
pw
?
pw
->
pw_name
:
"<unknown>"
,
(
int
)
st
.
st_uid
);
...
...
@@ -942,8 +945,8 @@ check_private_dir(const char *dirname, cpd_check_t check)
return
0
;
}
/** Create a file named <b>fname</b> with the contents <b>str</b>. Overwrite
the
* previous <b>fname</b> if possible. Return 0 on success, -1 on failure.
/** Create a file named <b>fname</b> with the contents <b>str</b>. Overwrite
*
the
previous <b>fname</b> if possible. Return 0 on success, -1 on failure.
*
* This function replaces the old file atomically, if possible.
*/
...
...
@@ -989,18 +992,21 @@ write_chunks_to_file_impl(const char *fname, const smartlist_t *chunks,
{
result
=
write_all
(
fd
,
chunk
->
bytes
,
chunk
->
len
,
0
);
if
(
result
<
0
||
(
size_t
)
result
!=
chunk
->
len
)
{
log
(
LOG_WARN
,
LD_FS
,
"Error writing to
\"
%s
\"
: %s"
,
tempname
,
strerror
(
errno
));
log
(
LOG_WARN
,
LD_FS
,
"Error writing to
\"
%s
\"
: %s"
,
tempname
,
strerror
(
errno
));
close
(
fd
);
goto
err
;
}
});
if
(
close
(
fd
))
{
log
(
LOG_WARN
,
LD_FS
,
"Error flushing to
\"
%s
\"
: %s"
,
tempname
,
strerror
(
errno
));
log
(
LOG_WARN
,
LD_FS
,
"Error flushing to
\"
%s
\"
: %s"
,
tempname
,
strerror
(
errno
));
goto
err
;
}
if
(
!
(
open_flags
&
O_APPEND
))
{
if
(
replace_file
(
tempname
,
fname
))
{
log
(
LOG_WARN
,
LD_FS
,
"Error replacing
\"
%s
\"
: %s"
,
fname
,
strerror
(
errno
));
log
(
LOG_WARN
,
LD_FS
,
"Error replacing
\"
%s
\"
: %s"
,
fname
,
strerror
(
errno
));
goto
err
;
}
}
...
...
@@ -1108,8 +1114,9 @@ read_file_to_str(const char *filename, int bin)
}
#ifdef MS_WINDOWS
if
(
!
bin
&&
strchr
(
string
,
'\r'
))
{
debug
(
LD_FS
,
"We didn't convert CRLF to LF as well as we hoped when reading %s. Coping."
,
filename
);
debug
(
LD_FS
,
"We didn't convert CRLF to LF as well as we hoped "
"when reading %s. Coping."
,
filename
);