-
Notifications
You must be signed in to change notification settings - Fork 73
/
rsync-wrapper.c
64 lines (49 loc) · 1.57 KB
/
rsync-wrapper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <strings.h>
/********************************************
* Wrapper - Secure Yourself
*
* 2007 - Mike Golvach - [email protected]
* Modified 2012 by Jason Antman <[email protected]> <http://www.jasonantman.com>
* - configured for use as rsync wrapper
*
* The latest version of this script can be found at:
* <https://github.com/jantman/misc-scripts/blob/master/rsync-wrapper.c>
*
********************************************/
/* Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License */
/* Define global variables */
int gid;
/* main(int argc, char **argv) - main process loop */
int main(int argc, char **argv)
{
/* Set euid and egid to actual user */
gid = getgid();
setegid(getgid());
seteuid(getuid());
/* Confirm user is in GROUP(502) group */
if ( gid != 502 ) {
printf("User Not Authorized! Exiting...\n");
exit(1);
}
/* Check argc count only at this point */
if ( argc != 1 ) {
printf("Usage: rsync-wrapper\n");
exit(1);
}
/* Set uid, gid, euid and egid to root */
setegid(0);
seteuid(0);
setgid(0);
setuid(0);
/* Check argv for proper arguments and run
* the corresponding script, if invoked.
*/
if (execl("/usr/bin/rsync", "rsync", "--server", "--sender", "-vlogDtprRe.iLsf", "--numeric-ids", ".", "/", NULL) < 0) {
perror("Execl:");
}
exit(0);
}