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