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