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