5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2001 - 2007 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
23 typedef struct ServerSessionStruct {
29 SilcSchedule schedule;
30 SilcNetListener listener;
31 SilcSFTPFilesystem fs;
34 static void error_cb(SilcSFTP sftp, SilcSFTPStatus status, void *context)
36 ServerSession session = context;
38 if (status == SILC_SFTP_STATUS_EOF) {
39 SILC_LOG_DEBUG(("Eof"));
40 silc_stream_destroy(session->stream);
44 SILC_LOG_DEBUG(("Error %d", status));
47 static void net_callback(SilcNetStatus status, SilcStream stream,
50 Server server = context;
51 ServerSession session;
53 SILC_LOG_DEBUG(("New connection"));
55 session = silc_calloc(1, sizeof(*session));
58 session->stream = stream;
59 session->sftp = silc_sftp_server_start(stream, server->schedule, error_cb,
66 Server server = silc_calloc(1, sizeof(*server));
68 const char *ip = "127.0.0.1";
71 silc_log_debug_hexdump(TRUE);
72 silc_log_set_debug_string("*sftp*");
74 server->schedule = silc_schedule_init(0, NULL);
75 if (!server->schedule)
78 server->listener = silc_net_tcp_create_listener(&ip, 1, 5000, FALSE,
79 FALSE, server->schedule,
80 net_callback, server);
81 if (!server->listener)
84 /* Make test filesystem hierarchy */
86 server->fs = silc_sftp_fs_memory_alloc((SILC_SFTP_FS_PERM_READ |
87 SILC_SFTP_FS_PERM_WRITE));
89 silc_sftp_fs_memory_add_dir(server->fs, NULL, (SILC_SFTP_FS_PERM_READ |
90 SILC_SFTP_FS_PERM_WRITE |
91 SILC_SFTP_FS_PERM_EXEC),
93 silc_sftp_fs_memory_add_file(server->fs, NULL, SILC_SFTP_FS_PERM_READ,
94 "passwd", "file:///etc/passwd");
95 silc_sftp_fs_memory_add_file(server->fs, NULL, (SILC_SFTP_FS_PERM_READ |
96 SILC_SFTP_FS_PERM_WRITE),
97 "writeme", "file://./writeme-test");
98 silc_sftp_fs_memory_add_file(server->fs, dir, SILC_SFTP_FS_PERM_READ,
99 "shadow", "file:///etc/shadow");
100 silc_sftp_fs_memory_add_file(server->fs, dir, SILC_SFTP_FS_PERM_READ,
101 "sftp_server.c", "file://sftp_server.c");
102 silc_sftp_fs_memory_add_dir(server->fs, dir, (SILC_SFTP_FS_PERM_READ |
103 SILC_SFTP_FS_PERM_WRITE |
104 SILC_SFTP_FS_PERM_EXEC),
106 silc_sftp_fs_memory_add_file(server->fs, NULL, SILC_SFTP_FS_PERM_EXEC,
107 "testi", "file://sftp_client.c");
109 silc_schedule(server->schedule);