X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fnetwork%2Facl.c;h=9d15a7eb2ad28a77146ab9e5458dd7c5375f93e3;hb=c6b2d01d4df5e571ea90373f2cf224b7e49d36fd;hp=fcc52629b4607a2c89614b7123a8e0c4bdf4b798;hpb=d666030b2349e8a710fcba4d2cabb912cc700580;p=vlc diff --git a/src/network/acl.c b/src/network/acl.c index fcc52629b4..9d15a7eb2a 100644 --- a/src/network/acl.c +++ b/src/network/acl.c @@ -33,10 +33,8 @@ #include #include -#include - #include -#include +#include /* FIXME: rwlock on acl, but libvlc doesn't implement rwlock */ typedef struct vlc_acl_entry_t @@ -86,9 +84,7 @@ static int ACL_Resolve( vlc_object_t *p_this, uint8_t *p_bytes, break; } -#if defined (HAVE_GETADDRINFO) || defined (WIN32) - /* unfortunately many people define AF_INET6 - though they don't have struct sockaddr_in6 */ +#ifdef AF_INET6 case AF_INET6: { struct sockaddr_in6 *addr; @@ -101,11 +97,11 @@ static int ACL_Resolve( vlc_object_t *p_this, uint8_t *p_bytes, default: msg_Err( p_this, "unknown address family" ); - vlc_freeaddrinfo( res ); + freeaddrinfo( res ); return -1; } - vlc_freeaddrinfo( res ); + freeaddrinfo( res ); return i_family; } @@ -201,7 +197,7 @@ int ACL_AddNet( vlc_acl_t *p_acl, const char *psz_ip, int i_len, return 0; } - +#undef ACL_Create /** * Creates an empty ACL. * @@ -210,7 +206,7 @@ int ACL_AddNet( vlc_acl_t *p_acl, const char *psz_ip, int i_len, * * @return an ACL object. NULL in case of error. */ -vlc_acl_t *__ACL_Create( vlc_object_t *p_this, bool b_allow ) +vlc_acl_t *ACL_Create( vlc_object_t *p_this, bool b_allow ) { vlc_acl_t *p_acl; @@ -218,7 +214,7 @@ vlc_acl_t *__ACL_Create( vlc_object_t *p_this, bool 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; @@ -227,7 +223,7 @@ vlc_acl_t *__ACL_Create( vlc_object_t *p_this, bool b_allow ) return p_acl; } - +#undef ACL_Duplicate /** * Perform a deep copy of an existing ACL. * @@ -236,7 +232,7 @@ vlc_acl_t *__ACL_Create( vlc_object_t *p_this, bool 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; @@ -264,7 +260,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; @@ -280,9 +276,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 ); } @@ -304,7 +298,7 @@ int ACL_LoadFile( vlc_acl_t *p_acl, const char *psz_path ) if( p_acl == NULL ) return -1; - file = utf8_fopen( psz_path, "r" ); + file = vlc_fopen( psz_path, "r" ); if( file == NULL ) return -1; @@ -335,7 +329,7 @@ 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", psz_path); @@ -356,16 +350,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, '/' ); @@ -377,7 +370,7 @@ int ACL_LoadFile( vlc_acl_t *p_acl, const char *psz_path ) : ACL_AddHost( p_acl, psz_ip, true ) ) { msg_Err( p_acl->p_owner, "cannot add ACL from %s", psz_path ); - goto error; + continue; } }