0

#のファイルは、/usr/include/linux/capability.h34 の可能な機能を定義します。次のようになります。

#define CAP_CHOWN            0

#define CAP_DAC_OVERRIDE     1

.....

#define CAP_MAC_ADMIN        33

#define CAP_LAST_CAP         CAP_MAC_ADMIN

各プロセスには、このように定義された機能があります

typedef struct __user_cap_data_struct {

        __u32 effective;
        __u32 permitted;
        __u32 inheritable;
} * cap_user_data_t;

私は混乱しています - プロセスは 32 ビットの有効な機能を持つことができますが、capability.h で定義されている機能の合計量は 34 です。

4

2 に答える 2

3

マニュアルをすべて読んでいないからです。

capget マニュアルは、それを使用しないように説得することから始まります。

These two functions are the raw kernel interface for getting  and  set‐
ting  thread capabilities.  Not only are these system calls specific to
Linux, but the kernel API is likely to change and use  of  these  func‐
tions  (in  particular the format of the cap_user_*_t types) is subject
to extension with each kernel revision,  but  old  programs  will  keep
working.

The  portable  interfaces  are  cap_set_proc(3) and cap_get_proc(3); if
possible you should use those interfaces in applications.  If you  wish
to use the Linux extensions in applications, you should use the easier-
to-use interfaces capsetp(3) and capgetp(3).

現在の詳細

Now that you have been warned, some current kernel details.  The struc‐
tures are defined as follows.

#define _LINUX_CAPABILITY_VERSION_1  0x19980330
#define _LINUX_CAPABILITY_U32S_1     1

#define _LINUX_CAPABILITY_VERSION_2  0x20071026
#define _LINUX_CAPABILITY_U32S_2     2

[...]
effective,  permitted,  inheritable  are  bitmasks  of the capabilities
defined in capability(7).  Note the CAP_* values are  bit  indexes  and
need to be bit-shifted before ORing into the bit fields.
[...]
Kernels  prior  to  2.6.25  prefer  32-bit  capabilities  with  version
_LINUX_CAPABILITY_VERSION_1, and kernels 2.6.25+ prefer 64-bit capabil‐
ities with version _LINUX_CAPABILITY_VERSION_2.  Note, 64-bit capabili‐
ties  use  datap[0]  and datap[1], whereas 32-bit capabilities only use
datap[0].

wheredatapは、へのポインターとして以前に定義されていました__user_cap_data_struct__u32したがって、 twoの配列で 2つの 64 ビット値を表すだけです__user_cap_data_struct

これだけでも、この API を使用してはならないことがわかります。そのため、マニュアルの残りの部分を読みませんでした。

于 2011-12-27T20:51:33.590 に答える
2

それらはビットマスクではなく、単なる定数です。EGCAP_MAC_ADMINは複数のビットを設定します。バイナリでは、33 は何ですか、10001?

于 2011-12-27T18:49:30.827 に答える