]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/gnupg/gnupg-1.4.0/16_min_privileges.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / gnupg / gnupg-1.4.0 / 16_min_privileges.patch
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
3 @@ -69,6 +69,11 @@
4  #endif
5  
6  
7 +#ifdef USE_CAPABILITIES
8 +#include <sys/capability.h>
9 +#include <sys/prctl.h>
10 +#endif
11 +
12  enum cmd_and_opt_values
13    {
14      aNull = 0,
15 @@ -1618,6 +1623,10 @@
16  #ifdef USE_SHM_COPROCESSING
17      ulong requested_shm_size=0;
18  #endif
19 +#ifdef USE_CAPABILITIES
20 +    uid_t curr_uid;
21 +    cap_t caps;
22 +#endif
23  
24  #ifdef __riscos__
25      opt.lock_once = 1;
26 @@ -1629,6 +1638,33 @@
27       * when adding any stuff between here and the call to
28       * secmem_init()  somewhere after the option parsing
29       */
30 +
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
33 +     * set up.
34 +     */
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" );
40 +           return -100;
41 +       }
42 +
43 +       if( setuid( curr_uid ) ) {
44 +           perror( "main(): could not set user id" );
45 +           return -100;
46 +       }
47 +
48 +       caps = cap_from_text( "cap_ipc_lock=p" );
49 +       if( cap_set_proc( caps ) ) {
50 +           perror( "main(): could not install capabilities" );
51 +           return -100;
52 +       }
53 +       cap_free( caps );
54 +    }
55 +#endif
56 +
57      log_set_name("gpg");
58      secure_random_alloc(); /* put random number into secure memory */
59      may_coredump = disable_core_dumps();
60 @@ -1747,7 +1783,7 @@
61      }
62  #endif
63      /* initialize the secure memory. */
64 -    got_secmem=secmem_init( 32768 );
65 +    got_secmem=secmem_init( 32768 ); /* this will drop all remaining privileges */
66      maybe_setuid = 0;
67      /* Okay, we are now working under our real uid */
68