Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
4a7ad5b6
Commit
4a7ad5b6
authored
Oct 15, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
listen, client: enable SO_PASSCRED, get client's uid
Enable authentication over unix sockets. Store the client's uid in the client struct.
parent
fa56ff3d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
3 deletions
+41
-3
client.c
src/client.c
+12
-1
client.h
src/client.h
+7
-1
listen.c
src/listen.c
+22
-1
No files found.
src/client.c
View file @
4a7ad5b6
...
...
@@ -72,8 +72,13 @@ struct client {
char
buffer
[
CLIENT_MAX_BUFFER_LENGTH
];
size_t
bufferLength
;
size_t
bufferPos
;
int
fd
;
/* file descriptor; -1 if expired */
int
permission
;
/** the uid of the client process, or -1 if unknown */
int
uid
;
time_t
lastTime
;
struct
strnode
*
cmd_list
;
/* for when in list mode */
struct
strnode
*
cmd_list_tail
;
/* for when in list mode */
...
...
@@ -147,6 +152,11 @@ int client_is_expired(const struct client *client)
return
client
->
fd
<
0
;
}
int
client_get_uid
(
const
struct
client
*
client
)
{
return
client
->
uid
;
}
int
client_get_permission
(
const
struct
client
*
client
)
{
return
client
->
permission
;
...
...
@@ -323,7 +333,7 @@ sockaddr_to_tmp_string(const struct sockaddr *addr)
return
hostname
;
}
void
client_new
(
int
fd
,
const
struct
sockaddr
*
addr
)
void
client_new
(
int
fd
,
const
struct
sockaddr
*
addr
,
int
uid
)
{
struct
client
*
client
;
...
...
@@ -337,6 +347,7 @@ void client_new(int fd, const struct sockaddr *addr)
list_add
(
&
client
->
siblings
,
&
clients
);
++
num_clients
;
client_init
(
client
,
fd
);
client
->
uid
=
uid
;
SECURE
(
"client %i: opened from %s
\n
"
,
client
->
num
,
sockaddr_to_tmp_string
(
addr
));
}
...
...
src/client.h
View file @
4a7ad5b6
...
...
@@ -33,10 +33,16 @@ void client_manager_deinit(void);
int
client_manager_io
(
void
);
void
client_manager_expire
(
void
);
void
client_new
(
int
fd
,
const
struct
sockaddr
*
addr
);
void
client_new
(
int
fd
,
const
struct
sockaddr
*
addr
,
int
uid
);
int
client_is_expired
(
const
struct
client
*
client
);
/**
* returns the uid of the client process, or a negative value if the
* uid is unknown
*/
int
client_get_uid
(
const
struct
client
*
client
);
int
client_get_permission
(
const
struct
client
*
client
);
void
client_set_permission
(
struct
client
*
client
,
int
permission
);
...
...
src/listen.c
View file @
4a7ad5b6
...
...
@@ -74,6 +74,7 @@ static int establishListen(int pf, const struct sockaddr *addrp,
{
int
sock
;
int
allowReuse
=
ALLOW_REUSE
;
int
passcred
=
1
;
if
((
sock
=
socket
(
pf
,
SOCK_STREAM
,
0
))
<
0
)
FATAL
(
"socket < 0
\n
"
);
...
...
@@ -96,6 +97,10 @@ static int establishListen(int pf, const struct sockaddr *addrp,
if
(
listen
(
sock
,
5
)
<
0
)
FATAL
(
"problems listen'ing: %s
\n
"
,
strerror
(
errno
));
#if defined(HAVE_UN) && defined(SO_PASSCRED)
setsockopt
(
sock
,
SOL_SOCKET
,
SO_PASSCRED
,
&
passcred
,
sizeof
(
passcred
));
#endif
numberOfListenSockets
++
;
listenSockets
=
xrealloc
(
listenSockets
,
sizeof
(
int
)
*
numberOfListenSockets
);
...
...
@@ -258,6 +263,22 @@ void freeAllListenSockets(void)
listenSockets
=
NULL
;
}
static
int
get_remote_uid
(
int
fd
)
{
#if defined(HAVE_UN) && defined(SO_PEERCRED)
struct
ucred
cred
;
socklen_t
len
=
sizeof
(
cred
);
if
(
getsockopt
(
fd
,
SOL_SOCKET
,
SO_PEERCRED
,
&
cred
,
&
len
)
<
0
)
return
0
;
return
cred
.
uid
;
#else
(
void
)
fd
;
return
-
1
;
#endif
}
void
getConnections
(
fd_set
*
fds
)
{
int
i
;
...
...
@@ -269,7 +290,7 @@ void getConnections(fd_set * fds)
if
(
FD_ISSET
(
listenSockets
[
i
],
fds
))
{
if
((
fd
=
accept
(
listenSockets
[
i
],
&
sockAddr
,
&
socklen
))
>=
0
)
{
client_new
(
fd
,
&
sockAddr
);
client_new
(
fd
,
&
sockAddr
,
get_remote_uid
(
fd
)
);
}
else
if
(
fd
<
0
&&
(
errno
!=
EAGAIN
&&
errno
!=
EINTR
))
{
ERROR
(
"Problems accept()'ing
\n
"
);
...
...
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