X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fnetwork%2Facl.c;h=62fcee2ca9c0194405480ecd0779e709fcbc2a85;hb=d601e4ed290edf58e9ace5c28f06c77ebf072004;hp=06eba088b48d7c369b6732c6c9689fbae07936f9;hpb=cc3bd152f5d2166087b9e19b962e3ace06bd12ea;p=vlc diff --git a/src/network/acl.c b/src/network/acl.c index 06eba088b4..62fcee2ca9 100644 --- a/src/network/acl.c +++ b/src/network/acl.c @@ -24,15 +24,17 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include #include #include -#include - #include -#include +#include /* FIXME: rwlock on acl, but libvlc doesn't implement rwlock */ typedef struct vlc_acl_entry_t @@ -40,7 +42,7 @@ typedef struct vlc_acl_entry_t uint8_t host[17]; uint8_t i_bytes_match; uint8_t i_bits_mask; - vlc_bool_t b_allow; + bool b_allow; } vlc_acl_entry_t; struct vlc_acl_t @@ -48,7 +50,7 @@ struct vlc_acl_t vlc_object_t *p_owner; unsigned i_size; vlc_acl_entry_t *p_entries; - vlc_bool_t b_allow_default; + bool b_allow_default; }; static int ACL_Resolve( vlc_object_t *p_this, uint8_t *p_bytes, @@ -150,7 +152,7 @@ int ACL_Check( vlc_acl_t *p_acl, const char *psz_ip ) * Items are always matched in the same order as they are added. */ int ACL_AddNet( vlc_acl_t *p_acl, const char *psz_ip, int i_len, - vlc_bool_t b_allow ) + bool b_allow ) { vlc_acl_entry_t *p_ent; unsigned i_size; @@ -185,9 +187,6 @@ int ACL_AddNet( vlc_acl_t *p_acl, const char *psz_ip, int i_len, if( i_len > 128 ) i_len = 128; - else - if( i_len < 0 ) - i_len = 0; } else i_len = 128; /* ACL_AddHost */ @@ -200,16 +199,16 @@ int ACL_AddNet( vlc_acl_t *p_acl, const char *psz_ip, int i_len, return 0; } - +#undef ACL_Create /** * Creates an empty ACL. * - * @param b_allow whether to grant (VLC_TRUE) or deny (VLC_FALSE) access + * @param b_allow whether to grant (true) or deny (false) access * by default (ie if none of the ACL entries matched). * * @return an ACL object. NULL in case of error. */ -vlc_acl_t *__ACL_Create( vlc_object_t *p_this, vlc_bool_t b_allow ) +vlc_acl_t *ACL_Create( vlc_object_t *p_this, bool b_allow ) { vlc_acl_t *p_acl; @@ -217,7 +216,7 @@ vlc_acl_t *__ACL_Create( vlc_object_t *p_this, vlc_bool_t b_allow ) if( p_acl == NULL ) return NULL; - vlc_object_yield( p_this ); + vlc_object_hold( p_this ); p_acl->p_owner = p_this; p_acl->i_size = 0; p_acl->p_entries = NULL; @@ -226,7 +225,7 @@ vlc_acl_t *__ACL_Create( vlc_object_t *p_this, vlc_bool_t b_allow ) return p_acl; } - +#undef ACL_Duplicate /** * Perform a deep copy of an existing ACL. * @@ -235,7 +234,7 @@ vlc_acl_t *__ACL_Create( vlc_object_t *p_this, vlc_bool_t b_allow ) * * @return a new ACL object, or NULL on error. */ -vlc_acl_t *__ACL_Duplicate( vlc_object_t *p_this, const vlc_acl_t *p_acl ) +vlc_acl_t *ACL_Duplicate( vlc_object_t *p_this, const vlc_acl_t *p_acl ) { vlc_acl_t *p_dupacl; @@ -263,7 +262,7 @@ vlc_acl_t *__ACL_Duplicate( vlc_object_t *p_this, const vlc_acl_t *p_acl ) else p_dupacl->p_entries = NULL; - vlc_object_yield( p_this ); + vlc_object_hold( p_this ); p_dupacl->p_owner = p_this; p_dupacl->i_size = p_acl->i_size; p_dupacl->b_allow_default = p_acl->b_allow_default; @@ -279,9 +278,7 @@ void ACL_Destroy( vlc_acl_t *p_acl ) { if( p_acl != NULL ) { - if( p_acl->p_entries != NULL ) - free( p_acl->p_entries ); - + free( p_acl->p_entries ); vlc_object_release( p_acl->p_owner ); free( p_acl ); } @@ -317,8 +314,7 @@ int ACL_LoadFile( vlc_acl_t *p_acl, const char *psz_path ) { if( ferror( file ) ) { - msg_Err( p_acl->p_owner, "error reading %s : %s\n", psz_path, - strerror( errno ) ); + msg_Err( p_acl->p_owner, "error reading %s : %m", psz_path ); goto error; } continue; @@ -335,9 +331,9 @@ int ACL_LoadFile( vlc_acl_t *p_acl, const char *psz_path ) continue; ptr = strchr( psz_ip, '\n' ); - if( ptr == NULL ) + if( ptr == NULL && !feof(file) ) { - msg_Warn( p_acl->p_owner, "skipping overly long line in %s\n", + msg_Warn( p_acl->p_owner, "skipping overly long line in %s", psz_path); do { @@ -345,8 +341,8 @@ int ACL_LoadFile( vlc_acl_t *p_acl, const char *psz_path ) { if( ferror( file ) ) { - msg_Err( p_acl->p_owner, "error reading %s : %s\n", - psz_path, strerror( errno ) ); + msg_Err( p_acl->p_owner, "error reading %s : %m", + psz_path ); } goto error; } @@ -356,16 +352,15 @@ int ACL_LoadFile( vlc_acl_t *p_acl, const char *psz_path ) continue; /* skip unusable line */ } - /* skips comment-only line */ - if( *psz_ip == '#' ) - continue; - - /* looks for first space, CR, LF, etc. or end-of-line comment */ - /* (there is at least a linefeed) */ - for( ptr = psz_ip; ( *ptr != '#' ) && !isspace( *ptr ); ptr++ ); + /* look for first space, CR, LF, etc. or comment character */ + for( ptr = psz_ip; ( *ptr!='#' ) && !isspace( *ptr ) && *ptr; ++ptr ); *ptr = '\0'; + /* skip lines without usable information */ + if( ptr == psz_ip ) + continue; + msg_Dbg( p_acl->p_owner, "restricted to %s", psz_ip ); ptr = strchr( psz_ip, '/' ); @@ -373,11 +368,11 @@ int ACL_LoadFile( vlc_acl_t *p_acl, const char *psz_path ) *ptr++ = '\0'; /* separate address from mask length */ if( (ptr != NULL) - ? ACL_AddNet( p_acl, psz_ip, atoi( ptr ), VLC_TRUE ) - : ACL_AddHost( p_acl, psz_ip, VLC_TRUE ) ) + ? ACL_AddNet( p_acl, psz_ip, atoi( ptr ), true ) + : ACL_AddHost( p_acl, psz_ip, true ) ) { msg_Err( p_acl->p_owner, "cannot add ACL from %s", psz_path ); - goto error; + continue; } }