Annotation of src/usr.bin/rsync/child.c, Revision 1.5
1.5 ! deraadt 1: /* $Id: child.c,v 1.4 2019/02/17 16:34:04 deraadt Exp $ */
1.1 benno 2: /*
3: * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
4: *
5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
8: *
9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16: */
17: #include <sys/stat.h>
18:
19: #include <assert.h>
20: #include <stdint.h>
21: #include <stdio.h>
22: #include <stdlib.h>
23: #include <string.h>
24: #include <unistd.h>
25:
26: #include "extern.h"
27:
28: /*
29: * This is run on the client machine to initiate a connection with the
30: * remote machine in --server mode.
31: * It does not return, as it executes into the remote shell.
32: *
33: * Pledges: exec, stdio.
34: */
35: void
36: rsync_child(const struct opts *opts, int fd, const struct fargs *f)
37: {
38: struct sess sess;
39: char **args;
40: size_t i;
41:
42: memset(&sess, 0, sizeof(struct sess));
43: sess.opts = opts;
44:
45: /* Construct the remote shell command. */
46:
1.3 deraadt 47: if ((args = fargs_cmdline(&sess, f)) == NULL) {
1.1 benno 48: ERRX1(&sess, "fargs_cmdline");
1.5 ! deraadt 49: exit(1);
1.1 benno 50: }
51:
1.4 deraadt 52: for (i = 0; args[i] != NULL; i++)
1.1 benno 53: LOG2(&sess, "exec[%zu] = %s", i, args[i]);
54:
55: /* Make sure the child's stdin is from the sender. */
56:
1.3 deraadt 57: if (dup2(fd, STDIN_FILENO) == -1) {
1.1 benno 58: ERR(&sess, "dup2");
1.5 ! deraadt 59: exit(1);
1.3 deraadt 60: } if (dup2(fd, STDOUT_FILENO) == -1) {
1.1 benno 61: ERR(&sess, "dup2");
1.5 ! deraadt 62: exit(1);
1.1 benno 63: }
64:
65: /* Here we go... */
66:
67: execvp(args[0], args);
68:
69: ERR(&sess, "%s: execvp", args[0]);
1.5 ! deraadt 70: exit(1);
1.1 benno 71: /* NOTREACHED */
72: }