2011-12-27 7 views
0

/usr/include/linux/capability.hのファイルには#34の可能な機能が定義されています。 それはのようになります:linux capability.hは34要素に対して32ビットマスクをどのように使用しますか?

#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ビットを持つことができ、まだ機能で定義された能力の総量を.hは34です。32ビットマスクで34の位置をエンコードすることはどのように可能ですか?

答えて

3

マニュアルをすべて読んだわけではありません。

capgetマニュアルは、あなたがそれを使用しないように説得することから始まり:datapは以前__user_cap_data_structへのポインタとして定義されて

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]. 

。したがって、2つの__u32の配列が2つの__user_cap_data_structの64ビット値を表します。

これだけでこのAPIを使用しないように指示しているので、残りのマニュアルは読んでいません。

2

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

+0

私はいつも、それぞれの機能が、設定されているか設定されていないこれらの3つのビットマップのそれぞれのビットとして実装されていると考えました。そのため、32ビットの34の可能な機能があります。 – abirvalg

+0

@abirvalg:そうではありません。それらが '#defined'にある値を見てください。それらはビット定数ではありません。 – Puppy

+0

@DeadMG:残念ながら... – BatchyX

関連する問題