Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-gpu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-gpu
Commits
536779c8
Commit
536779c8
authored
Jun 06, 2008
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix/split rootwrap_bind
parent
aa47b162
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
172 additions
and
1 deletion
+172
-1
src/Makefile.am
src/Makefile.am
+1
-1
src/network/rootbind.c
src/network/rootbind.c
+171
-0
No files found.
src/Makefile.am
View file @
536779c8
...
...
@@ -321,7 +321,7 @@ SOURCES_libvlc_common = \
network/tcp.c
\
network/udp.c
\
network/httpd.c
\
network/root
wrap
.c
\
network/root
bind
.c
\
network/tls.c
\
network/poll.c
\
text/charset.c
\
...
...
src/network/rootbind.c
0 → 100644
View file @
536779c8
/*****************************************************************************
* rootbind.c: bind to reserved ports through the root wrapper
*****************************************************************************
* Copyright © 2005-2008 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#if !defined (WIN32) && !defined (SYS_BEOS)
# define ENABLE_ROOTWRAP 1
#endif
#include <stddef.h>
struct
sockaddr
;
int
rootwrap_bind
(
int
,
int
,
int
,
const
struct
sockaddr
*
,
size_t
);
#include <errno.h>
#ifdef ENABLE_ROOTWRAP
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <pthread.h>
/**
* Receive a file descriptor from another process
*/
static
int
recv_fd
(
int
p
)
{
struct
msghdr
hdr
;
struct
iovec
iov
;
struct
cmsghdr
*
cmsg
;
int
val
,
fd
;
char
buf
[
CMSG_SPACE
(
sizeof
(
fd
))];
hdr
.
msg_name
=
NULL
;
hdr
.
msg_namelen
=
0
;
hdr
.
msg_iov
=
&
iov
;
hdr
.
msg_iovlen
=
1
;
hdr
.
msg_control
=
buf
;
hdr
.
msg_controllen
=
sizeof
(
buf
);
iov
.
iov_base
=
&
val
;
iov
.
iov_len
=
sizeof
(
val
);
if
(
recvmsg
(
p
,
&
hdr
,
0
)
!=
sizeof
(
val
))
return
-
1
;
for
(
cmsg
=
CMSG_FIRSTHDR
(
&
hdr
);
cmsg
!=
NULL
;
cmsg
=
CMSG_NXTHDR
(
&
hdr
,
cmsg
))
{
if
((
cmsg
->
cmsg_level
==
SOL_SOCKET
)
&&
(
cmsg
->
cmsg_type
=
SCM_RIGHTS
)
&&
(
cmsg
->
cmsg_len
>=
CMSG_LEN
(
sizeof
(
fd
))))
{
memcpy
(
&
fd
,
CMSG_DATA
(
cmsg
),
sizeof
(
fd
));
return
fd
;
}
}
errno
=
val
;
return
-
1
;
}
/**
* Tries to obtain a bound TCP socket from the root process
*/
int
rootwrap_bind
(
int
family
,
int
socktype
,
int
protocol
,
const
struct
sockaddr
*
addr
,
size_t
alen
)
{
/* can't use libvlc */
static
pthread_mutex_t
mutex
=
PTHREAD_MUTEX_INITIALIZER
;
struct
sockaddr_storage
ss
;
int
fd
,
sock
=
-
1
;
const
char
*
sockenv
=
getenv
(
"VLC_ROOTWRAP_SOCK"
);
if
(
sockenv
!=
NULL
)
sock
=
atoi
(
sock
);
if
(
sock
==
-
1
)
{
errno
=
EACCES
;
return
-
1
;
}
switch
(
family
)
{
case
AF_INET
:
if
(
alen
<
sizeof
(
struct
sockaddr_in
))
{
errno
=
EINVAL
;
return
-
1
;
}
break
;
#ifdef AF_INET6
case
AF_INET6
:
if
(
alen
<
sizeof
(
struct
sockaddr_in6
))
{
errno
=
EINVAL
;
return
-
1
;
}
break
;
#endif
default:
errno
=
EAFNOSUPPORT
;
return
-
1
;
}
if
(
family
!=
addr
->
sa_family
)
{
errno
=
EAFNOSUPPORT
;
return
-
1
;
}
/* Only TCP is implemented at the moment */
if
((
socktype
!=
SOCK_STREAM
)
||
(
protocol
&&
(
protocol
!=
IPPROTO_TCP
)))
{
errno
=
EACCES
;
return
-
1
;
}
memset
(
&
ss
,
0
,
sizeof
(
ss
));
memcpy
(
&
ss
,
addr
,
alen
>
sizeof
(
ss
)
?
sizeof
(
ss
)
:
alen
);
pthread_mutex_lock
(
&
mutex
);
if
(
send
(
sock
,
&
ss
,
sizeof
(
ss
),
0
)
!=
sizeof
(
ss
))
return
-
1
;
fd
=
recv_fd
(
sock
);
pthread_mutex_unlock
(
&
mutex
);
return
fd
;
}
#else
int
rootwrap_bind
(
int
family
,
int
socktype
,
int
protocol
,
const
struct
sockaddr
*
addr
,
size_t
alen
)
{
(
void
)
family
;
(
void
)
socktype
;
(
void
)
protocol
;
(
void
)
addr
;
(
void
)
alen
;
errno
=
EACCES
;
return
-
1
;
}
#endif
/* ENABLE_ROOTWRAP */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment