66 * Copyright (c) 2021 Google
77 */
88
9- #include "linux/capability.h"
10- #include <stddef.h>
119#define _GNU_SOURCE
1210#include "config.h"
1311
@@ -1444,14 +1442,10 @@ static int cb_listen_control_msg(sd_event_source *s, int sd, uint32_t revents,
14441442
14451443static int listen_control_msg (struct ctx * ctx , uint32_t net )
14461444{
1447- cap_flag_t dropped_sets [] = { CAP_EFFECTIVE , CAP_INHERITABLE ,
1448- CAP_PERMITTED };
1449- cap_value_t dropped_capability [] = { CAP_NET_BIND_SERVICE };
14501445 struct sockaddr_mctp addr = { 0 };
14511446 int rc , sd = -1 , val ;
14521447 char * failed ;
14531448 cap_t cap ;
1454- size_t i ;
14551449
14561450 sd = mctp_ops .mctp .socket ();
14571451 if (sd < 0 ) {
@@ -1471,21 +1465,12 @@ static int listen_control_msg(struct ctx *ctx, uint32_t net)
14711465 goto warn_out ;
14721466 }
14731467
1474- cap = cap_get_proc ( );
1468+ cap = cap_from_text ( "CAP_NET_ADMIN=pe" );
14751469 if (!cap ) {
1476- failed = "cap_get_proc ()" ;
1470+ failed = "cap_from_text ()" ;
14771471 goto warn_out ;
14781472 }
14791473
1480- for (i = 0 ; i < ARRAY_SIZE (dropped_sets ); i ++ ) {
1481- rc = cap_set_flag (cap , dropped_sets [i ], 1 , dropped_capability ,
1482- CAP_CLEAR );
1483- if (rc < 0 ) {
1484- failed = "cap_clear_flag()" ;
1485- goto cap_out ;
1486- }
1487- }
1488-
14891474 rc = cap_set_proc (cap );
14901475 if (rc < 0 ) {
14911476 failed = "cap_set_proc()" ;
@@ -6389,6 +6374,7 @@ static int endpoint_allocate_eids(struct peer *peer)
63896374int main (int argc , char * * argv )
63906375{
63916376 struct ctx ctxi = { 0 }, * ctx = & ctxi ;
6377+ cap_t cap ;
63926378 int rc ;
63936379
63946380 setlinebuf (stdout );
@@ -6408,6 +6394,26 @@ int main(int argc, char **argv)
64086394 err (EXIT_FAILURE , "Can't read configuration" );
64096395 }
64106396
6397+ cap = cap_from_text ("CAP_NET_BIND_SERVICE=pe CAP_NET_ADMIN=p" );
6398+ if (!cap ) {
6399+ warnx ("Failed allocating capability state, %s %d" ,
6400+ strerror (errno ), - errno );
6401+ return 1 ;
6402+ }
6403+
6404+ rc = cap_set_proc (cap );
6405+ if (rc < 0 ) {
6406+ warnx ("Could not set capabilites %s %d" , strerror (errno ),
6407+ - errno );
6408+ return 1 ;
6409+ }
6410+
6411+ rc = cap_free (cap );
6412+ if (rc < 0 ) {
6413+ warnx ("Failed freeing capability state" );
6414+ return 1 ;
6415+ }
6416+
64116417 ctx -> nl = mctp_nl_new (false);
64126418 if (!ctx -> nl ) {
64136419 warnx ("Failed creating netlink object" );
0 commit comments