"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/handy.c" between
burp-2.3.14.tar.bz2 and burp-2.3.20.tar.bz2

About: Burp is a backup and restore program using librsync and also VSS (for Windows clients). Latest version.

handy.c  (burp-2.3.14.tar.bz2):handy.c  (burp-2.3.20.tar.bz2)
skipping to change at line 339 skipping to change at line 339
void setup_signal(int sig, void handler(int sig)) void setup_signal(int sig, void handler(int sig))
{ {
struct sigaction sa; struct sigaction sa;
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
sa.sa_handler=handler; sa.sa_handler=handler;
sigaction(sig, &sa, NULL); sigaction(sig, &sa, NULL);
} }
/* Function based on src/lib/priv.c from bacula. */ /* Function based on src/lib/priv.c from bacula. */
int chuser_and_or_chgrp(const char *user, const char *group) int chuser_and_or_chgrp(const char *user, const char *group, int readall)
{ {
#ifndef HAVE_WIN32 #ifdef HAVE_WIN32
return 0;
#else
struct passwd *passw = NULL; struct passwd *passw = NULL;
struct group *grp = NULL; struct group *grp = NULL;
gid_t gid; gid_t gid;
uid_t uid; uid_t uid;
char *username=NULL; char *username=NULL;
// Allow setting readall=1 without setting user
if(readall && !user)
user="nobody";
if(!user && !group) return 0; if(!user && !group) return 0;
if(user) if(user)
{ {
if(!(passw=getpwnam(user))) if(!(passw=getpwnam(user)))
{ {
logp("could not find user '%s': %s\n", logp("could not find user '%s': %s\n",
user, strerror(errno)); user, strerror(errno));
return -1; return -1;
} }
skipping to change at line 380 skipping to change at line 385
if(!(username=strdup_w(user, __func__))) if(!(username=strdup_w(user, __func__)))
return -1; return -1;
uid=passw->pw_uid; uid=passw->pw_uid;
gid=passw->pw_gid; gid=passw->pw_gid;
if(group) if(group)
{ {
if(!(grp=getgrnam(group))) if(!(grp=getgrnam(group)))
{ {
logp("could not find group '%s': %s\n", group, logp("could not find group '%s': %s\n", group,
strerror(errno)); strerror(errno));
free_w(&username); goto err;
return -1;
} }
gid=grp->gr_gid; gid=grp->gr_gid;
} else {
// Resolve gid to group name for logp()
if (!(grp=getgrgid(gid)))
{
logp("could not find group for gid %d: %s\n", gid,
strerror(errno));
goto err;
}
group=grp->gr_name;
grp=NULL;
} }
if(gid!=getgid() // do not do it if we already have the same gid. if(gid!=getgid() // do not do it if we already have the same gid.
&& initgroups(username, gid)) && initgroups(username, gid))
{ {
if(grp) if(grp)
logp("could not initgroups for group '%s', user '%s': %s\ n", group, user, strerror(errno)); logp("could not initgroups for group '%s', user '%s': %s\ n", group, username, strerror(errno));
else else
logp("could not initgroups for user '%s': %s\n", user, st logp("could not initgroups for user '%s': %s\n", username
rerror(errno)); , strerror(errno));
free_w(&username); goto err;
return -1;
} }
free_w(&username);
if(grp) if(grp)
{ {
if(gid!=getgid() // do not do it if we already have the same gid if(gid!=getgid() // do not do it if we already have the same gid
&& setgid(gid)) && setgid(gid))
{ {
logp("could not set group '%s': %s\n", group, logp("could not set group '%s': %s\n", group,
strerror(errno)); strerror(errno));
return -1; goto err;
} }
} }
if(uid!=getuid() // do not do it if we already have the same uid if (readall)
{
#ifdef ENABLE_KEEP_READALL_CAPS_SUPPORT
cap_t caps;
// Make capabilities pass through setreuid
if(prctl(PR_SET_KEEPCAPS, 1))
{
logp("prctl(PR_SET_KEEPCAPS) failed: %s\n", strerror(errn
o));
goto err;
}
if(setreuid(uid, uid))
{
logp("Could not switch to user=%s (uid=%u): %s\n", userna
me, uid, strerror(errno));
goto err;
}
// `ep' is Effective and Permitted
caps=cap_from_text("cap_dac_read_search=ep");
if(!caps)
{
logp("cap_from_text() failed: %s\n", strerror(errno));
goto err;
}
if(cap_set_proc(caps) < 0)
{
logp("cap_set_proc() failed: %s\n", strerror(errno));
goto err;
}
cap_free(caps);
logp("Privileges switched to %s keeping readall capability.\n", u
sername);
#else
logp("Keep readall capabilities is not implemented on this platfo
rm yet\n");
goto err;
#endif
} else if(uid!=getuid() // do not do it if we already have the same uid
&& setuid(uid)) && setuid(uid))
{ {
logp("could not set specified user '%s': %s\n", username, logp("could not set specified user '%s': %s\n", username,
strerror(errno)); strerror(errno));
return -1; goto err;
} }
#endif
return 0; return 0;
err:
free_w(&username);
return -1;
#endif
} }
// Not in dpth.c so that Windows client can see it. // Not in dpth.c so that Windows client can see it.
int dpth_protocol1_is_compressed(int compressed, const char *datapath) int dpth_protocol1_is_compressed(int compressed, const char *datapath)
{ {
const char *dp=NULL; const char *dp=NULL;
if(compressed>0) return compressed; if(compressed>0) return compressed;
if(compressed==0) return 0; if(compressed==0) return 0;
 End of changes. 13 change blocks. 
14 lines changed or deleted 66 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)