ACC SHELL

Path : /usr/share/YaST2/clients/
File Upload :
Current File : //usr/share/YaST2/clients/samba-client.ycp

/**
 * File:	clients/samba-client.ycp
 * Package:	Configuration of samba-client
 * Summary:	Main file
 * Authors:	Stanislav Visnovsky <visnov@suse.cz>
 *
 * $Id: samba-client.ycp 46403 2008-04-11 12:19:56Z jsuchome $
 *
 * Main file for samba-client configuration. Uses all other files.
 */

{

/***
 * <h3>Configuration of the samba-client</h3>
 */

textdomain "samba-client";

import "CommandLine";
import "Popup";
import "Report";

import "Samba";
import "SambaAD";
import "SambaNetJoin";

/**
 * Enable or disable winbind service (high-level)
 *
 * @param options  a list of parameters passed as args
 * @return boolean true on success
 */
boolean WinbindEnableHandler( map<string,string> options ) {
    // check the "command" to be present exactly once
    string command = CommandLine::UniqueOption( options, 
	["enable", "disable" ] );
    if( command == nil ) return false;

    return Samba::SetWinbind( command == "enable" );
}

/**
 * Check domain membership.
 * 
 * @param options  a list of parameters passed as args
 * @return boolean true on success
 */
boolean DomainMemberHandler( map<string, any> options ) {

    string domain = (string) (options["domain"]:nil);
    
    // validate the options
    if( domain == nil ) {
	// user must provide the domain name to be tested
	// error message for isdomainmember command line action 
	Report::Error( sformat( _("Enter the name of a domain.") ) );
	return false;
    }

    SambaAD::ReadADS (domain);
    if (SambaAD::ADS () != "")
    {
	SambaAD::ReadRealm ();
    }
    
    boolean result = SambaNetJoin::Test(domain);
    if( result == nil ) {
	// translators: error message for isdomainmember command line action 
	Report::Error( _("Cannot test domain membership.") );
	return false;
    }
    
    if( result ) {
	// translators: result message for isdomainmember command line action 
	CommandLine::Print( sformat( _("This machine is a member of %1"), domain ) );
    } else {
	// translators: result message for isdomainmember command line action 
	CommandLine::Print( sformat( _("This machine is not a member of %1"), domain ) );
    }
    
    return true;
}

/**
 * Join a domain.
 * 
 * @param options  a list of parameters passed as args
 * @return boolean true on success
 */
boolean JoinDomainHandler( map <string, any> options ) {
    string domain = (string) (options["domain"]:nil);
    
    // validate the options
    if( domain == nil ) {
	// must provide the domain name to be joined
	// error message for joindomain command line action 
	Report::Error( sformat( _("Enter the name of a domain.") ) );
	return false;
    }

    SambaAD::ReadADS (domain);
    if (SambaAD::ADS () != "")
    {
	SambaAD::ReadRealm ();
    }
    
    string result = SambaNetJoin::Join(domain, "member", (string)(options["user"]:nil), (string) (options["password"]:""), (string) (options["machine"]:nil));
    if( result == nil ) {
	// translators: result message for joindomain command line action 
	CommandLine::Print( sformat( _("Domain %1 joined successfully."), domain ) );
	return true;
    } else {
	Report::Error( result );
	return false;
    }
}

/**
 * Change workgroup name.
 * 
 * @param options  a list of parameters passed as args
 * @return boolean true on success
 */
boolean ChangeConfiguration( map<string, any> options ) {
	
    string value = (string) (options["workgroup"]:nil);
    if( value != nil ) Samba::SetWorkgroup(value);

    return true;
}

// command line handler for writing
boolean SambaWrite () {

    return Samba::Write (true);
}

/* The main () */
y2milestone ("----------------------------------------");
y2milestone ("Samba-client module started");

include "samba-client/wizards.ycp";

/* main ui function */
any ret = nil;

/* the command line description map */
map cmdline = $[
    "id" 		: "samba-client",
    // translators: command line help text for Samba client module
    "help" 		: _("Samba client configuration module.
See Samba documentation for details."),
    "guihandler" 	: SambaClientSequence,
    "initialize"	: Samba::Read,
    "finish"		: SambaWrite,
    "actions"		: $[
	"winbind" :$[
	    "handler"	: WinbindEnableHandler,
	    // translators: command line help text for winbind action
	    "help"	: _("Enable or disable the Winbind services (winbindd)")
	],
	"isdomainmember": $[
	    "handler"	: DomainMemberHandler,
	    // translators: command line help text for isdomainmember action
	    "help"	: _("Check if this machine is a member of a domain")
	],
	"joindomain"	: $[
	    "handler"	: JoinDomainHandler,
	    // translators: command line help text for joindomain action
	    "help"	: _("Join this machine into a domain")
	],
	"configure"	: $[
	    "handler"	: ChangeConfiguration,
	    // translators: command line help text for configure action
	    "help"	: _("Change the global settings of Samba")
	]
    ],
    "options"		: $[
	"enable" 	:$[
	    // translators: command line help text for winbind enable option 
	    "help"	: _("Enable the service")
	],
	"disable"	:$[
	    // translators: command line help text for winbind disable option 
	    "help"	: _("Disable the service")
	],
	"domain"	:$[
	    // translators: command line help text for domain to be checked/joined 
	    "help"	: _("The name of a domain to join"),
	    "type"	: "string"
	],
	"user"		:$[
	    // translators: command line help text for joindomain user option 
	    "help"	: _("The user used for joining the domain. If omitted, YaST2 will
try to join the domain without specifying user and password."),
	    "type"	: "string"
	],
	"password"	:$[
	    // translators: command line help text for joindomain password option 
	    "help"	: _("The password used for the user when joining the domain"),
	    "type"	: "string"
	],
	"machine"	:$[
	    // command line help text for machine optioa
	    "help"	: _("The machine account"),
	    "type"	: "string"
	],
	"workgroup"	:$[
	    // translators: command line help text for the workgroup name option 
	    "help"	: _("The name of a workgroup"),
	    "type"	: "string"
	], 
    ],
    "mappings"		: $[
	"winbind" 	: [ "enable", "disable" ],
	"isdomainmember": [ "domain" ],
	"joindomain"	: [ "domain", "user", "password", "machine" ],
	"configure"	: [ "workgroup" ]
    ]
];

ret = CommandLine::Run( cmdline );

y2debug("ret=%1", ret);

/* Finish */
y2milestone("Samba-client module finished");
y2milestone("----------------------------------------");

return ret;

/* EOF */
}

ACC SHELL 2018