Home |
Function ftp_server_set_auth Function cb_ftp_check_user_name_fnc |
Function ftp_server_set_authThis function defines users and their file access rights when logged in to the FTP server. typedef struct _FTPPathInfo { unsigned int Access; const char * Path; } FTPPathInfo; typedef struct _FTPUserInfo { const char * UserName; const char * Password; const FTPPathInfo * Pathes; // open array, 0 terminated const char * InitialDir; // optional } FTPUserInfo; void ftp_server_set_auth(const FTPUserInfo * UserList, int UserCount); ParametersUserListPointer to an array of FTPUserInfo structures defining user credentials, file access rights, and a user's initial directory. UserCountNumber of elements in the array pointed to by parameter UserList. The function tells the FTP server which users may log in to the FTP server and what file I/O permissions they have, respectively. If this function is never called, all users have unrestricted read/write access to all files, system files are, and hidden files are not listed. The InitialDir is optional and can be used to override the CFG_FTP_ROOT_DIR configuration parameter on a per-user basis. If NULL, CFG_FTP_ROOT_DIR is used instead. For each group of users sharing the same access rights, a NUL-terminated array of FTPPathInfo structures must be set up. Each element of the array defines a partial file name or path name and associated access rights. Before the FTP server opens a file, it will search the list for a path specification contained (not case sensitive) in the full path name of the file to be opened. The access rights associated with the first matching path is applied. If no match is found, access to the file is denied. Example:const FTPPathInfo SuperUsers[] = { { FTP_ACCESS_READ|FTP_ACCESS_WRITE|FTP_ACCESS_HIDDEN, "" }, {0} }; const FTPPathInfo Users[] = { { FTP_ACCESS_READ|FTP_ACCESS_WRITE, "C:\\Test" }, { FTP_ACCESS_NONE, "C:\\Config" }, { FTP_ACCESS_READ, "C:\\" }, {0} }; const FTPPathInfo Anyone[] = { { FTP_ACCESS_READ|FTP_DENY_SYSTEM, "C:\\Test" }, {0} }; An empty string ("") is contained in any string, so a path specification of "" matches any file or path name. In the example above, user group SuperUser defines just one FTPPathInfo (an empty string) with access rights FTP_ACCESS_READ | FTP_ACCESS_WRITE | FTP_ACCESS_HIDDEN. Thus, read and write access is granted to all files for all users which are a member of this group and all hidden files are displayed. Group Users grants read/write access to just one directory, no access to another directory, and read-only for the rest of drive C:. Since no other drives are given, Users have no access to drive D:, for example. Note that the order of entries is important: the third path is a substring of the second. If these two entries were swapped, the third path would never match. For group Anyone, only read-only access is defined for one directory tree. Access to all other files and listing system files is denied. User groups must be populated with users using an array of structure FTPUserInfo: Example:const FTPUserInfo UserList[] = { { "root", "secret", SuperUsers }, { "harry", "xyz", Users }, { "joe", "zyx", Users }, { "guest", "", Anyone, "C:\\Test" } }; For each user, his login name and password (both are case-sensitive) and the user group defined above are given. Please note that an empty password will match any password the user enters. The user information is applied by calling ftp_server_set_auth before ftp_server_daemon: int main(void) { int Result; // get the right date and time RTCMOSSetSystemTime(); // initialize the TCP/IP stack NetInitialize(); // initialize RTIP-32 virtual file system vf_init(); // define FTP site initial directory (trailing backslash required) CFG_FTP_ROOT_DIR = "C:\\"; // tell the server what users we have ftp_server_set_auth(UserList, sizeof(UserList) / sizeof(UserList[0])); // execute the FTP server Result = ftp_server_daemon(); if (Result) Error("ft_server_daemon failed"); return 0; }
|