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