mirror of
https://github.com/bol-van/zapret.git
synced 2025-04-19 13:32:58 +03:00
nfqws, tpws : read cap_last_cap to avoid errors on some systems
This commit is contained in:
parent
7504f697ce
commit
b8696afdb7
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18
nfq/nfqws.c
18
nfq/nfqws.c
@ -387,26 +387,36 @@ bool setpcap(cap_value_t *caps,int ncaps)
|
|||||||
cap_free(capabilities);
|
cap_free(capabilities);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
int getmaxcap()
|
||||||
|
{
|
||||||
|
int maxcap = CAP_LAST_CAP;
|
||||||
|
FILE *F = fopen("/proc/sys/kernel/cap_last_cap","r");
|
||||||
|
if (F)
|
||||||
|
{
|
||||||
|
fscanf(F,"%d",&maxcap);
|
||||||
|
fclose(F);
|
||||||
|
}
|
||||||
|
return maxcap;
|
||||||
|
|
||||||
|
}
|
||||||
bool dropcaps()
|
bool dropcaps()
|
||||||
{
|
{
|
||||||
// must have CAP_SETPCAP at the end. its required to clear bounding set
|
// must have CAP_SETPCAP at the end. its required to clear bounding set
|
||||||
cap_value_t cap_values[] = {CAP_NET_ADMIN,CAP_SETPCAP};
|
cap_value_t cap_values[] = {CAP_NET_ADMIN,CAP_SETPCAP};
|
||||||
int capct=sizeof(cap_values)/sizeof(*cap_values);
|
int capct=sizeof(cap_values)/sizeof(*cap_values);
|
||||||
|
int maxcap = getmaxcap();
|
||||||
|
|
||||||
if (setpcap(cap_values, capct))
|
if (setpcap(cap_values, capct))
|
||||||
{
|
{
|
||||||
for(int cap=0;cap<=63;cap++)
|
for(int cap=0;cap<=maxcap;cap++)
|
||||||
{
|
{
|
||||||
if (cap_drop_bound(cap))
|
if (cap_drop_bound(cap))
|
||||||
{
|
|
||||||
if (errno!=EINVAL)
|
|
||||||
{
|
{
|
||||||
fprintf(stderr,"could not drop cap %d\n",cap);
|
fprintf(stderr,"could not drop cap %d\n",cap);
|
||||||
perror("cap_drop_bound");
|
perror("cap_drop_bound");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// now without CAP_SETPCAP
|
// now without CAP_SETPCAP
|
||||||
if (!setpcap(cap_values, capct - 1))
|
if (!setpcap(cap_values, capct - 1))
|
||||||
{
|
{
|
||||||
|
18
tpws/tpws.c
18
tpws/tpws.c
@ -816,26 +816,36 @@ bool setpcap(cap_value_t *caps,int ncaps)
|
|||||||
cap_free(capabilities);
|
cap_free(capabilities);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
int getmaxcap()
|
||||||
|
{
|
||||||
|
int maxcap = CAP_LAST_CAP;
|
||||||
|
FILE *F = fopen("/proc/sys/kernel/cap_last_cap","r");
|
||||||
|
if (F)
|
||||||
|
{
|
||||||
|
fscanf(F,"%d",&maxcap);
|
||||||
|
fclose(F);
|
||||||
|
}
|
||||||
|
return maxcap;
|
||||||
|
|
||||||
|
}
|
||||||
bool dropcaps()
|
bool dropcaps()
|
||||||
{
|
{
|
||||||
// must have CAP_SETPCAP at the end. its required to clear bounding set
|
// must have CAP_SETPCAP at the end. its required to clear bounding set
|
||||||
cap_value_t cap_values[] = {CAP_SETPCAP};
|
cap_value_t cap_values[] = {CAP_SETPCAP};
|
||||||
int capct=sizeof(cap_values)/sizeof(*cap_values);
|
int capct=sizeof(cap_values)/sizeof(*cap_values);
|
||||||
|
int maxcap = getmaxcap();
|
||||||
|
|
||||||
if (setpcap(cap_values, capct))
|
if (setpcap(cap_values, capct))
|
||||||
{
|
{
|
||||||
for(int cap=0;cap<=63;cap++)
|
for(int cap=0;cap<=maxcap;cap++)
|
||||||
{
|
{
|
||||||
if (cap_drop_bound(cap))
|
if (cap_drop_bound(cap))
|
||||||
{
|
|
||||||
if (errno!=EINVAL)
|
|
||||||
{
|
{
|
||||||
fprintf(stderr,"could not drop cap %d\n",cap);
|
fprintf(stderr,"could not drop cap %d\n",cap);
|
||||||
perror("cap_drop_bound");
|
perror("cap_drop_bound");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// now without CAP_SETPCAP
|
// now without CAP_SETPCAP
|
||||||
if (!setpcap(cap_values, capct - 1))
|
if (!setpcap(cap_values, capct - 1))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user