Ticket #21: pulseaudio_fix21-2.patch

File pulseaudio_fix21-2.patch, 2.6 kB (added by rawuza, 2 years ago)
  • pulseaudio/src/daemon/caps.c

    old new  
    6969#endif 
    7070} 
    7171 
     72/* Switch to real user, but only set effective UID so 
     73   we can switch back to root later */ 
     74void pa_suspend_root(void) { 
     75    uid_t uid = getuid(); 
     76 
     77    if (uid == 0 || geteuid() != 0) 
     78        return; 
     79 
     80    pa_log_info("suspending root privileges."); 
     81 
     82#if defined(HAVE_SETRESUID) 
     83    setresuid(-1, uid, -1); 
     84#elif defined(HAVE_SETREUID) 
     85    setreuid(-1, uid); 
     86#else 
     87    seteuid(uid); 
     88#endif 
     89} 
     90 
     91/* Re-gain root privileges */ 
     92void pa_gain_root(void) { 
     93    if (geteuid() == 0) 
     94      return; 
     95 
     96    pa_log_info("gaining root privileges."); 
     97 
     98#if defined(HAVE_SETRESUID) 
     99    setresuid(-1, 0, -1); 
     100#elif defined(HAVE_SETREUID) 
     101    setreuid(-1, 0); 
     102#else 
     103    seteuid(0); 
     104#endif 
     105} 
     106 
    72107#else 
    73108 
    74109void pa_drop_root(void) { 
    75110} 
    76111 
     112void pa_suspend_root(void) { 
     113} 
     114 
     115void pa_gain_root(void) { 
     116} 
    77117#endif 
    78118 
    79119#ifdef HAVE_SYS_CAPABILITY_H 
  • pulseaudio/src/daemon/caps.h

    old new  
    2525***/ 
    2626 
    2727void pa_drop_root(void); 
     28void pa_suspend_root(void); 
     29void pa_gain_root(void); 
    2830int pa_limit_caps(void); 
    2931int pa_drop_caps(void); 
    3032 
  • pulseaudio/src/daemon/main.c

    old new  
    331331 
    332332    setlocale(LC_ALL, ""); 
    333333 
    334     pa_limit_caps(); 
    335  
    336334#ifdef HAVE_GETUID 
    337335    real_root = getuid() == 0; 
    338336    suid_root = !real_root && geteuid() == 0; 
    339337 
     338    pa_suspend_root(); 
     339 
    340340    if (suid_root && (pa_own_uid_in_group(PA_REALTIME_GROUP, &gid) <= 0 || gid >= 1000)) { 
    341341        pa_log_warn("WARNING: called SUID root, but not in group '"PA_REALTIME_GROUP"'."); 
    342342        pa_drop_root(); 
     
    378378    pa_log_set_maximal_level(conf->log_level); 
    379379    pa_log_set_target(conf->auto_log_target ? PA_LOG_STDERR : conf->log_target, NULL); 
    380380 
    381     if (conf->high_priority && conf->cmd == PA_CMD_DAEMON) 
    382         pa_raise_priority(); 
    383  
    384     pa_drop_caps(); 
     381    if (conf->high_priority && conf->cmd == PA_CMD_DAEMON) { 
     382#ifdef HAVE_GETUID 
     383      pa_gain_root(); 
     384#endif 
     385      pa_limit_caps(); 
     386      pa_raise_priority(); 
     387      pa_drop_caps(); 
     388    } 
    385389 
    386390    if (suid_root) 
    387391        pa_drop_root();