redmine

Fixed: Permission denied on --enable-debug=no

Bugreport: https://github.com/xaionaro/clsync/issues/133
@@ -1054,19 +1054,28 @@ int privileged_handler(ctx_t *ctx_p) @@ -1054,19 +1054,28 @@ int privileged_handler(ctx_t *ctx_p)
1054 case -1: 1054 case -1:
1055 error("Cannot fork()."); 1055 error("Cannot fork().");
1056 break; 1056 break;
1057 - case 0: 1057 + case 0: {
  1058 + int rc;
  1059 + (void)rc; // anti-warning on ./configure --enable-debug=no
1058 #ifdef ANTIPARANOID 1060 #ifdef ANTIPARANOID
1059 if (ctx_p->privileged_gid != exec_gid) 1061 if (ctx_p->privileged_gid != exec_gid)
1060 #endif 1062 #endif
1061 - debug(4, "setgid(%u) == %i", exec_gid, setgid(exec_gid)); 1063 + {
  1064 + rc = setgid(exec_gid);
  1065 + debug(4, "setgid(%u) == %i", exec_gid, rc);
  1066 + }
1062 1067
1063 #ifdef ANTIPARANOID 1068 #ifdef ANTIPARANOID
1064 if (ctx_p->privileged_uid != exec_uid) 1069 if (ctx_p->privileged_uid != exec_uid)
1065 #endif 1070 #endif
1066 - debug(4, "setuid(%u) == %i", exec_uid, setuid(exec_uid)); 1071 + {
  1072 + rc = setuid(exec_uid);
  1073 + debug(4, "setuid(%u) == %i", exec_uid, rc);
  1074 + }
1067 1075
1068 debug(3, "execvp(\"%s\", argv)", file); 1076 debug(3, "execvp(\"%s\", argv)", file);
1069 exit(execvp(file, argv)); 1077 exit(execvp(file, argv));
  1078 + }
1070 } 1079 }
1071 cmd_ret_p->ret = (void *)(long)pid; 1080 cmd_ret_p->ret = (void *)(long)pid;
1072 debug(21, "/PA_FORK_EXECVP"); 1081 debug(21, "/PA_FORK_EXECVP");
@@ -1640,12 +1649,20 @@ int __privileged_fork_execvp(const char *file, char *const argv[]) @@ -1640,12 +1649,20 @@ int __privileged_fork_execvp(const char *file, char *const argv[])
1640 case -1: 1649 case -1:
1641 error("Cannot fork()."); 1650 error("Cannot fork().");
1642 return -1; 1651 return -1;
1643 - case 0: 1652 + case 0: {
1644 - debug(4, "setgid(%u) == %i", __privileged_fork_execvp_gid, setgid(__privileged_fork_execvp_gid)); 1653 + int rc;
1645 - debug(4, "setuid(%u) == %i", __privileged_fork_execvp_uid, setuid(__privileged_fork_execvp_uid)); 1654 + (void)rc; // anti-warning on ./configure --enable-debug=no
  1655 +
  1656 + rc = setgid(__privileged_fork_execvp_gid);
  1657 + debug(4, "setgid(%u) == %i", __privileged_fork_execvp_gid, rc);
  1658 +
  1659 + rc = setuid(__privileged_fork_execvp_uid);
  1660 + debug(4, "setuid(%u) == %i", __privileged_fork_execvp_uid, rc);
  1661 +
1646 errno = 0; 1662 errno = 0;
1647 execvp(file, argv); 1663 execvp(file, argv);
1648 exit(errno); 1664 exit(errno);
  1665 + }
1649 } 1666 }
1650 1667
1651 return pid; 1668 return pid;