Author: juhliarik Date: Wed May 30 17:24:48 2007 New Revision: 38209 URL: http://svn.opensuse.org/viewcvs/yast?rev=38209&view=rev Log: add patch for uploading anonymous user in vsftpd (create upload dir) Modified: trunk/ftp-server/config/ftp-server.rnc trunk/ftp-server/src/FtpServer.ycp trunk/ftp-server/src/helps.ycp trunk/ftp-server/src/uiforms.ycp trunk/ftp-server/src/wid_functions.ycp trunk/ftp-server/src/write_load.ycp Modified: trunk/ftp-server/config/ftp-server.rnc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ftp-server/config/ftp-server.rnc?rev=38209&r1=38208&r2=38209&view=diff ============================================================================== --- trunk/ftp-server/config/ftp-server.rnc (original) +++ trunk/ftp-server/config/ftp-server.rnc Wed May 30 17:24:48 2007 @@ -23,7 +23,6 @@ element AnonCreatDirs { text }? & element Banner { text }? & element SSLEnable { text }? & - element SSLVersion { text }? & element TLS { text }? & element AntiWarez { text }? & element SSL { text }? & Modified: trunk/ftp-server/src/FtpServer.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ftp-server/src/FtpServer.ycp?rev=38209&r1=38208&r2=38209&view=diff ============================================================================== --- trunk/ftp-server/src/FtpServer.ycp (original) +++ trunk/ftp-server/src/FtpServer.ycp Wed May 30 17:24:48 2007 @@ -96,6 +96,24 @@ global boolean start_xinetd = false; /** + * variable signifies if it is create upload dir + * only for vsftpd and anonymous connections with allowed upload + * + * global boolean variable + */ + +global boolean create_upload_dir = false; + +/** + * variable signifies if upload dir has good permissions + * only for vsftpd and anonymous connections with allowed upload + * + * global boolean variable + */ + +global boolean upload_good_permission = false; + +/** * variable signifies home dir for anonymous user * * global string variable @@ -252,6 +270,48 @@ return true; } + +/** + * Read vsftpd configuration + * existing upload file and permissions + * + * @return boolean successfull + */ + + +boolean ReadVSFTPDUpload () { + boolean result = false; + string command = ""; + if (anon_homedir !="") + command = "ls -l "+anon_homedir+ " | grep upload"; + if (command != "") { + map options = (map)SCR::Execute (.target.bash_output, command); + y2milestone("[ftp-server] (ReadVSFTPDUpload) command for existing upload dir: %1 output: %2",command, options); + if (options["exit"]:nil == 0) + result = true; + else + result = false; + if (result) { + //Popup::Message("Work ReadVSFTPDUpload"); + create_upload_dir = true; + string permissions = substring (tostring(options["stdout"]:nil),0,10); + string w = filterchars (permissions, "w"); + string r = filterchars (permissions, "r"); + if ((size(w) <3) || (size(r) <3)) { + upload_good_permission = false; + //Popup::Message("good permissions"); + } else { + upload_good_permission = true; + //Popup::Message("wrong permissions"); + } + } + } + return result; +} + + + + /** * Remap current pure -FtpServer configuration * to temporary structure @@ -295,7 +355,7 @@ if ((Users::Read () == "") && (EDIT_SETTINGS["VirtualUser"]:nil == "NO")) { if ((vsftpd_edit) && (EDIT_SETTINGS["GuestUser"]:nil != "") && (EDIT_SETTINGS["FtpDirLocal"]:nil == "")) { - Popup::Message("if ((vsftpd_edit) && (EDIT_SETTINGS"); + //Popup::Message("if ((vsftpd_edit) && (EDIT_SETTINGS"); Users::SelectUserByName (EDIT_SETTINGS["GuestUser"]:nil); userinfo = Users::GetCurrentUser (); string guest_home_dir = (string) userinfo["homedirectory"]:nil; @@ -319,9 +379,10 @@ boolean progress_orig = Progress::set (false); SuSEFirewall::Read (); Progress::set (progress_orig); - - - + //read existing upload directory for vsftpd + if (vsftpd_edit) { + result = ReadVSFTPDUpload (); + } return result; } @@ -505,7 +566,49 @@ return result; } +/** + * Ask for creation upload directory + * It is necessary if user want to allow uploading for anonymous + * @return boolean result of function (true/false) + */ +boolean WriteUpload () { + boolean result = true; + string command =""; + integer authentication = tointeger(EDIT_SETTINGS["AnonAuthen"]:nil); + if ((vsftpd_edit) && (authentication == 0) && (create_upload_dir) && (upload_good_permission)) { + boolean write_enable = ((EDIT_SETTINGS["EnableUpload"]:nil == "YES") ? true:false); + boolean anon_upload = ((EDIT_SETTINGS["AnonReadOnly"]:nil == "NO") ? true:false); + boolean anon_create_dirs = ((EDIT_SETTINGS["AnonCreatDirs"]:nil == "YES") ? true:false); + if ((write_enable) && ((anon_upload) || (anon_create_dirs))) + command = "dir=`ls "; + command = command + anon_homedir; + command = command + " | grep upload`; if [ -z $dir ]; then mkdir "; + command = command + anon_homedir +"upload; chown "; + + if (EDIT_SETTINGS["GuestUser"]:nil !="") + command = command + EDIT_SETTINGS["GuestUser"]:nil +":"+EDIT_SETTINGS["GuestUser"]:nil; + else if (EDIT_SETTINGS["FTPUser"]:nil !="") + command = command + EDIT_SETTINGS["FTPUser"]:nil +":"+EDIT_SETTINGS["FTPUser"]:nil; + command = command + " " + anon_homedir +"upload; chmod 766 "; + command = command + anon_homedir +"upload; else chmod 766 " + anon_homedir +"upload; fi"; +/* +"dir=`ls /srv/ftp/ | grep upload`; if [ -z $dir ]; then echo $dir; mkdir /srv/ftp/upload; + chown ftp:ftp /srv/ftp/upload/; chmod 755 /srv/ftp/upload; else chmod 766 /srv/ftp/upload/; fi" +*/ + y2milestone("[ftp-server] (WriteUpload) bash command for creating upload dir : %1", command); + map options = (map)SCR::Execute (.target.bash_output, command); + if (options["exit"]:nil == 0) + result = true; + else + result = false; + //Popup::Message(command); + + } else { + result = true; + } + return result; +} /** * read value from PURE_EDIT_SETTINGS * @@ -667,7 +770,7 @@ /* FtpServer read dialog caption */ string caption = _("Saving FTP Configuration"); - integer steps = 2; + integer steps = 3; // We do not set help text here, because it was set outside Progress::New(caption, " ", @@ -697,6 +800,13 @@ if (!WriteXinetd ()) Report::Error (_("Cannot write settings for xinetd!")); sleep(sl); + if (PollAbort()) return false; + Progress::NextStage (); + // write settings for starting daemon + if (!WriteUpload ()) Report::Error (_("Cannot create upload direcotry for anonymous connections!")); + sleep(sl); + + if(PollAbort()) return false; /* Progress finished */ Progress::NextStage(); @@ -858,7 +968,6 @@ * @return table items */ global list Overview() { - // TODO FIXME: your code here... return []; } Modified: trunk/ftp-server/src/helps.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ftp-server/src/helps.ycp?rev=38209&r1=38208&r2=38209&view=diff ============================================================================== --- trunk/ftp-server/src/helps.ycp (original) +++ trunk/ftp-server/src/helps.ycp Wed May 30 17:24:48 2007 @@ -146,14 +146,26 @@ /* anonymous settings anonymous can't upload dialog help 5/6 */ _("<p><b>Anonymous Can Upload</b><br> -If enabled anonymous users will be permitted to upload.</p> +If enabled anonymous users will be permitted to upload. +<i>vsftpd only: </i>If you want that anonymous users can upload you +need existing directory with allowed writing in home directory after login.</p> ")+ /* anonymous settings anonymous can create dirs dialog help 6/6 */ _("<p><b>Anonymous Can Create Dirs</b><br> -If enabled anonymous users can create directories.</p> +If enabled anonymous users can create directories. +<i>vsftpd only: </i>If you want that anonymous users can create directories you +need existing directory with allowed writing in home directory after login.</p> +")+ + +/* anonymous settings anonymous can create dirs dialog help 6/6 */ +_("<p><b>Enable Upload <i>(vsftpd only)</i></b><br> +If enable ftp users can upload. Anonymous users need to allow + \"Anonymous Can Upload\" for enabling upload.</p> "), + + /* expert settings dialog help 1/6 */ "vsftpd_settings" : _("<p><b><big>Expert Settings</b><br> Expert settings - security and firewall settings.</p> Modified: trunk/ftp-server/src/uiforms.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ftp-server/src/uiforms.ycp?rev=38209&r1=38208&r2=38209&view=diff ============================================================================== --- trunk/ftp-server/src/uiforms.ycp (original) +++ trunk/ftp-server/src/uiforms.ycp Wed May 30 17:24:48 2007 @@ -116,8 +116,8 @@ `HBox(`HSpacing(1),`VBox ( `Left(`CheckBox (`id("EnableUpload"), `opt(`notify), _("&Enable Upload"))), `HBox(`HSpacing(2),`VBox( - `Left(`CheckBox (`id("AnonReadOnly"), _("Anon&ymous Can Upload"))), - `Left(`CheckBox (`id("AnonCreatDirs"), _("Anonymou&s Can Create Directories"))) + `Left(`CheckBox (`id("AnonReadOnly"), `opt(`notify), _("Anon&ymous Can Upload"))), + `Left(`CheckBox (`id("AnonCreatDirs"),`opt(`notify), _("Anonymou&s Can Create Directories"))) )) )) ), //end of `Frame ( _("Anonymous Settings") Modified: trunk/ftp-server/src/wid_functions.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ftp-server/src/wid_functions.ycp?rev=38209&r1=38208&r2=38209&view=diff ============================================================================== --- trunk/ftp-server/src/wid_functions.ycp (original) +++ trunk/ftp-server/src/wid_functions.ycp Wed May 30 17:24:48 2007 @@ -25,6 +25,15 @@ include "ftp-server/uiforms.ycp"; + +/** + * variable signifies repeat asking about upload file + * only for vsftpd + * + * internal boolean variable + */ +boolean ask_again = true; + /** * CWMServiceStart function with no parameter returning boolean value * that says if the service is started. @@ -342,6 +351,7 @@ FtpServer::WriteToEditMap("AnonReadOnly", (((boolean) UI::QueryWidget(`id("AnonReadOnly"), `Value) == true) ? "NO":"YES")); if (FtpServer::vsftpd_edit) FtpServer::WriteToEditMap("EnableUpload", (((boolean) UI::QueryWidget(`id("EnableUpload"), `Value) == true) ? "YES":"NO")); + } /** @@ -352,8 +362,12 @@ symbol HandleAnonSettings(string key, map event) { if (FtpServer::vsftpd_edit) { any button = event["ID"]:nil; - if (button == "EnableUpload") { - boolean check_upload = (boolean) UI::QueryWidget(`id("EnableUpload"), `Value); + boolean anon_upload = false; + boolean anon_create_dirs = false; + string yesno_comment =""; + string yesno_question =""; + boolean check_upload = (boolean) UI::QueryWidget(`id("EnableUpload"), `Value); + if (button == "EnableUpload") { if (check_upload) { UI::ChangeWidget(`id("AnonReadOnly"), `Enabled, true); UI::ChangeWidget(`id( "AnonCreatDirs" ),`Enabled, true); @@ -362,6 +376,44 @@ UI::ChangeWidget(`id( "AnonCreatDirs" ),`Enabled, false); } } // end of if (button == "EnableUpload") { + + anon_upload = (boolean) UI::QueryWidget(`id("AnonReadOnly"), `Value); + anon_create_dirs = (boolean) UI::QueryWidget(`id("AnonCreatDirs"), `Value); + + if (((button == "AnonReadOnly") || (anon_upload) && (check_upload)) && (ask_again)) { + if (!FtpServer::create_upload_dir) { + yesno_question ="Do you want to create directory\n" + FtpServer::anon_homedir +"upload with allowed writing?"; + yesno_comment = "If you want that \"anonymous\" users can upload\n you need to create directory with allowed writing.\n\n"; + yesno_comment = yesno_comment + FtpServer::anon_homedir + " is a home directory after login of \"anonymous\" users."; + FtpServer::create_upload_dir = Popup::YesNoHeadline(yesno_question, yesno_comment); + ask_again = FtpServer::create_upload_dir; + FtpServer::upload_good_permission = true; + } else if (!FtpServer::upload_good_permission) { + yesno_question ="Do you want to change permission\nfor" + FtpServer::anon_homedir +"upload (allow writing)?"; + yesno_comment = "If you want that \"anonymous\" users can upload\n you need directory with allowed writing.\n\n"; + yesno_comment = yesno_comment + FtpServer::anon_homedir + " is a home directory after login of \"anonymous\" users."; + FtpServer::upload_good_permission = Popup::YesNoHeadline(yesno_question, yesno_comment); + ask_again = FtpServer::upload_good_permission; + } + + } + + if (((button == "AnonCreatDirs") || (anon_create_dirs) && (check_upload)) && (ask_again)) { + if (!FtpServer::create_upload_dir) { + yesno_question ="Do you want to create directory\n" + FtpServer::anon_homedir +"upload with allowed writing?"; + yesno_comment = "If you want that \"anonymous\" users can create directories\n you need to create directory with allowed writing.\n\n"; + yesno_comment = yesno_comment + FtpServer::anon_homedir + " is a home directory after login of \"anonymous\" users."; + FtpServer::create_upload_dir = Popup::YesNoHeadline(yesno_question, yesno_comment); + ask_again = FtpServer::create_upload_dir; + FtpServer::upload_good_permission = true; + } else if (!FtpServer::upload_good_permission) { + yesno_question ="Do you want to change permission\nfor" + FtpServer::anon_homedir +"upload (allow writing)?"; + yesno_comment = "If you want that \"anonymous\" users can create directories\n you need directory with allowed writing.\n\n"; + yesno_comment = yesno_comment + FtpServer::anon_homedir + " is a home directory after login of \"anonymous\" users."; + FtpServer::upload_good_permission = Popup::YesNoHeadline(yesno_question, yesno_comment); + ask_again = FtpServer::upload_good_permission; + } + } } // end of if (FtpServer::vsftpd_edit) { } Modified: trunk/ftp-server/src/write_load.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ftp-server/src/write_load.ycp?rev=38209&r1=38208&r2=38209&view=diff ============================================================================== --- trunk/ftp-server/src/write_load.ycp (original) +++ trunk/ftp-server/src/write_load.ycp Wed May 30 17:24:48 2007 @@ -705,10 +705,8 @@ yes_no = FtpServer::EDIT_SETTINGS["AnonReadOnly"]:nil; if (yes_no == "YES") { FtpServer::VS_SETTINGS["anon_upload_enable"] = "NO"; - FtpServer::VS_SETTINGS["write_enable"] = "NO"; } else { FtpServer::VS_SETTINGS["anon_upload_enable"] = "YES"; - FtpServer::VS_SETTINGS["write_enable"] = "YES"; } } else { if (haskey(FtpServer::VS_SETTINGS, "anon_upload_enable")) { @@ -731,15 +729,11 @@ case("AnonCreatDirs"): if (vsftpd_edit) { if (write) { - FtpServer::VS_SETTINGS["anon_mkdir_write_enable"] = FtpServer::EDIT_SETTINGS["AnonCreatDirs"]:nil; - if (FtpServer::EDIT_SETTINGS["AnonCreatDirs"]:nil == "YES") - FtpServer::VS_SETTINGS["write_enable"] = "YES"; + FtpServer::VS_SETTINGS["anon_mkdir_write_enable"] = FtpServer::EDIT_SETTINGS["AnonCreatDirs"]:nil; } else { return ((haskey(FtpServer::VS_SETTINGS, "anon_mkdir_write_enable") ? toupper(FtpServer::VS_SETTINGS["anon_mkdir_write_enable"]:nil) : FtpServer::DEFAULT_CONFIG["AnonCreatDirs"]:nil)); } - - } else { if (write) FtpServer::PURE_SETTINGS["AnonymousCanCreateDirs"] = FtpServer::EDIT_SETTINGS["AnonCreatDirs"]:nil; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org