"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/libcap/cap_flag.c" between
proftpd-1.3.6b.tar.gz and proftpd-1.3.6c.tar.gz

About: ProFTPD is a highly configurable FTP server software (with FTPS and SFTP support).

cap_flag.c  (proftpd-1.3.6b):cap_flag.c  (proftpd-1.3.6c)
/* /*
* Copyright (c) 1997-8 Andrew G. Morgan <morgan@linux.kernel.org> * Copyright (c) 1997-8,2008 Andrew G. Morgan <morgan@kernel.org>
*
* See end of file for Log.
* *
* This file deals with flipping of capabilities on internal * This file deals with flipping of capabilities on internal
* capability sets as specified by POSIX.1e (formerlly, POSIX 6). * capability sets as specified by POSIX.1e (formerlly, POSIX 6).
*/ */
#include "libcap.h" #include "libcap.h"
/* /*
* Return the state of a specified capability flag. The state is * Return the state of a specified capability flag. The state is
* returned as the contents of *raised. The capability is from one of * returned as the contents of *raised. The capability is from one of
skipping to change at line 28 skipping to change at line 26
int cap_get_flag(cap_t cap_d, cap_value_t value, cap_flag_t set, int cap_get_flag(cap_t cap_d, cap_value_t value, cap_flag_t set,
cap_flag_value_t *raised) cap_flag_value_t *raised)
{ {
/* /*
* Do we have a set and a place to store its value? * Do we have a set and a place to store its value?
* Is it a known capability? * Is it a known capability?
*/ */
if (raised && good_cap_t(cap_d) && value >= 0 && value < __CAP_BITS if (raised && good_cap_t(cap_d) && value >= 0 && value < __CAP_BITS
&& set >= 0 && set < NUMBER_OF_CAP_SETS) { && set >= 0 && set < NUMBER_OF_CAP_SETS) {
__cap_s *cap_p = (__cap_s *) (set*CAP_SET_SIZE *raised = isset_cap(cap_d,value,set) ? CAP_SET:CAP_CLEAR;
+ (__u8 *) &cap_d->set);
*raised = isset_cap(cap_p,value) ? CAP_SET:CAP_CLEAR;
return 0; return 0;
} else { } else {
_cap_debug("invalid arguments"); _cap_debug("invalid arguments");
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
} }
/* /*
* raise/lower a selection of capabilities * raise/lower a selection of capabilities
*/ */
int cap_set_flag(cap_t cap_d, cap_flag_t set, int cap_set_flag(cap_t cap_d, cap_flag_t set,
int no_values, cap_value_t *array_values, int no_values, const cap_value_t *array_values,
cap_flag_value_t raise) cap_flag_value_t raise)
{ {
/* /*
* Do we have a set and a place to store its value? * Do we have a set and a place to store its value?
* Is it a known capability? * Is it a known capability?
*/ */
if (good_cap_t(cap_d) && no_values > 0 && no_values <= __CAP_BITS if (good_cap_t(cap_d) && no_values > 0 && no_values <= __CAP_BITS
&& (set >= 0) && (set < NUMBER_OF_CAP_SETS) && (set >= 0) && (set < NUMBER_OF_CAP_SETS)
&& (raise == CAP_SET || raise == CAP_CLEAR) ) { && (raise == CAP_SET || raise == CAP_CLEAR) ) {
int i; int i;
for (i=0; i<no_values; ++i) { for (i=0; i<no_values; ++i) {
if (array_values[i] < 0 || array_values[i] >= __CAP_BITS) { if (array_values[i] < 0 || array_values[i] >= __CAP_BITS) {
_cap_debug("weird capability (%d) - skipped", array_values[i]); _cap_debug("weird capability (%d) - skipped", array_values[i]);
} else { } else {
int value = array_values[i]; int value = array_values[i];
__cap_s *cap_p = (__cap_s *) (set*CAP_SET_SIZE
+ (__u8 *) &cap_d->set);
if (raise == CAP_SET) { if (raise == CAP_SET) {
cap_p->raise_cap(value); cap_d->raise_cap(value,set);
} else { } else {
cap_p->lower_cap(value); cap_d->lower_cap(value,set);
} }
} }
} }
return 0; return 0;
} else { } else {
_cap_debug("invalid arguments"); _cap_debug("invalid arguments");
errno = EINVAL; errno = EINVAL;
return -1; return -1;
skipping to change at line 94 skipping to change at line 84
} }
/* /*
* Reset the capability to be empty (nothing raised) * Reset the capability to be empty (nothing raised)
*/ */
int cap_clear(cap_t cap_d) int cap_clear(cap_t cap_d)
{ {
if (good_cap_t(cap_d)) { if (good_cap_t(cap_d)) {
memset(&(cap_d->set), 0, sizeof(cap_d->set)); memset(&(cap_d->u), 0, sizeof(cap_d->u));
return 0; return 0;
} else { } else {
_cap_debug("invalid pointer"); _cap_debug("invalid pointer");
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
} }
/* /*
* $Log: cap_flag.c,v $ * Reset the all of the capability bits for one of the flag sets
* Revision 1.1 2003-01-03 02:16:17 jwm
*
* Turning mod_linuxprivs into a core module, mod_cap. This is by no means
* complete.
*
* Revision 1.2 1999/09/07 23:14:19 macgyver
* Updated capabilities library and model.
*
* Revision 1.1.1.1 1999/04/17 22:16:31 morgan
* release 1.0 of libcap
*
* Revision 1.4 1998/09/20 23:07:59 morgan
* fixed lower bound check on 'set'.
*
* Revision 1.3 1998/05/24 22:54:09 morgan
* updated for 2.1.104
*
* Revision 1.2 1997/04/28 00:57:11 morgan
* fixes and zefram's patches
*
* Revision 1.1 1997/04/21 04:32:52 morgan
* Initial revision
*
*/ */
int cap_clear_flag(cap_t cap_d, cap_flag_t flag)
{
switch (flag) {
case CAP_EFFECTIVE:
case CAP_PERMITTED:
case CAP_INHERITABLE:
if (good_cap_t(cap_d)) {
unsigned i;
for (i=0; i<_LIBCAP_CAPABILITY_U32S; i++) {
cap_d->u[i].flat[flag] = 0;
}
return 0;
}
/*
* fall through
*/
default:
_cap_debug("invalid pointer");
errno = EINVAL;
return -1;
}
}
/*
* Compare two capability sets
*/
int cap_compare(cap_t a, cap_t b)
{
unsigned i;
int result;
if (!(good_cap_t(a) && good_cap_t(b))) {
_cap_debug("invalid arguments");
errno = EINVAL;
return -1;
}
for (i=0, result=0; i<_LIBCAP_CAPABILITY_U32S; i++) {
result |=
((a->u[i].flat[CAP_EFFECTIVE] != b->u[i].flat[CAP_EFFECTIVE])
? LIBCAP_EFF : 0)
| ((a->u[i].flat[CAP_INHERITABLE] != b->u[i].flat[CAP_INHERITABLE])
? LIBCAP_INH : 0)
| ((a->u[i].flat[CAP_PERMITTED] != b->u[i].flat[CAP_PERMITTED])
? LIBCAP_PER : 0);
}
return result;
}
 End of changes. 12 change blocks. 
40 lines changed or deleted 7 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)