xref: /openssh-portable/sftp-server-main.c (revision 0323d9b6)
1*0323d9b6Sotto@openbsd.org /* $OpenBSD: sftp-server-main.c,v 1.6 2019/06/06 05:13:13 otto Exp $ */
2d8cb1f18SDamien Miller /*
3d8cb1f18SDamien Miller  * Copyright (c) 2008 Markus Friedl.  All rights reserved.
4d8cb1f18SDamien Miller  *
5d8cb1f18SDamien Miller  * Permission to use, copy, modify, and distribute this software for any
6d8cb1f18SDamien Miller  * purpose with or without fee is hereby granted, provided that the above
7d8cb1f18SDamien Miller  * copyright notice and this permission notice appear in all copies.
8d8cb1f18SDamien Miller  *
9d8cb1f18SDamien Miller  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10d8cb1f18SDamien Miller  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11d8cb1f18SDamien Miller  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12d8cb1f18SDamien Miller  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13d8cb1f18SDamien Miller  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14d8cb1f18SDamien Miller  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15d8cb1f18SDamien Miller  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16d8cb1f18SDamien Miller  */
17d8cb1f18SDamien Miller 
18d8cb1f18SDamien Miller #include "includes.h"
19d8cb1f18SDamien Miller 
20d8cb1f18SDamien Miller #include <sys/types.h>
21d8cb1f18SDamien Miller #include <pwd.h>
22d8cb1f18SDamien Miller #include <stdarg.h>
23d8cb1f18SDamien Miller #include <stdio.h>
24d8cb1f18SDamien Miller #include <unistd.h>
25d8cb1f18SDamien Miller 
26d8cb1f18SDamien Miller #include "log.h"
27d8cb1f18SDamien Miller #include "sftp.h"
28d8cb1f18SDamien Miller #include "misc.h"
29ffb1e7e8Sdtucker@openbsd.org #include "xmalloc.h"
30d8cb1f18SDamien Miller 
31d8cb1f18SDamien Miller void
cleanup_exit(int i)32d8cb1f18SDamien Miller cleanup_exit(int i)
33d8cb1f18SDamien Miller {
34d8cb1f18SDamien Miller 	sftp_server_cleanup_exit(i);
35d8cb1f18SDamien Miller }
36d8cb1f18SDamien Miller 
37d8cb1f18SDamien Miller int
main(int argc,char ** argv)38d8cb1f18SDamien Miller main(int argc, char **argv)
39d8cb1f18SDamien Miller {
40d8cb1f18SDamien Miller 	struct passwd *user_pw;
41d8cb1f18SDamien Miller 
42d8cb1f18SDamien Miller 	/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
43d8cb1f18SDamien Miller 	sanitise_stdfd();
44d8cb1f18SDamien Miller 
4542c5ec4bSDamien Miller 	seed_rng();
4642c5ec4bSDamien Miller 
47d8cb1f18SDamien Miller 	if ((user_pw = getpwuid(getuid())) == NULL) {
489eab9564SDamien Miller 		fprintf(stderr, "No user found for uid %lu\n",
499eab9564SDamien Miller 		    (u_long)getuid());
50d8cb1f18SDamien Miller 		return 1;
51d8cb1f18SDamien Miller 	}
52d8cb1f18SDamien Miller 
53d8cb1f18SDamien Miller 	return (sftp_server_main(argc, argv, user_pw));
54d8cb1f18SDamien Miller }
55