1 --- gnupg-1.4.0/g10/g10.c 2004-12-16 09:47:36.000000000 +0000
2 +++ /tmp/dpep.O5S02c/gnupg-1.4.0/g10/g10.c 2005-02-03 23:31:40.645873299 +0000
7 +#ifdef USE_CAPABILITIES
8 +#include <sys/capability.h>
9 +#include <sys/prctl.h>
12 enum cmd_and_opt_values
15 @@ -1618,6 +1623,10 @@
16 #ifdef USE_SHM_COPROCESSING
17 ulong requested_shm_size=0;
19 +#ifdef USE_CAPABILITIES
26 @@ -1629,6 +1638,33 @@
27 * when adding any stuff between here and the call to
28 * secmem_init() somewhere after the option parsing
31 + /* if we use capabilities and run as root, we can immediately setuid back
32 + * to the normal user and only keep CAP_IPC_LOCK until the shared memory is
35 +#ifdef USE_CAPABILITIES
36 + curr_uid = getuid();
37 + if( curr_uid && !geteuid() ) { /* we are setuid root */
38 + if( prctl( PR_SET_KEEPCAPS, 1, 0, 0, 0 ) ) {
39 + perror( "main(): could not keep capabilities" );
43 + if( setuid( curr_uid ) ) {
44 + perror( "main(): could not set user id" );
48 + caps = cap_from_text( "cap_ipc_lock=p" );
49 + if( cap_set_proc( caps ) ) {
50 + perror( "main(): could not install capabilities" );
58 secure_random_alloc(); /* put random number into secure memory */
59 may_coredump = disable_core_dumps();
63 /* initialize the secure memory. */
64 - got_secmem=secmem_init( 32768 );
65 + got_secmem=secmem_init( 32768 ); /* this will drop all remaining privileges */
67 /* Okay, we are now working under our real uid */