1*eedc3e89Sotto /* $OpenBSD: sftp-server-main.c,v 1.6 2019/06/06 05:13:13 otto Exp $ */
21f9f2765Smarkus /*
31f9f2765Smarkus * Copyright (c) 2008 Markus Friedl. All rights reserved.
41f9f2765Smarkus *
51f9f2765Smarkus * Permission to use, copy, modify, and distribute this software for any
61f9f2765Smarkus * purpose with or without fee is hereby granted, provided that the above
71f9f2765Smarkus * copyright notice and this permission notice appear in all copies.
81f9f2765Smarkus *
91f9f2765Smarkus * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
101f9f2765Smarkus * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
111f9f2765Smarkus * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
121f9f2765Smarkus * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
131f9f2765Smarkus * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
141f9f2765Smarkus * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
151f9f2765Smarkus * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
161f9f2765Smarkus */
171f9f2765Smarkus
181f9f2765Smarkus #include <sys/types.h>
19d5a37c29Sdjm #include <pwd.h>
201f9f2765Smarkus #include <stdarg.h>
21d5a37c29Sdjm #include <stdio.h>
22d5a37c29Sdjm #include <unistd.h>
231f9f2765Smarkus
241f9f2765Smarkus #include "log.h"
251f9f2765Smarkus #include "sftp.h"
26d5a37c29Sdjm #include "misc.h"
27e2395bfaSdtucker #include "xmalloc.h"
281f9f2765Smarkus
291f9f2765Smarkus void
cleanup_exit(int i)301f9f2765Smarkus cleanup_exit(int i)
311f9f2765Smarkus {
321f9f2765Smarkus sftp_server_cleanup_exit(i);
331f9f2765Smarkus }
341f9f2765Smarkus
351f9f2765Smarkus int
main(int argc,char ** argv)361f9f2765Smarkus main(int argc, char **argv)
371f9f2765Smarkus {
38d5a37c29Sdjm struct passwd *user_pw;
39d5a37c29Sdjm
40d5a37c29Sdjm /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
41d5a37c29Sdjm sanitise_stdfd();
42d5a37c29Sdjm
43d5a37c29Sdjm if ((user_pw = getpwuid(getuid())) == NULL) {
44a2e8fbe2Stobias fprintf(stderr, "No user found for uid %lu\n",
45a2e8fbe2Stobias (u_long)getuid());
46d5a37c29Sdjm return 1;
47d5a37c29Sdjm }
48d5a37c29Sdjm
49d5a37c29Sdjm return (sftp_server_main(argc, argv, user_pw));
501f9f2765Smarkus }
51