1998-03-08 17:14:49 +03:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
1998-03-14 15:57:58 +03:00
Samba Web Administration Tool
2002-09-25 19:19:00 +04:00
Version 3.0 .0
Copyright ( C ) Andrew Tridgell 1997 - 2002
Copyright ( C ) John H Terpstra 2002
2009-11-30 00:23:22 +03:00
1998-03-08 17:14:49 +03:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
1998-03-08 17:14:49 +03:00
( at your option ) any later version .
2009-11-30 00:23:22 +03:00
1998-03-08 17:14:49 +03:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2009-11-30 00:23:22 +03:00
1998-03-08 17:14:49 +03:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1998-03-08 17:14:49 +03:00
*/
2001-11-19 05:49:53 +03:00
/**
2003-03-18 01:33:34 +03:00
* @ defgroup swat SWAT - Samba Web Administration Tool
2001-11-19 05:49:53 +03:00
* @ {
* @ file swat . c
*
* @ brief Samba Web Administration Tool .
* */
1998-03-08 17:14:49 +03:00
# include "includes.h"
2010-08-05 12:49:53 +04:00
# include "popt_common.h"
2004-10-07 08:01:18 +04:00
# include "web/swat_proto.h"
2010-12-23 14:14:21 +03:00
# include "printing/pcap.h"
1998-03-08 17:14:49 +03:00
2007-10-19 22:38:36 +04:00
static int demo_mode = False ;
static int passwd_only = False ;
2007-10-19 04:40:25 +04:00
static bool have_write_access = False ;
static bool have_read_access = False ;
1999-12-13 16:27:58 +03:00
static int iNumNonAutoPrintServices = 0 ;
1998-03-08 17:14:49 +03:00
1998-11-12 00:37:44 +03:00
/*
* Password Management Globals
*/
1998-11-14 00:41:01 +03:00
# define SWAT_USER "username"
1998-11-12 10:06:48 +03:00
# define OLD_PSWD "old_passwd"
# define NEW_PSWD "new_passwd"
# define NEW2_PSWD "new2_passwd"
1998-11-12 21:44:16 +03:00
# define CHG_S_PASSWD_FLAG "chg_s_passwd_flag"
# define CHG_R_PASSWD_FLAG "chg_r_passwd_flag"
1998-11-12 10:06:48 +03:00
# define ADD_USER_FLAG "add_user_flag"
2000-02-26 01:25:25 +03:00
# define DELETE_USER_FLAG "delete_user_flag"
1998-11-12 10:06:48 +03:00
# define DISABLE_USER_FLAG "disable_user_flag"
# define ENABLE_USER_FLAG "enable_user_flag"
1998-11-12 21:44:16 +03:00
# define RHOST "remote_host"
1998-03-08 17:14:49 +03:00
2007-12-04 04:17:05 +03:00
# define _(x) lang_msg_rotate(talloc_tos(),x)
2004-02-02 03:08:35 +03:00
1998-11-12 00:37:44 +03:00
/****************************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-01-03 11:28:12 +03:00
static int enum_index ( int value , const struct enum_list * enumlist )
1998-05-08 05:45:12 +04:00
{
2000-09-13 11:08:09 +04:00
int i ;
1998-05-08 05:45:12 +04:00
for ( i = 0 ; enumlist [ i ] . name ; i + + )
if ( value = = enumlist [ i ] . value ) break ;
return ( i ) ;
}
2003-01-03 11:28:12 +03:00
static char * fix_backslash ( const char * str )
1998-05-08 05:45:12 +04:00
{
2000-09-13 11:08:09 +04:00
static char newstring [ 1024 ] ;
char * p = newstring ;
1998-05-08 05:45:12 +04:00
1998-05-08 20:59:30 +04:00
while ( * str ) {
if ( * str = = ' \\ ' ) { * p + + = ' \\ ' ; * p + + = ' \\ ' ; }
else * p + + = * str ;
+ + str ;
1998-05-08 05:45:12 +04:00
}
1998-11-11 04:54:31 +03:00
* p = ' \0 ' ;
return newstring ;
}
2007-12-04 04:17:05 +03:00
static const char * fix_quotes ( TALLOC_CTX * ctx , const char * str )
2005-05-24 21:33:47 +04:00
{
2007-12-04 04:17:05 +03:00
char * newstring = NULL ;
char * p = NULL ;
size_t newstring_len ;
2005-05-24 21:33:47 +04:00
int quote_len = strlen ( " " " ) ;
2007-12-04 04:17:05 +03:00
/* Count the number of quotes. */
newstring_len = 1 ;
2008-06-03 17:26:42 +04:00
p = ( char * ) str ;
while ( * p ) {
if ( * p = = ' \" ' ) {
2007-12-04 04:17:05 +03:00
newstring_len + = quote_len ;
} else {
newstring_len + + ;
}
2008-06-03 17:26:42 +04:00
+ + p ;
2007-12-04 04:17:05 +03:00
}
newstring = TALLOC_ARRAY ( ctx , char , newstring_len ) ;
if ( ! newstring ) {
return " " ;
}
for ( p = newstring ; * str ; str + + ) {
if ( * str = = ' \" ' ) {
strncpy ( p , " " " , quote_len ) ;
2005-05-24 21:37:04 +04:00
p + = quote_len ;
2005-05-24 21:33:47 +04:00
} else {
* p + + = * str ;
}
}
* p = ' \0 ' ;
return newstring ;
}
2003-01-03 11:28:12 +03:00
static char * stripspaceupper ( const char * str )
1998-11-11 04:54:31 +03:00
{
2002-08-17 18:34:48 +04:00
static char newstring [ 1024 ] ;
char * p = newstring ;
1998-11-11 04:54:31 +03:00
2002-08-17 18:34:48 +04:00
while ( * str ) {
2005-12-27 23:52:36 +03:00
if ( * str ! = ' ' ) * p + + = toupper_ascii ( * str ) ;
2002-08-17 18:34:48 +04:00
+ + str ;
}
1998-11-11 04:54:31 +03:00
* p = ' \0 ' ;
1998-05-08 05:45:12 +04:00
return newstring ;
}
2003-01-03 11:28:12 +03:00
static char * make_parm_name ( const char * label )
1998-05-08 05:45:12 +04:00
{
1998-11-12 10:06:48 +03:00
static char parmname [ 1024 ] ;
char * p = parmname ;
1998-05-08 05:45:12 +04:00
while ( * label ) {
if ( * label = = ' ' ) * p + + = ' _ ' ;
else * p + + = * label ;
+ + label ;
}
1998-11-11 04:54:31 +03:00
* p = ' \0 ' ;
1998-05-08 05:45:12 +04:00
return parmname ;
}
1998-03-10 09:42:36 +03:00
1998-11-12 00:37:44 +03:00
/****************************************************************************
include a lump of html in a page
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-01-03 11:28:12 +03:00
static int include_html ( const char * fname )
1998-03-08 17:14:49 +03:00
{
2001-10-14 16:10:29 +04:00
int fd ;
1998-03-08 17:14:49 +03:00
char buf [ 1024 ] ;
int ret ;
2001-10-14 16:10:29 +04:00
fd = web_open ( fname , O_RDONLY , 0 ) ;
2001-09-24 19:55:09 +04:00
2001-10-14 16:10:29 +04:00
if ( fd = = - 1 ) {
2004-10-02 02:24:44 +04:00
printf ( _ ( " ERROR: Can't open %s " ) , fname ) ;
printf ( " \n " ) ;
1998-09-01 10:03:03 +04:00
return 0 ;
1998-03-08 17:14:49 +03:00
}
2001-10-14 16:10:29 +04:00
while ( ( ret = read ( fd , buf , sizeof ( buf ) ) ) > 0 ) {
2008-12-31 05:24:39 +03:00
if ( write ( 1 , buf , ret ) = = - 1 ) {
break ;
}
1998-03-08 17:14:49 +03:00
}
2001-10-14 16:10:29 +04:00
close ( fd ) ;
1998-09-01 10:03:03 +04:00
return 1 ;
}
1998-11-12 00:37:44 +03:00
/****************************************************************************
start the page with standard stuff
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-09-01 10:03:03 +04:00
static void print_header ( void )
{
if ( ! cgi_waspost ( ) ) {
2004-10-02 02:24:44 +04:00
printf ( " Expires: 0 \r \n " ) ;
1998-09-01 10:03:03 +04:00
}
2004-10-02 02:24:44 +04:00
printf ( " Content-type: text/html \r \n \r \n " ) ;
1998-09-01 10:03:03 +04:00
if ( ! include_html ( " include/header.html " ) ) {
2004-10-02 02:24:44 +04:00
printf ( " <!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 3.2//EN \" > \n " ) ;
printf ( " <HTML> \n <HEAD> \n <TITLE>Samba Web Administration Tool</TITLE> \n </HEAD> \n <BODY background= \" /swat/images/background.jpg \" > \n \n " ) ;
1998-09-01 10:03:03 +04:00
}
1998-03-08 17:14:49 +03:00
}
2001-09-24 19:55:09 +04:00
/* *******************************************************************
show parameter label with translated name in the following form
because showing original and translated label in one line looks
too long , and showing translated label only is unusable for
heavy users .
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HELP security [ combo box ] [ button ]
SECURITY
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
( capital words are translated by gettext . )
if no translation is available , then same form as original is
used .
" i18n_translated_parm " class is used to change the color of the
translated parameter with CSS .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-04 04:17:05 +03:00
static const char * get_parm_translated ( TALLOC_CTX * ctx ,
2001-09-24 19:55:09 +04:00
const char * pAnchor , const char * pHelp , const char * pLabel )
{
2007-12-04 04:17:05 +03:00
const char * pTranslated = _ ( pLabel ) ;
char * output ;
if ( strcmp ( pLabel , pTranslated ) ! = 0 ) {
output = talloc_asprintf ( ctx ,
2005-12-20 05:23:51 +03:00
" <A HREF= \" /swat/help/manpages/smb.conf.5.html#%s \" target= \" docs \" > %s</A> %s <br><span class= \" i18n_translated_parm \" >%s</span> " ,
2001-09-24 19:55:09 +04:00
pAnchor , pHelp , pLabel , pTranslated ) ;
return output ;
}
2007-12-04 04:17:05 +03:00
output = talloc_asprintf ( ctx ,
2005-12-20 05:23:51 +03:00
" <A HREF= \" /swat/help/manpages/smb.conf.5.html#%s \" target= \" docs \" > %s</A> %s " ,
2001-09-24 19:55:09 +04:00
pAnchor , pHelp , pLabel ) ;
return output ;
}
1998-11-12 00:37:44 +03:00
/****************************************************************************
2007-12-04 04:17:05 +03:00
finish off the page
1998-11-12 00:37:44 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-09-01 10:03:03 +04:00
static void print_footer ( void )
{
if ( ! include_html ( " include/footer.html " ) ) {
2004-10-02 02:24:44 +04:00
printf ( " \n </BODY> \n </HTML> \n " ) ;
1998-09-01 10:03:03 +04:00
}
}
1998-11-12 00:37:44 +03:00
/****************************************************************************
2007-12-04 04:17:05 +03:00
display one editable parameter in a form
1998-11-12 00:37:44 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-03-08 17:14:49 +03:00
static void show_parameter ( int snum , struct parm_struct * parm )
{
int i ;
void * ptr = parm - > ptr ;
2004-12-26 21:51:49 +03:00
char * utf8_s1 , * utf8_s2 ;
2008-04-30 01:36:24 +04:00
size_t converted_size ;
2007-12-04 04:17:05 +03:00
TALLOC_CTX * ctx = talloc_stackframe ( ) ;
1998-03-08 17:14:49 +03:00
2005-06-25 00:25:18 +04:00
if ( parm - > p_class = = P_LOCAL & & snum > = 0 ) {
2008-12-15 16:16:06 +03:00
ptr = lp_local_ptr_by_snum ( snum , ptr ) ;
1998-03-08 17:14:49 +03:00
}
2007-12-04 04:17:05 +03:00
printf ( " <tr><td>%s</td><td> " , get_parm_translated ( ctx ,
stripspaceupper ( parm - > label ) , _ ( " Help " ) , parm - > label ) ) ;
1998-03-08 17:14:49 +03:00
switch ( parm - > type ) {
case P_CHAR :
2004-10-02 02:24:44 +04:00
printf ( " <input type=text size=2 name= \" parm_%s \" value= \" %c \" > " ,
1998-05-08 05:45:12 +04:00
make_parm_name ( parm - > label ) , * ( char * ) ptr ) ;
2004-10-02 02:24:44 +04:00
printf ( " <input type=button value= \" %s \" onClick= \" swatform.parm_%s.value= \' %c \' \" > " ,
2001-09-24 19:55:09 +04:00
_ ( " Set Default " ) , make_parm_name ( parm - > label ) , ( char ) ( parm - > def . cvalue ) ) ;
1998-03-08 17:14:49 +03:00
break ;
2001-06-23 19:01:34 +04:00
case P_LIST :
2005-12-20 05:23:51 +03:00
printf ( " <input type=text size=40 name= \" parm_%s \" value= \" " ,
2001-06-23 19:01:34 +04:00
make_parm_name ( parm - > label ) ) ;
2001-06-23 19:27:04 +04:00
if ( ( char * * * ) ptr & & * ( char * * * ) ptr & & * * ( char * * * ) ptr ) {
char * * list = * ( char * * * ) ptr ;
2001-06-23 19:01:34 +04:00
for ( ; * list ; list + + ) {
2005-04-20 01:35:42 +04:00
/* enclose in HTML encoded quotes if the string contains a space */
2004-12-26 21:51:49 +03:00
if ( strchr_m ( * list , ' ' ) ) {
2009-03-19 04:20:11 +03:00
push_utf8_talloc ( talloc_tos ( ) , & utf8_s1 , * list , & converted_size ) ;
push_utf8_talloc ( talloc_tos ( ) , & utf8_s2 , ( ( * ( list + 1 ) ) ? " , " : " " ) , & converted_size ) ;
2005-04-20 01:35:42 +04:00
printf ( " "%s"%s " , utf8_s1 , utf8_s2 ) ;
2004-12-26 21:51:49 +03:00
} else {
2009-03-19 04:20:11 +03:00
push_utf8_talloc ( talloc_tos ( ) , & utf8_s1 , * list , & converted_size ) ;
push_utf8_talloc ( talloc_tos ( ) , & utf8_s2 , ( ( * ( list + 1 ) ) ? " , " : " " ) , & converted_size ) ;
2004-12-26 21:51:49 +03:00
printf ( " %s%s " , utf8_s1 , utf8_s2 ) ;
}
2009-03-19 04:20:11 +03:00
TALLOC_FREE ( utf8_s1 ) ;
TALLOC_FREE ( utf8_s2 ) ;
2001-06-23 19:01:34 +04:00
}
}
2004-10-02 02:24:44 +04:00
printf ( " \" > " ) ;
printf ( " <input type=button value= \" %s \" onClick= \" swatform.parm_%s.value= \' " ,
2001-09-24 19:55:09 +04:00
_ ( " Set Default " ) , make_parm_name ( parm - > label ) ) ;
2001-06-23 19:01:34 +04:00
if ( parm - > def . lvalue ) {
2001-06-23 19:27:04 +04:00
char * * list = ( char * * ) ( parm - > def . lvalue ) ;
2001-06-23 19:01:34 +04:00
for ( ; * list ; list + + ) {
2005-04-20 01:35:42 +04:00
/* enclose in HTML encoded quotes if the string contains a space */
2007-12-04 04:17:05 +03:00
if ( strchr_m ( * list , ' ' ) )
2005-04-20 01:35:42 +04:00
printf ( " "%s"%s " , * list , ( ( * ( list + 1 ) ) ? " , " : " " ) ) ;
2003-11-22 07:33:36 +03:00
else
2004-10-02 02:24:44 +04:00
printf ( " %s%s " , * list , ( ( * ( list + 1 ) ) ? " , " : " " ) ) ;
2001-06-23 19:01:34 +04:00
}
}
2004-10-02 02:24:44 +04:00
printf ( " \' \" > " ) ;
2001-06-23 19:01:34 +04:00
break ;
1998-03-08 17:14:49 +03:00
case P_STRING :
case P_USTRING :
2009-03-19 04:20:11 +03:00
push_utf8_talloc ( talloc_tos ( ) , & utf8_s1 , * ( char * * ) ptr , & converted_size ) ;
2005-12-20 05:23:51 +03:00
printf ( " <input type=text size=40 name= \" parm_%s \" value= \" %s \" > " ,
2007-12-04 04:17:05 +03:00
make_parm_name ( parm - > label ) , fix_quotes ( ctx , utf8_s1 ) ) ;
2009-03-19 04:20:11 +03:00
TALLOC_FREE ( utf8_s1 ) ;
2004-10-02 02:24:44 +04:00
printf ( " <input type=button value= \" %s \" onClick= \" swatform.parm_%s.value= \' %s \' \" > " ,
2001-09-24 19:55:09 +04:00
_ ( " Set Default " ) , make_parm_name ( parm - > label ) , fix_backslash ( ( char * ) ( parm - > def . svalue ) ) ) ;
1998-03-08 17:14:49 +03:00
break ;
case P_BOOL :
2004-10-02 02:24:44 +04:00
printf ( " <select name= \" parm_%s \" > " , make_parm_name ( parm - > label ) ) ;
2007-10-19 04:40:25 +04:00
printf ( " <option %s>Yes " , ( * ( bool * ) ptr ) ? " selected " : " " ) ;
printf ( " <option %s>No " , ( * ( bool * ) ptr ) ? " " : " selected " ) ;
2004-10-02 02:24:44 +04:00
printf ( " </select> " ) ;
printf ( " <input type=button value= \" %s \" onClick= \" swatform.parm_%s.selectedIndex= \' %d \' \" > " ,
2007-10-19 04:40:25 +04:00
_ ( " Set Default " ) , make_parm_name ( parm - > label ) , ( bool ) ( parm - > def . bvalue ) ? 0 : 1 ) ;
1998-03-08 17:14:49 +03:00
break ;
case P_BOOLREV :
2004-10-02 02:24:44 +04:00
printf ( " <select name= \" parm_%s \" > " , make_parm_name ( parm - > label ) ) ;
2007-10-19 04:40:25 +04:00
printf ( " <option %s>Yes " , ( * ( bool * ) ptr ) ? " " : " selected " ) ;
printf ( " <option %s>No " , ( * ( bool * ) ptr ) ? " selected " : " " ) ;
2004-10-02 02:24:44 +04:00
printf ( " </select> " ) ;
printf ( " <input type=button value= \" %s \" onClick= \" swatform.parm_%s.selectedIndex= \' %d \' \" > " ,
2007-10-19 04:40:25 +04:00
_ ( " Set Default " ) , make_parm_name ( parm - > label ) , ( bool ) ( parm - > def . bvalue ) ? 1 : 0 ) ;
1998-03-08 17:14:49 +03:00
break ;
case P_INTEGER :
2004-10-02 02:24:44 +04:00
printf ( " <input type=text size=8 name= \" parm_%s \" value= \" %d \" > " , make_parm_name ( parm - > label ) , * ( int * ) ptr ) ;
printf ( " <input type=button value= \" %s \" onClick= \" swatform.parm_%s.value= \' %d \' \" > " ,
2001-09-24 19:55:09 +04:00
_ ( " Set Default " ) , make_parm_name ( parm - > label ) , ( int ) ( parm - > def . ivalue ) ) ;
1998-03-08 17:14:49 +03:00
break ;
2007-11-24 19:27:54 +03:00
case P_OCTAL : {
char * o ;
o = octal_string ( * ( int * ) ptr ) ;
printf ( " <input type=text size=8 name= \" parm_%s \" value=%s> " ,
make_parm_name ( parm - > label ) , o ) ;
TALLOC_FREE ( o ) ;
o = octal_string ( ( int ) ( parm - > def . ivalue ) ) ;
printf ( " <input type=button value= \" %s \" "
" onClick= \" swatform.parm_%s.value= \' %s \' \" > " ,
_ ( " Set Default " ) , make_parm_name ( parm - > label ) , o ) ;
TALLOC_FREE ( o ) ;
1998-03-08 17:14:49 +03:00
break ;
2007-11-24 19:27:54 +03:00
}
1998-03-08 17:14:49 +03:00
case P_ENUM :
2004-10-02 02:24:44 +04:00
printf ( " <select name= \" parm_%s \" > " , make_parm_name ( parm - > label ) ) ;
2000-09-13 11:08:09 +04:00
for ( i = 0 ; parm - > enum_list [ i ] . name ; i + + ) {
if ( i = = 0 | | parm - > enum_list [ i ] . value ! = parm - > enum_list [ i - 1 ] . value ) {
2004-10-02 02:24:44 +04:00
printf ( " <option %s>%s " , ( * ( int * ) ptr ) = = parm - > enum_list [ i ] . value ? " selected " : " " , parm - > enum_list [ i ] . name ) ;
2000-09-13 11:08:09 +04:00
}
}
2004-10-02 02:24:44 +04:00
printf ( " </select> " ) ;
printf ( " <input type=button value= \" %s \" onClick= \" swatform.parm_%s.selectedIndex= \' %d \' \" > " ,
2001-09-24 19:55:09 +04:00
_ ( " Set Default " ) , make_parm_name ( parm - > label ) , enum_index ( ( int ) ( parm - > def . ivalue ) , parm - > enum_list ) ) ;
1998-03-08 17:14:49 +03:00
break ;
1998-03-14 11:29:06 +03:00
case P_SEP :
break ;
1998-03-08 17:14:49 +03:00
}
2004-10-02 02:24:44 +04:00
printf ( " </td></tr> \n " ) ;
2007-12-04 04:17:05 +03:00
TALLOC_FREE ( ctx ) ;
1998-03-08 17:14:49 +03:00
}
1998-11-12 00:37:44 +03:00
/****************************************************************************
display a set of parameters for a service
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-09-25 19:19:00 +04:00
static void show_parameters ( int snum , int allparameters , unsigned int parm_filter , int printers )
1998-03-08 17:14:49 +03:00
{
int i = 0 ;
struct parm_struct * parm ;
2003-01-03 11:28:12 +03:00
const char * heading = NULL ;
const char * last_heading = NULL ;
1998-03-08 17:14:49 +03:00
while ( ( parm = lp_next_parameter ( snum , & i , allparameters ) ) ) {
2005-06-25 00:25:18 +04:00
if ( snum < 0 & & parm - > p_class = = P_LOCAL & & ! ( parm - > flags & FLAG_GLOBAL ) )
1998-03-14 11:29:06 +03:00
continue ;
2005-06-25 00:25:18 +04:00
if ( parm - > p_class = = P_SEPARATOR ) {
1998-03-14 11:29:06 +03:00
heading = parm - > label ;
continue ;
}
1998-03-08 17:14:49 +03:00
if ( parm - > flags & FLAG_HIDE ) continue ;
1999-12-13 16:27:58 +03:00
if ( snum > = 0 ) {
if ( printers & ! ( parm - > flags & FLAG_PRINT ) ) continue ;
if ( ! printers & ! ( parm - > flags & FLAG_SHARE ) ) continue ;
}
2003-07-28 09:47:15 +04:00
if ( ! ( parm_filter & FLAG_ADVANCED ) ) {
1999-12-13 16:27:58 +03:00
if ( ! ( parm - > flags & FLAG_BASIC ) ) {
2003-07-28 09:47:15 +04:00
void * ptr = parm - > ptr ;
1998-05-08 05:45:12 +04:00
2005-06-25 00:25:18 +04:00
if ( parm - > p_class = = P_LOCAL & & snum > = 0 ) {
2008-12-15 16:16:06 +03:00
ptr = lp_local_ptr_by_snum ( snum , ptr ) ;
1999-12-13 16:27:58 +03:00
}
1998-05-08 05:45:12 +04:00
switch ( parm - > type ) {
case P_CHAR :
if ( * ( char * ) ptr = = ( char ) ( parm - > def . cvalue ) ) continue ;
break ;
2001-06-23 19:01:34 +04:00
case P_LIST :
2008-10-18 17:56:07 +04:00
if ( ! str_list_equal ( * ( const char * * * ) ptr ,
( const char * * ) ( parm - > def . lvalue ) ) ) continue ;
2001-06-23 19:01:34 +04:00
break ;
1998-05-08 05:45:12 +04:00
case P_STRING :
case P_USTRING :
if ( ! strcmp ( * ( char * * ) ptr , ( char * ) ( parm - > def . svalue ) ) ) continue ;
break ;
case P_BOOL :
case P_BOOLREV :
2007-10-19 04:40:25 +04:00
if ( * ( bool * ) ptr = = ( bool ) ( parm - > def . bvalue ) ) continue ;
1998-05-08 05:45:12 +04:00
break ;
case P_INTEGER :
case P_OCTAL :
if ( * ( int * ) ptr = = ( int ) ( parm - > def . ivalue ) ) continue ;
break ;
case P_ENUM :
if ( * ( int * ) ptr = = ( int ) ( parm - > def . ivalue ) ) continue ;
break ;
case P_SEP :
continue ;
2003-07-28 09:47:15 +04:00
}
1998-05-08 05:45:12 +04:00
}
1998-03-08 17:14:49 +03:00
if ( printers & & ! ( parm - > flags & FLAG_PRINT ) ) continue ;
}
2003-07-28 09:47:15 +04:00
if ( ( parm_filter & FLAG_WIZARD ) & & ! ( parm - > flags & FLAG_WIZARD ) ) continue ;
2009-11-30 00:23:22 +03:00
2003-07-28 09:47:15 +04:00
if ( ( parm_filter & FLAG_ADVANCED ) & & ! ( parm - > flags & FLAG_ADVANCED ) ) continue ;
2009-11-30 00:23:22 +03:00
1998-03-14 11:29:06 +03:00
if ( heading & & heading ! = last_heading ) {
2004-10-02 02:24:44 +04:00
printf ( " <tr><td></td></tr><tr><td><b><u>%s</u></b></td></tr> \n " , _ ( heading ) ) ;
1998-03-14 11:29:06 +03:00
last_heading = heading ;
}
1998-03-08 17:14:49 +03:00
show_parameter ( snum , parm ) ;
}
}
1999-12-13 16:27:58 +03:00
/****************************************************************************
load the smb . conf file into loadparm .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static bool load_config ( bool save_def )
1999-12-13 16:27:58 +03:00
{
2007-12-10 22:30:37 +03:00
return lp_load ( get_dyn_CONFIGFILE ( ) , False , save_def , False , True ) ;
1999-12-13 16:27:58 +03:00
}
1998-11-12 00:37:44 +03:00
/****************************************************************************
write a config file
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static void write_config ( FILE * f , bool show_defaults )
1998-03-17 14:44:16 +03:00
{
2008-03-28 17:49:13 +03:00
TALLOC_CTX * ctx = talloc_stackframe ( ) ;
1998-03-17 14:44:16 +03:00
fprintf ( f , " # Samba config file created using SWAT \n " ) ;
1998-03-17 15:31:43 +03:00
fprintf ( f , " # from %s (%s) \n " , cgi_remote_host ( ) , cgi_remote_addr ( ) ) ;
2008-03-28 17:49:13 +03:00
fprintf ( f , " # Date: %s \n \n " , current_timestring ( ctx , False ) ) ;
2009-11-30 00:23:22 +03:00
2001-07-04 11:15:53 +04:00
lp_dump ( f , show_defaults , iNumNonAutoPrintServices ) ;
2008-03-28 17:49:13 +03:00
TALLOC_FREE ( ctx ) ;
1998-03-17 14:44:16 +03:00
}
1998-11-12 00:37:44 +03:00
/****************************************************************************
2002-09-25 19:19:00 +04:00
save and reload the smb . conf config file
1998-11-12 00:37:44 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
static int save_reload ( int snum )
1998-03-08 17:14:49 +03:00
{
FILE * f ;
2001-05-30 10:12:21 +04:00
struct stat st ;
2001-05-29 03:56:56 +04:00
2007-12-10 22:30:37 +03:00
f = sys_fopen ( get_dyn_CONFIGFILE ( ) , " w " ) ;
1998-03-08 17:14:49 +03:00
if ( ! f ) {
2007-12-10 22:30:37 +03:00
printf ( _ ( " failed to open %s for writing " ) , get_dyn_CONFIGFILE ( ) ) ;
2004-10-02 02:24:44 +04:00
printf ( " \n " ) ;
1998-03-08 17:14:49 +03:00
return 0 ;
}
2001-05-30 10:12:21 +04:00
/* just in case they have used the buggy xinetd to create the file */
if ( fstat ( fileno ( f ) , & st ) = = 0 & &
( st . st_mode & S_IWOTH ) ) {
2003-05-07 22:28:24 +04:00
# if defined HAVE_FCHMOD
2001-05-30 10:12:21 +04:00
fchmod ( fileno ( f ) , S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH ) ;
2003-05-07 22:28:24 +04:00
# else
2007-12-10 22:30:37 +03:00
chmod ( get_dyn_CONFIGFILE ( ) , S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH ) ;
2003-05-07 22:28:24 +04:00
# endif
2001-05-30 10:12:21 +04:00
}
2001-07-04 11:15:53 +04:00
write_config ( f , False ) ;
2009-01-06 17:13:43 +03:00
if ( snum > = 0 )
2001-07-04 11:15:53 +04:00
lp_dump_one ( f , False , snum ) ;
1998-03-08 17:14:49 +03:00
fclose ( f ) ;
2008-03-12 02:54:48 +03:00
lp_kill_all_services ( ) ;
1998-03-08 17:14:49 +03:00
1999-12-13 16:27:58 +03:00
if ( ! load_config ( False ) ) {
2007-12-10 22:30:37 +03:00
printf ( _ ( " Can't reload %s " ) , get_dyn_CONFIGFILE ( ) ) ;
2004-10-02 02:24:44 +04:00
printf ( " \n " ) ;
1998-03-08 17:14:49 +03:00
return 0 ;
}
1999-12-13 16:27:58 +03:00
iNumNonAutoPrintServices = lp_numservices ( ) ;
2010-12-23 14:14:21 +03:00
if ( pcap_cache_loaded ( ) ) {
load_printers ( server_event_context ( ) ,
server_messaging_context ( ) ) ;
}
1998-03-08 17:14:49 +03:00
return 1 ;
}
1998-11-12 00:37:44 +03:00
/****************************************************************************
commit one parameter
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-01-03 11:28:12 +03:00
static void commit_parameter ( int snum , struct parm_struct * parm , const char * v )
1998-03-14 14:24:01 +03:00
{
int i ;
char * s ;
2005-06-25 00:25:18 +04:00
if ( snum < 0 & & parm - > p_class = = P_LOCAL ) {
1998-03-14 14:24:01 +03:00
/* this handles the case where we are changing a local
variable globally . We need to change the parameter in
all shares where it is currently set to the default */
for ( i = 0 ; i < lp_numservices ( ) ; i + + ) {
s = lp_servicename ( i ) ;
if ( s & & ( * s ) & & lp_is_default ( i , parm ) ) {
lp_do_parameter ( i , parm - > label , v ) ;
}
}
}
lp_do_parameter ( snum , parm - > label , v ) ;
}
1998-11-12 00:37:44 +03:00
/****************************************************************************
commit a set of parameters for a service
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-03-08 17:14:49 +03:00
static void commit_parameters ( int snum )
{
int i = 0 ;
struct parm_struct * parm ;
2007-12-04 04:17:05 +03:00
char * label ;
2003-01-03 11:28:12 +03:00
const char * v ;
1998-03-08 17:14:49 +03:00
while ( ( parm = lp_next_parameter ( snum , & i , 1 ) ) ) {
2007-12-04 04:17:05 +03:00
if ( asprintf ( & label , " parm_%s " , make_parm_name ( parm - > label ) ) > 0 ) {
if ( ( v = cgi_variable ( label ) ) ! = NULL ) {
if ( parm - > flags & FLAG_HIDE )
continue ;
commit_parameter ( snum , parm , v ) ;
}
SAFE_FREE ( label ) ;
1998-03-08 17:14:49 +03:00
}
}
}
1998-11-12 00:37:44 +03:00
/****************************************************************************
2005-12-20 05:23:51 +03:00
spit out the html for a link with an image
1998-11-12 00:37:44 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-12-20 05:23:51 +03:00
static void image_link ( const char * name , const char * hlink , const char * src )
1998-03-08 17:14:49 +03:00
{
2005-12-20 05:23:51 +03:00
printf ( " <A HREF= \" %s/%s \" ><img border= \" 0 \" src= \" /swat/%s \" alt= \" %s \" ></A> \n " ,
cgi_baseurl ( ) , hlink , src , name ) ;
1998-03-08 17:14:49 +03:00
}
1998-11-12 00:37:44 +03:00
/****************************************************************************
display the main navigation controls at the top of each page along
with a title
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-12-20 05:23:51 +03:00
static void show_main_buttons ( void )
1998-03-08 17:14:49 +03:00
{
1999-12-13 16:27:58 +03:00
char * p ;
2009-11-30 00:23:22 +03:00
2005-12-20 05:23:51 +03:00
if ( ( p = cgi_user_name ( ) ) & & strcmp ( p , " root " ) ) {
printf ( _ ( " Logged in as <b>%s</b> " ) , p ) ;
printf ( " <p> \n " ) ;
}
1998-11-12 00:37:44 +03:00
2005-12-20 05:23:51 +03:00
image_link ( _ ( " Home " ) , " " , " images/home.gif " ) ;
1999-12-13 16:27:58 +03:00
if ( have_write_access ) {
2005-12-20 05:23:51 +03:00
image_link ( _ ( " Globals " ) , " globals " , " images/globals.gif " ) ;
image_link ( _ ( " Shares " ) , " shares " , " images/shares.gif " ) ;
image_link ( _ ( " Printers " ) , " printers " , " images/printers.gif " ) ;
image_link ( _ ( " Wizard " ) , " wizard " , " images/wizard.gif " ) ;
1999-12-13 16:27:58 +03:00
}
2005-12-20 05:23:51 +03:00
/* root always gets all buttons, otherwise look for -P */
2005-02-02 21:01:11 +03:00
if ( have_write_access | | ( ! passwd_only & & have_read_access ) ) {
2005-12-20 05:23:51 +03:00
image_link ( _ ( " Status " ) , " status " , " images/status.gif " ) ;
image_link ( _ ( " View Config " ) , " viewconfig " , " images/viewconfig.gif " ) ;
1999-12-13 16:27:58 +03:00
}
2005-12-20 05:23:51 +03:00
image_link ( _ ( " Password Management " ) , " passwd " , " images/passwd.gif " ) ;
1998-03-08 17:14:49 +03:00
2005-12-20 05:23:51 +03:00
printf ( " <HR> \n " ) ;
1998-03-08 17:14:49 +03:00
}
2002-09-25 19:19:00 +04:00
/****************************************************************************
* Handle Display / Edit Mode CGI
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void ViewModeBoxes ( int mode )
{
2004-10-02 02:24:44 +04:00
printf ( " <p>%s: \n " , _ ( " Current View Is " ) ) ;
printf ( " <input type=radio name= \" ViewMode \" value=0 %s>%s \n " , ( ( mode = = 0 ) ? " checked " : " " ) , _ ( " Basic " ) ) ;
printf ( " <input type=radio name= \" ViewMode \" value=1 %s>%s \n " , ( ( mode = = 1 ) ? " checked " : " " ) , _ ( " Advanced " ) ) ;
printf ( " <br>%s: \n " , _ ( " Change View To " ) ) ;
printf ( " <input type=submit name= \" BasicMode \" value= \" %s \" > \n " , _ ( " Basic " ) ) ;
printf ( " <input type=submit name= \" AdvMode \" value= \" %s \" > \n " , _ ( " Advanced " ) ) ;
printf ( " </p><br> \n " ) ;
2002-09-25 19:19:00 +04:00
}
1998-11-12 00:37:44 +03:00
/****************************************************************************
2005-12-20 05:23:51 +03:00
display a welcome page
1998-11-12 00:37:44 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-03-08 17:14:49 +03:00
static void welcome_page ( void )
{
2008-10-17 14:48:19 +04:00
if ( file_exist ( " help/welcome.html " ) ) {
2006-02-08 07:05:34 +03:00
include_html ( " help/welcome.html " ) ;
} else {
include_html ( " help/welcome-no-samba-doc.html " ) ;
}
1998-03-08 17:14:49 +03:00
}
1998-11-12 00:37:44 +03:00
/****************************************************************************
display the current smb . conf
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-03-14 11:29:06 +03:00
static void viewconfig_page ( void )
{
1998-03-17 14:44:16 +03:00
int full_view = 0 ;
if ( cgi_variable ( " full_view " ) ) {
full_view = 1 ;
}
2004-10-02 02:24:44 +04:00
printf ( " <H2>%s</H2> \n " , _ ( " Current Config " ) ) ;
printf ( " <form method=post> \n " ) ;
1998-03-17 14:44:16 +03:00
if ( full_view ) {
2004-10-02 02:24:44 +04:00
printf ( " <input type=submit name= \" normal_view \" value= \" %s \" > \n " , _ ( " Normal View " ) ) ;
1998-03-17 14:44:16 +03:00
} else {
2004-10-02 02:24:44 +04:00
printf ( " <input type=submit name= \" full_view \" value= \" %s \" > \n " , _ ( " Full View " ) ) ;
1998-03-17 14:44:16 +03:00
}
2004-10-02 02:24:44 +04:00
printf ( " <p><pre> " ) ;
2001-07-04 11:15:53 +04:00
write_config ( stdout , full_view ) ;
2004-10-02 02:24:44 +04:00
printf ( " </pre> " ) ;
printf ( " </form> \n " ) ;
1998-03-14 11:29:06 +03:00
}
2002-09-25 19:19:00 +04:00
/****************************************************************************
second screen of the wizard . . . Fetch Configuration Parameters
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void wizard_params_page ( void )
{
unsigned int parm_filter = FLAG_WIZARD ;
/* Here we first set and commit all the parameters that were selected
in the previous screen . */
2004-10-02 02:24:44 +04:00
printf ( " <H2>%s</H2> \n " , _ ( " Wizard Parameter Edit Page " ) ) ;
2002-09-25 19:19:00 +04:00
if ( cgi_variable ( " Commit " ) ) {
2003-05-26 20:54:39 +04:00
commit_parameters ( GLOBAL_SECTION_SNUM ) ;
2009-11-30 01:31:45 +03:00
save_reload ( - 1 ) ;
2002-09-25 19:19:00 +04:00
}
2004-10-02 02:24:44 +04:00
printf ( " <form name= \" swatform \" method=post action=wizard_params> \n " ) ;
2002-09-25 19:19:00 +04:00
if ( have_write_access ) {
2004-10-02 02:24:44 +04:00
printf ( " <input type=submit name= \" Commit \" value= \" Commit Changes \" > \n " ) ;
2002-09-25 19:19:00 +04:00
}
2004-10-02 02:24:44 +04:00
printf ( " <input type=reset name= \" Reset Values \" value= \" Reset \" > \n " ) ;
printf ( " <p> \n " ) ;
2009-11-30 00:23:22 +03:00
2004-10-02 02:24:44 +04:00
printf ( " <table> \n " ) ;
2003-05-26 20:54:39 +04:00
show_parameters ( GLOBAL_SECTION_SNUM , 1 , parm_filter , 0 ) ;
2004-10-02 02:24:44 +04:00
printf ( " </table> \n " ) ;
printf ( " </form> \n " ) ;
2002-09-25 19:19:00 +04:00
}
/****************************************************************************
Utility to just rewrite the smb . conf file - effectively just cleans it up
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void rewritecfg_file ( void )
{
2003-05-26 20:54:39 +04:00
commit_parameters ( GLOBAL_SECTION_SNUM ) ;
2009-11-30 01:31:45 +03:00
save_reload ( - 1 ) ;
2005-12-20 05:23:51 +03:00
printf ( " <H2>%s</H2> \n " , _ ( " Note: smb.conf file has been read and rewritten " ) ) ;
2002-09-25 19:19:00 +04:00
}
/****************************************************************************
wizard to create / modify the smb . conf file
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void wizard_page ( void )
{
/* Set some variables to collect data from smb.conf */
int role = 0 ;
int winstype = 0 ;
int have_home = - 1 ;
int HomeExpo = 0 ;
int SerType = 0 ;
if ( cgi_variable ( " Rewrite " ) ) {
( void ) rewritecfg_file ( ) ;
return ;
}
if ( cgi_variable ( " GetWizardParams " ) ) {
( void ) wizard_params_page ( ) ;
return ;
}
if ( cgi_variable ( " Commit " ) ) {
2006-06-20 23:21:14 +04:00
SerType = atoi ( cgi_variable_nonull ( " ServerType " ) ) ;
winstype = atoi ( cgi_variable_nonull ( " WINSType " ) ) ;
2002-09-25 19:19:00 +04:00
have_home = lp_servicenumber ( HOMES_NAME ) ;
2006-06-20 23:21:14 +04:00
HomeExpo = atoi ( cgi_variable_nonull ( " HomeExpo " ) ) ;
2002-09-25 19:19:00 +04:00
/* Plain text passwords are too badly broken - use encrypted passwords only */
2003-05-26 20:54:39 +04:00
lp_do_parameter ( GLOBAL_SECTION_SNUM , " encrypt passwords " , " Yes " ) ;
2009-11-30 00:23:22 +03:00
2002-09-25 19:19:00 +04:00
switch ( SerType ) {
case 0 :
/* Stand-alone Server */
2003-05-26 20:54:39 +04:00
lp_do_parameter ( GLOBAL_SECTION_SNUM , " security " , " USER " ) ;
lp_do_parameter ( GLOBAL_SECTION_SNUM , " domain logons " , " No " ) ;
2002-09-25 19:19:00 +04:00
break ;
case 1 :
/* Domain Member */
2003-05-26 20:54:39 +04:00
lp_do_parameter ( GLOBAL_SECTION_SNUM , " security " , " DOMAIN " ) ;
lp_do_parameter ( GLOBAL_SECTION_SNUM , " domain logons " , " No " ) ;
2002-09-25 19:19:00 +04:00
break ;
case 2 :
/* Domain Controller */
2003-05-26 20:54:39 +04:00
lp_do_parameter ( GLOBAL_SECTION_SNUM , " security " , " USER " ) ;
lp_do_parameter ( GLOBAL_SECTION_SNUM , " domain logons " , " Yes " ) ;
2002-09-25 19:19:00 +04:00
break ;
}
switch ( winstype ) {
case 0 :
2003-05-26 20:54:39 +04:00
lp_do_parameter ( GLOBAL_SECTION_SNUM , " wins support " , " No " ) ;
lp_do_parameter ( GLOBAL_SECTION_SNUM , " wins server " , " " ) ;
2002-09-25 19:19:00 +04:00
break ;
case 1 :
2003-05-26 20:54:39 +04:00
lp_do_parameter ( GLOBAL_SECTION_SNUM , " wins support " , " Yes " ) ;
lp_do_parameter ( GLOBAL_SECTION_SNUM , " wins server " , " " ) ;
2002-09-25 19:19:00 +04:00
break ;
case 2 :
2003-05-26 20:54:39 +04:00
lp_do_parameter ( GLOBAL_SECTION_SNUM , " wins support " , " No " ) ;
2006-06-20 23:21:14 +04:00
lp_do_parameter ( GLOBAL_SECTION_SNUM , " wins server " , cgi_variable_nonull ( " WINSAddr " ) ) ;
2002-09-25 19:19:00 +04:00
break ;
}
/* Have to create Homes share? */
if ( ( HomeExpo = = 1 ) & & ( have_home = = - 1 ) ) {
2007-12-04 04:17:05 +03:00
const char * unix_share = HOMES_NAME ;
2002-09-25 19:19:00 +04:00
load_config ( False ) ;
2003-05-26 20:54:39 +04:00
lp_copy_service ( GLOBAL_SECTION_SNUM , unix_share ) ;
2002-09-25 19:19:00 +04:00
have_home = lp_servicenumber ( HOMES_NAME ) ;
lp_do_parameter ( have_home , " read only " , " No " ) ;
lp_do_parameter ( have_home , " valid users " , " %S " ) ;
lp_do_parameter ( have_home , " browseable " , " No " ) ;
commit_parameters ( have_home ) ;
2008-07-16 01:37:48 +04:00
save_reload ( have_home ) ;
2002-09-25 19:19:00 +04:00
}
/* Need to Delete Homes share? */
if ( ( HomeExpo = = 0 ) & & ( have_home ! = - 1 ) ) {
lp_remove_service ( have_home ) ;
have_home = - 1 ;
}
2003-05-26 20:54:39 +04:00
commit_parameters ( GLOBAL_SECTION_SNUM ) ;
2009-11-30 01:31:45 +03:00
save_reload ( - 1 ) ;
2002-09-25 19:19:00 +04:00
}
else
{
/* Now determine smb.conf WINS settings */
if ( lp_wins_support ( ) )
winstype = 1 ;
2002-11-09 19:57:45 +03:00
if ( lp_wins_server_list ( ) & & strlen ( * lp_wins_server_list ( ) ) )
winstype = 2 ;
2002-09-25 19:19:00 +04:00
/* Do we have a homes share? */
have_home = lp_servicenumber ( HOMES_NAME ) ;
}
if ( ( winstype = = 2 ) & & lp_wins_support ( ) )
winstype = 3 ;
role = lp_server_role ( ) ;
2009-11-30 00:23:22 +03:00
2002-09-25 19:19:00 +04:00
/* Here we go ... */
2004-10-02 02:24:44 +04:00
printf ( " <H2>%s</H2> \n " , _ ( " Samba Configuration Wizard " ) ) ;
printf ( " <form method=post action=wizard> \n " ) ;
2002-09-25 19:19:00 +04:00
if ( have_write_access ) {
2005-12-20 05:23:51 +03:00
printf ( " %s \n " , _ ( " The \" Rewrite smb.conf file \" button will clear the smb.conf file of all default values and of comments. " ) ) ;
2004-10-02 02:24:44 +04:00
printf ( " %s " , _ ( " The same will happen if you press the commit button. " ) ) ;
printf ( " <br><br> \n " ) ;
printf ( " <center> " ) ;
printf ( " <input type=submit name= \" Rewrite \" value= \" %s \" > " , _ ( " Rewrite smb.conf file " ) ) ;
printf ( " <input type=submit name= \" Commit \" value= \" %s \" > " , _ ( " Commit " ) ) ;
printf ( " <input type=submit name= \" GetWizardParams \" value= \" %s \" > " , _ ( " Edit Parameter Values " ) ) ;
printf ( " </center> \n " ) ;
2002-09-25 19:19:00 +04:00
}
2004-10-02 02:24:44 +04:00
printf ( " <hr> " ) ;
printf ( " <center><table border=0> " ) ;
printf ( " <tr><td><b>%s: </b></td> \n " , _ ( " Server Type " ) ) ;
printf ( " <td><input type=radio name= \" ServerType \" value= \" 0 \" %s> %s </td> " , ( ( role = = ROLE_STANDALONE ) ? " checked " : " " ) , _ ( " Stand Alone " ) ) ;
printf ( " <td><input type=radio name= \" ServerType \" value= \" 1 \" %s> %s </td> " , ( ( role = = ROLE_DOMAIN_MEMBER ) ? " checked " : " " ) , _ ( " Domain Member " ) ) ;
printf ( " <td><input type=radio name= \" ServerType \" value= \" 2 \" %s> %s </td> " , ( ( role = = ROLE_DOMAIN_PDC ) ? " checked " : " " ) , _ ( " Domain Controller " ) ) ;
printf ( " </tr> \n " ) ;
2002-09-25 19:19:00 +04:00
if ( role = = ROLE_DOMAIN_BDC ) {
2004-10-02 02:24:44 +04:00
printf ( " <tr><td></td><td colspan=3><font color= \" #ff0000 \" >%s</font></td></tr> \n " , _ ( " Unusual Type in smb.conf - Please Select New Mode " ) ) ;
2002-09-25 19:19:00 +04:00
}
2004-10-02 02:24:44 +04:00
printf ( " <tr><td><b>%s: </b></td> \n " , _ ( " Configure WINS As " ) ) ;
printf ( " <td><input type=radio name= \" WINSType \" value= \" 0 \" %s> %s </td> " , ( ( winstype = = 0 ) ? " checked " : " " ) , _ ( " Not Used " ) ) ;
printf ( " <td><input type=radio name= \" WINSType \" value= \" 1 \" %s> %s </td> " , ( ( winstype = = 1 ) ? " checked " : " " ) , _ ( " Server for client use " ) ) ;
printf ( " <td><input type=radio name= \" WINSType \" value= \" 2 \" %s> %s </td> " , ( ( winstype = = 2 ) ? " checked " : " " ) , _ ( " Client of another WINS server " ) ) ;
printf ( " </tr> \n " ) ;
printf ( " <tr><td></td><td></td><td></td><td>%s <input type=text size= \" 16 \" name= \" WINSAddr \" value= \" " , _ ( " Remote WINS Server " ) ) ;
2003-09-26 06:04:03 +04:00
2003-08-19 19:18:27 +04:00
/* Print out the list of wins servers */
if ( lp_wins_server_list ( ) ) {
int i ;
const char * * wins_servers = lp_wins_server_list ( ) ;
2004-10-02 02:24:44 +04:00
for ( i = 0 ; wins_servers [ i ] ; i + + ) printf ( " %s " , wins_servers [ i ] ) ;
2003-08-19 19:18:27 +04:00
}
2009-11-30 00:23:22 +03:00
2004-10-02 02:24:44 +04:00
printf ( " \" ></td></tr> \n " ) ;
2002-09-25 19:19:00 +04:00
if ( winstype = = 3 ) {
2004-10-02 02:24:44 +04:00
printf ( " <tr><td></td><td colspan=3><font color= \" #ff0000 \" >%s</font></td></tr> \n " , _ ( " Error: WINS Server Mode and WINS Support both set in smb.conf " ) ) ;
printf ( " <tr><td></td><td colspan=3><font color= \" #ff0000 \" >%s</font></td></tr> \n " , _ ( " Please Select desired WINS mode above. " ) ) ;
2002-09-25 19:19:00 +04:00
}
2004-10-02 02:24:44 +04:00
printf ( " <tr><td><b>%s: </b></td> \n " , _ ( " Expose Home Directories " ) ) ;
printf ( " <td><input type=radio name= \" HomeExpo \" value= \" 1 \" %s> Yes</td> " , ( have_home = = - 1 ) ? " " : " checked " ) ;
printf ( " <td><input type=radio name= \" HomeExpo \" value= \" 0 \" %s> No</td> " , ( have_home = = - 1 ) ? " checked " : " " ) ;
printf ( " <td></td></tr> \n " ) ;
2009-11-30 00:23:22 +03:00
2002-09-25 19:19:00 +04:00
/* Enable this when we are ready ....
2004-10-02 02:24:44 +04:00
* printf ( " <tr><td><b>%s: </b></td> \n " , _ ( " Is Print Server " ) ) ;
* printf ( " <td><input type=radio name= \" PtrSvr \" value= \" 1 \" %s> Yes</td> " ) ;
* printf ( " <td><input type=radio name= \" PtrSvr \" value= \" 0 \" %s> No</td> " ) ;
* printf ( " <td></td></tr> \n " ) ;
2002-09-25 19:19:00 +04:00
*/
2009-11-30 00:23:22 +03:00
2004-10-02 02:24:44 +04:00
printf ( " </table></center> " ) ;
printf ( " <hr> " ) ;
2002-09-25 19:19:00 +04:00
2004-10-02 02:24:44 +04:00
printf ( " %s \n " , _ ( " The above configuration options will set multiple parameters and will generally assist with rapid Samba deployment. " ) ) ;
printf ( " </form> \n " ) ;
2002-09-25 19:19:00 +04:00
}
1998-11-12 00:37:44 +03:00
/****************************************************************************
2005-12-20 05:23:51 +03:00
display a globals editing page
1998-11-12 00:37:44 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-12-20 05:23:51 +03:00
static void globals_page ( void )
1998-03-08 17:14:49 +03:00
{
2002-09-25 19:19:00 +04:00
unsigned int parm_filter = FLAG_BASIC ;
int mode = 0 ;
1998-03-08 17:14:49 +03:00
2005-12-20 05:23:51 +03:00
printf ( " <H2>%s</H2> \n " , _ ( " Global Parameters " ) ) ;
1998-03-08 17:14:49 +03:00
if ( cgi_variable ( " Commit " ) ) {
2003-05-26 20:54:39 +04:00
commit_parameters ( GLOBAL_SECTION_SNUM ) ;
2009-11-30 01:31:45 +03:00
save_reload ( - 1 ) ;
1998-03-08 17:14:49 +03:00
}
2002-09-25 19:19:00 +04:00
if ( cgi_variable ( " ViewMode " ) )
2006-06-20 23:21:14 +04:00
mode = atoi ( cgi_variable_nonull ( " ViewMode " ) ) ;
2003-07-26 20:56:38 +04:00
if ( cgi_variable ( " BasicMode " ) )
mode = 0 ;
if ( cgi_variable ( " AdvMode " ) )
mode = 1 ;
2002-09-25 19:19:00 +04:00
2005-12-20 05:23:51 +03:00
printf ( " <form name= \" swatform \" method=post action=globals> \n " ) ;
2002-09-25 19:19:00 +04:00
ViewModeBoxes ( mode ) ;
switch ( mode ) {
case 0 :
parm_filter = FLAG_BASIC ;
break ;
case 1 :
parm_filter = FLAG_ADVANCED ;
break ;
}
2004-10-02 02:24:44 +04:00
printf ( " <br> \n " ) ;
1998-11-14 05:29:38 +03:00
if ( have_write_access ) {
2004-10-02 02:24:44 +04:00
printf ( " <input type=submit name= \" Commit \" value= \" %s \" > \n " ,
2001-09-24 19:55:09 +04:00
_ ( " Commit Changes " ) ) ;
1998-11-14 05:29:38 +03:00
}
2004-10-02 02:24:44 +04:00
printf ( " <input type=reset name= \" Reset Values \" value= \" %s \" > \n " ,
2001-09-24 19:55:09 +04:00
_ ( " Reset Values " ) ) ;
2002-09-25 19:19:00 +04:00
2004-10-02 02:24:44 +04:00
printf ( " <p> \n " ) ;
printf ( " <table> \n " ) ;
2003-05-26 20:54:39 +04:00
show_parameters ( GLOBAL_SECTION_SNUM , 1 , parm_filter , 0 ) ;
2004-10-02 02:24:44 +04:00
printf ( " </table> \n " ) ;
printf ( " </form> \n " ) ;
1998-03-08 17:14:49 +03:00
}
1998-11-12 00:37:44 +03:00
/****************************************************************************
2004-10-02 02:24:44 +04:00
display a shares editing page . share is in unix codepage ,
1998-11-12 00:37:44 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-03-08 17:14:49 +03:00
static void shares_page ( void )
{
2003-01-03 11:28:12 +03:00
const char * share = cgi_variable ( " share " ) ;
1998-03-08 17:14:49 +03:00
char * s ;
2004-10-02 02:24:44 +04:00
char * utf8_s ;
2001-09-24 19:55:09 +04:00
int snum = - 1 ;
1998-03-08 17:14:49 +03:00
int i ;
2002-09-25 19:19:00 +04:00
int mode = 0 ;
unsigned int parm_filter = FLAG_BASIC ;
2008-04-30 01:36:24 +04:00
size_t converted_size ;
1998-03-08 17:14:49 +03:00
if ( share )
snum = lp_servicenumber ( share ) ;
2004-10-02 02:24:44 +04:00
printf ( " <H2>%s</H2> \n " , _ ( " Share Parameters " ) ) ;
1998-03-08 17:14:49 +03:00
if ( cgi_variable ( " Commit " ) & & snum > = 0 ) {
commit_parameters ( snum ) ;
2009-11-30 01:31:45 +03:00
save_reload ( - 1 ) ;
2008-07-16 01:37:48 +04:00
snum = lp_servicenumber ( share ) ;
1998-03-08 17:14:49 +03:00
}
if ( cgi_variable ( " Delete " ) & & snum > = 0 ) {
lp_remove_service ( snum ) ;
2009-11-30 01:31:45 +03:00
save_reload ( - 1 ) ;
1998-03-08 17:14:49 +03:00
share = NULL ;
snum = - 1 ;
}
if ( cgi_variable ( " createshare " ) & & ( share = cgi_variable ( " newshare " ) ) ) {
snum = lp_servicenumber ( share ) ;
2008-07-16 01:37:48 +04:00
if ( snum < 0 ) {
load_config ( False ) ;
lp_copy_service ( GLOBAL_SECTION_SNUM , share ) ;
snum = lp_servicenumber ( share ) ;
save_reload ( snum ) ;
snum = lp_servicenumber ( share ) ;
}
1998-03-08 17:14:49 +03:00
}
2004-10-02 02:24:44 +04:00
printf ( " <FORM name= \" swatform \" method=post> \n " ) ;
1998-03-08 17:14:49 +03:00
2004-10-02 02:24:44 +04:00
printf ( " <table> \n " ) ;
2003-07-27 23:49:23 +04:00
2002-09-25 19:19:00 +04:00
if ( cgi_variable ( " ViewMode " ) )
2006-06-20 23:21:14 +04:00
mode = atoi ( cgi_variable_nonull ( " ViewMode " ) ) ;
2003-07-26 20:56:38 +04:00
if ( cgi_variable ( " BasicMode " ) )
mode = 0 ;
if ( cgi_variable ( " AdvMode " ) )
mode = 1 ;
2003-07-27 23:49:23 +04:00
2002-09-25 19:19:00 +04:00
ViewModeBoxes ( mode ) ;
switch ( mode ) {
case 0 :
parm_filter = FLAG_BASIC ;
break ;
case 1 :
parm_filter = FLAG_ADVANCED ;
break ;
}
2004-10-02 02:24:44 +04:00
printf ( " <br><tr> \n " ) ;
printf ( " <td><input type=submit name=selectshare value= \" %s \" ></td> \n " , _ ( " Choose Share " ) ) ;
printf ( " <td><select name=share> \n " ) ;
1998-03-08 17:14:49 +03:00
if ( snum < 0 )
2004-10-02 02:24:44 +04:00
printf ( " <option value= \" \" > \n " ) ;
1998-03-08 17:14:49 +03:00
for ( i = 0 ; i < lp_numservices ( ) ; i + + ) {
s = lp_servicename ( i ) ;
1998-03-08 17:52:45 +03:00
if ( s & & ( * s ) & & strcmp ( s , " IPC$ " ) & & ! lp_print_ok ( i ) ) {
2009-03-19 04:20:11 +03:00
push_utf8_talloc ( talloc_tos ( ) , & utf8_s , s , & converted_size ) ;
2004-10-02 02:24:44 +04:00
printf ( " <option %s value= \" %s \" >%s \n " ,
1998-03-08 17:14:49 +03:00
( share & & strcmp ( share , s ) = = 0 ) ? " SELECTED " : " " ,
2004-10-02 02:24:44 +04:00
utf8_s , utf8_s ) ;
2009-03-19 04:20:11 +03:00
TALLOC_FREE ( utf8_s ) ;
1998-03-08 17:14:49 +03:00
}
}
2004-10-02 02:24:44 +04:00
printf ( " </select></td> \n " ) ;
1999-12-13 16:27:58 +03:00
if ( have_write_access ) {
2004-10-02 02:24:44 +04:00
printf ( " <td><input type=submit name= \" Delete \" value= \" %s \" ></td> \n " , _ ( " Delete Share " ) ) ;
1999-12-13 16:27:58 +03:00
}
2004-10-02 02:24:44 +04:00
printf ( " </tr> \n " ) ;
printf ( " </table> " ) ;
printf ( " <table> " ) ;
1999-12-13 16:27:58 +03:00
if ( have_write_access ) {
2004-10-02 02:24:44 +04:00
printf ( " <tr> \n " ) ;
printf ( " <td><input type=submit name=createshare value= \" %s \" ></td> \n " , _ ( " Create Share " ) ) ;
printf ( " <td><input type=text size=30 name=newshare></td></tr> \n " ) ;
1999-12-13 16:27:58 +03:00
}
2004-10-02 02:24:44 +04:00
printf ( " </table> " ) ;
1998-03-08 17:14:49 +03:00
if ( snum > = 0 ) {
1998-11-14 05:29:38 +03:00
if ( have_write_access ) {
2004-10-02 02:24:44 +04:00
printf ( " <input type=submit name= \" Commit \" value= \" %s \" > \n " , _ ( " Commit Changes " ) ) ;
1998-11-14 05:29:38 +03:00
}
2004-10-02 02:24:44 +04:00
printf ( " <input type=reset name= \" Reset Values \" value= \" %s \" > \n " , _ ( " Reset Values " ) ) ;
printf ( " <p> \n " ) ;
1998-03-08 17:14:49 +03:00
}
if ( snum > = 0 ) {
2004-10-02 02:24:44 +04:00
printf ( " <table> \n " ) ;
2002-09-25 19:19:00 +04:00
show_parameters ( snum , 1 , parm_filter , 0 ) ;
2004-10-02 02:24:44 +04:00
printf ( " </table> \n " ) ;
1998-03-08 17:14:49 +03:00
}
2004-10-02 02:24:44 +04:00
printf ( " </FORM> \n " ) ;
1998-03-08 17:14:49 +03:00
}
1998-11-12 10:06:48 +03:00
/*************************************************************
change a password either locally or remotely
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static bool change_password ( const char * remote_machine , const char * user_name ,
2003-01-03 11:28:12 +03:00
const char * old_passwd , const char * new_passwd ,
2000-02-26 01:25:25 +03:00
int local_flags )
1998-11-12 00:37:44 +03:00
{
2006-02-04 01:19:41 +03:00
NTSTATUS ret ;
2007-11-22 04:42:52 +03:00
char * err_str = NULL ;
char * msg_str = NULL ;
1998-11-13 02:49:32 +03:00
1998-11-12 10:13:06 +03:00
if ( demo_mode ) {
2004-10-02 02:24:44 +04:00
printf ( " %s \n <p> " , _ ( " password change in demo mode rejected " ) ) ;
1998-11-12 10:13:06 +03:00
return False ;
}
2009-11-30 00:23:22 +03:00
1998-11-12 10:06:48 +03:00
if ( remote_machine ! = NULL ) {
2007-11-23 14:04:35 +03:00
ret = remote_password_change ( remote_machine , user_name ,
old_passwd , new_passwd , & err_str ) ;
if ( err_str ! = NULL )
2004-10-02 02:24:44 +04:00
printf ( " %s \n <p> " , err_str ) ;
2007-11-23 14:04:35 +03:00
SAFE_FREE ( err_str ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_IS_OK ( ret ) ;
1998-11-12 00:37:44 +03:00
}
2007-03-11 19:49:16 +03:00
if ( ! initialize_password_db ( True , NULL ) ) {
2004-10-02 02:24:44 +04:00
printf ( " %s \n <p> " , _ ( " Can't setup password database vectors. " ) ) ;
1998-11-12 10:06:48 +03:00
return False ;
1998-11-12 00:37:44 +03:00
}
2009-11-30 00:23:22 +03:00
2007-11-22 04:42:52 +03:00
ret = local_password_change ( user_name , local_flags , new_passwd ,
& err_str , & msg_str ) ;
1998-11-13 02:49:32 +03:00
2007-11-22 04:42:52 +03:00
if ( msg_str )
2004-10-02 02:24:44 +04:00
printf ( " %s \n <p> " , msg_str ) ;
2007-11-22 04:42:52 +03:00
if ( err_str )
2004-10-02 02:24:44 +04:00
printf ( " %s \n <p> " , err_str ) ;
1998-11-13 02:49:32 +03:00
2007-11-22 04:42:52 +03:00
SAFE_FREE ( msg_str ) ;
SAFE_FREE ( err_str ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_IS_OK ( ret ) ;
1998-11-12 00:37:44 +03:00
}
/****************************************************************************
do the stuff required to add or change a password
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void chg_passwd ( void )
{
2003-01-03 11:28:12 +03:00
const char * host ;
2007-10-19 04:40:25 +04:00
bool rslt ;
2000-02-26 01:25:25 +03:00
int local_flags = 0 ;
1998-11-12 00:37:44 +03:00
/* Make sure users name has been specified */
2006-06-20 23:21:14 +04:00
if ( strlen ( cgi_variable_nonull ( SWAT_USER ) ) = = 0 ) {
2004-10-02 02:24:44 +04:00
printf ( " <p>%s \n " , _ ( " Must specify \" User Name \" " ) ) ;
1998-11-12 00:37:44 +03:00
return ;
}
/*
2000-02-26 01:25:25 +03:00
* smbpasswd doesn ' t require anything but the users name to delete , disable or enable the user ,
1998-11-12 00:37:44 +03:00
* so if that ' s what we ' re doing , skip the rest of the checks
*/
2000-02-26 01:25:25 +03:00
if ( ! cgi_variable ( DISABLE_USER_FLAG ) & & ! cgi_variable ( ENABLE_USER_FLAG ) & & ! cgi_variable ( DELETE_USER_FLAG ) ) {
1998-11-12 00:37:44 +03:00
1998-11-12 21:44:16 +03:00
/*
* If current user is not root , make sure old password has been specified
* If REMOTE change , even root must provide old password
*/
2006-06-20 23:21:14 +04:00
if ( ( ( ! am_root ( ) ) & & ( strlen ( cgi_variable_nonull ( OLD_PSWD ) ) < = 0 ) ) | |
( ( cgi_variable ( CHG_R_PASSWD_FLAG ) ) & & ( strlen ( cgi_variable_nonull ( OLD_PSWD ) ) < = 0 ) ) ) {
2004-10-02 02:24:44 +04:00
printf ( " <p>%s \n " , _ ( " Must specify \" Old Password \" " ) ) ;
1998-11-12 00:37:44 +03:00
return ;
}
1998-11-12 21:44:16 +03:00
/* If changing a users password on a remote hosts we have to know what host */
2006-06-20 23:21:14 +04:00
if ( ( cgi_variable ( CHG_R_PASSWD_FLAG ) ) & & ( strlen ( cgi_variable_nonull ( RHOST ) ) < = 0 ) ) {
2004-10-02 02:24:44 +04:00
printf ( " <p>%s \n " , _ ( " Must specify \" Remote Machine \" " ) ) ;
1998-11-12 21:44:16 +03:00
return ;
}
1998-11-12 00:37:44 +03:00
/* Make sure new passwords have been specified */
2006-06-20 23:21:14 +04:00
if ( ( strlen ( cgi_variable_nonull ( NEW_PSWD ) ) < = 0 ) | |
( strlen ( cgi_variable_nonull ( NEW2_PSWD ) ) < = 0 ) ) {
2004-10-02 02:24:44 +04:00
printf ( " <p>%s \n " , _ ( " Must specify \" New, and Re-typed Passwords \" " ) ) ;
1998-11-12 00:37:44 +03:00
return ;
}
/* Make sure new passwords was typed correctly twice */
2006-06-20 23:21:14 +04:00
if ( strcmp ( cgi_variable_nonull ( NEW_PSWD ) , cgi_variable_nonull ( NEW2_PSWD ) ) ! = 0 ) {
2004-10-02 02:24:44 +04:00
printf ( " <p>%s \n " , _ ( " Re-typed password didn't match new password " ) ) ;
1998-11-12 00:37:44 +03:00
return ;
}
}
1998-11-12 21:44:16 +03:00
if ( cgi_variable ( CHG_R_PASSWD_FLAG ) ) {
host = cgi_variable ( RHOST ) ;
} else if ( am_root ( ) ) {
host = NULL ;
} else {
host = " 127.0.0.1 " ;
}
2000-02-26 01:25:25 +03:00
/*
* Set up the local flags .
*/
local_flags | = ( cgi_variable ( ADD_USER_FLAG ) ? LOCAL_ADD_USER : 0 ) ;
2004-05-05 18:46:00 +04:00
local_flags | = ( cgi_variable ( ADD_USER_FLAG ) ? LOCAL_SET_PASSWORD : 0 ) ;
local_flags | = ( cgi_variable ( CHG_S_PASSWD_FLAG ) ? LOCAL_SET_PASSWORD : 0 ) ;
2000-02-26 01:25:25 +03:00
local_flags | = ( cgi_variable ( DELETE_USER_FLAG ) ? LOCAL_DELETE_USER : 0 ) ;
local_flags | = ( cgi_variable ( ENABLE_USER_FLAG ) ? LOCAL_ENABLE_USER : 0 ) ;
local_flags | = ( cgi_variable ( DISABLE_USER_FLAG ) ? LOCAL_DISABLE_USER : 0 ) ;
1998-11-12 21:44:16 +03:00
rslt = change_password ( host ,
2006-06-20 23:21:14 +04:00
cgi_variable_nonull ( SWAT_USER ) ,
cgi_variable_nonull ( OLD_PSWD ) , cgi_variable_nonull ( NEW_PSWD ) ,
2000-02-26 01:25:25 +03:00
local_flags ) ;
1998-11-12 00:37:44 +03:00
2004-05-05 18:46:00 +04:00
if ( cgi_variable ( CHG_S_PASSWD_FLAG ) ) {
2004-10-02 02:24:44 +04:00
printf ( " <p> " ) ;
2000-02-26 01:25:25 +03:00
if ( rslt = = True ) {
2006-06-20 23:21:14 +04:00
printf ( _ ( " The passwd for '%s' has been changed. " ) , cgi_variable_nonull ( SWAT_USER ) ) ;
2004-10-02 02:24:44 +04:00
printf ( " \n " ) ;
2000-02-26 01:25:25 +03:00
} else {
2006-06-20 23:21:14 +04:00
printf ( _ ( " The passwd for '%s' has NOT been changed. " ) , cgi_variable_nonull ( SWAT_USER ) ) ;
2004-10-02 02:24:44 +04:00
printf ( " \n " ) ;
2000-02-26 01:25:25 +03:00
}
1998-11-12 00:37:44 +03:00
}
2009-11-30 00:23:22 +03:00
1998-11-12 00:37:44 +03:00
return ;
}
/****************************************************************************
display a password editing page
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void passwd_page ( void )
{
2003-01-03 11:28:12 +03:00
const char * new_name = cgi_user_name ( ) ;
1998-11-12 00:37:44 +03:00
/*
* After the first time through here be nice . If the user
* changed the User box text to another users name , remember it .
*/
1998-11-14 00:41:01 +03:00
if ( cgi_variable ( SWAT_USER ) ) {
2006-06-20 23:21:14 +04:00
new_name = cgi_variable_nonull ( SWAT_USER ) ;
1998-11-12 10:32:33 +03:00
}
if ( ! new_name ) new_name = " " ;
1998-11-12 00:37:44 +03:00
2004-10-02 02:24:44 +04:00
printf ( " <H2>%s</H2> \n " , _ ( " Server Password Management " ) ) ;
1998-11-12 21:44:16 +03:00
2004-10-02 02:24:44 +04:00
printf ( " <FORM name= \" swatform \" method=post> \n " ) ;
1998-11-12 21:44:16 +03:00
2004-10-02 02:24:44 +04:00
printf ( " <table> \n " ) ;
1998-11-12 21:44:16 +03:00
/*
* Create all the dialog boxes for data collection
*/
2004-10-02 02:24:44 +04:00
printf ( " <tr><td> %s : </td> \n " , _ ( " User Name " ) ) ;
printf ( " <td><input type=text size=30 name=%s value=%s></td></tr> \n " , SWAT_USER , new_name ) ;
1998-11-14 05:14:30 +03:00
if ( ! am_root ( ) ) {
2004-10-02 02:24:44 +04:00
printf ( " <tr><td> %s : </td> \n " , _ ( " Old Password " ) ) ;
printf ( " <td><input type=password size=30 name=%s></td></tr> \n " , OLD_PSWD ) ;
1998-11-12 00:37:44 +03:00
}
2004-10-02 02:24:44 +04:00
printf ( " <tr><td> %s : </td> \n " , _ ( " New Password " ) ) ;
printf ( " <td><input type=password size=30 name=%s></td></tr> \n " , NEW_PSWD ) ;
printf ( " <tr><td> %s : </td> \n " , _ ( " Re-type New Password " ) ) ;
printf ( " <td><input type=password size=30 name=%s></td></tr> \n " , NEW2_PSWD ) ;
printf ( " </table> \n " ) ;
1998-11-12 00:37:44 +03:00
1998-11-12 21:44:16 +03:00
/*
* Create all the control buttons for requesting action
*/
2004-10-02 02:24:44 +04:00
printf ( " <input type=submit name=%s value= \" %s \" > \n " ,
2001-09-24 19:55:09 +04:00
CHG_S_PASSWD_FLAG , _ ( " Change Password " ) ) ;
1998-11-14 05:14:30 +03:00
if ( demo_mode | | am_root ( ) ) {
2004-10-02 02:24:44 +04:00
printf ( " <input type=submit name=%s value= \" %s \" > \n " ,
2001-09-24 19:55:09 +04:00
ADD_USER_FLAG , _ ( " Add New User " ) ) ;
2004-10-02 02:24:44 +04:00
printf ( " <input type=submit name=%s value= \" %s \" > \n " ,
2001-09-24 19:55:09 +04:00
DELETE_USER_FLAG , _ ( " Delete User " ) ) ;
2004-10-02 02:24:44 +04:00
printf ( " <input type=submit name=%s value= \" %s \" > \n " ,
2001-09-24 19:55:09 +04:00
DISABLE_USER_FLAG , _ ( " Disable User " ) ) ;
2004-10-02 02:24:44 +04:00
printf ( " <input type=submit name=%s value= \" %s \" > \n " ,
2001-09-24 19:55:09 +04:00
ENABLE_USER_FLAG , _ ( " Enable User " ) ) ;
1998-11-12 00:37:44 +03:00
}
2004-10-02 02:24:44 +04:00
printf ( " <p></FORM> \n " ) ;
1998-11-12 00:37:44 +03:00
/*
1998-11-27 09:09:25 +03:00
* Do some work if change , add , disable or enable was
* requested . It could be this is the first time through this
* code , so there isn ' t anything to do . */
2000-02-26 01:25:25 +03:00
if ( ( cgi_variable ( CHG_S_PASSWD_FLAG ) ) | | ( cgi_variable ( ADD_USER_FLAG ) ) | | ( cgi_variable ( DELETE_USER_FLAG ) ) | |
1998-11-12 21:44:16 +03:00
( cgi_variable ( DISABLE_USER_FLAG ) ) | | ( cgi_variable ( ENABLE_USER_FLAG ) ) ) {
chg_passwd ( ) ;
}
2004-10-02 02:24:44 +04:00
printf ( " <H2>%s</H2> \n " , _ ( " Client/Server Password Management " ) ) ;
1998-11-12 21:44:16 +03:00
2004-10-02 02:24:44 +04:00
printf ( " <FORM name= \" swatform \" method=post> \n " ) ;
1998-11-12 21:44:16 +03:00
2004-10-02 02:24:44 +04:00
printf ( " <table> \n " ) ;
1998-11-12 21:44:16 +03:00
/*
* Create all the dialog boxes for data collection
*/
2004-10-02 02:24:44 +04:00
printf ( " <tr><td> %s : </td> \n " , _ ( " User Name " ) ) ;
printf ( " <td><input type=text size=30 name=%s value=%s></td></tr> \n " , SWAT_USER , new_name ) ;
printf ( " <tr><td> %s : </td> \n " , _ ( " Old Password " ) ) ;
printf ( " <td><input type=password size=30 name=%s></td></tr> \n " , OLD_PSWD ) ;
printf ( " <tr><td> %s : </td> \n " , _ ( " New Password " ) ) ;
printf ( " <td><input type=password size=30 name=%s></td></tr> \n " , NEW_PSWD ) ;
printf ( " <tr><td> %s : </td> \n " , _ ( " Re-type New Password " ) ) ;
printf ( " <td><input type=password size=30 name=%s></td></tr> \n " , NEW2_PSWD ) ;
printf ( " <tr><td> %s : </td> \n " , _ ( " Remote Machine " ) ) ;
printf ( " <td><input type=text size=30 name=%s></td></tr> \n " , RHOST ) ;
printf ( " </table> " ) ;
1998-11-27 09:09:25 +03:00
1998-11-12 21:44:16 +03:00
/*
* Create all the control buttons for requesting action
*/
2004-10-02 02:24:44 +04:00
printf ( " <input type=submit name=%s value= \" %s \" > " ,
2001-09-24 19:55:09 +04:00
CHG_R_PASSWD_FLAG , _ ( " Change Password " ) ) ;
1998-11-27 09:09:25 +03:00
2004-10-02 02:24:44 +04:00
printf ( " <p></FORM> \n " ) ;
1998-11-12 21:44:16 +03:00
/*
1998-11-27 09:09:25 +03:00
* Do some work if a request has been made to change the
* password somewhere other than the server . It could be this
* is the first time through this code , so there isn ' t
* anything to do . */
1998-11-12 21:44:16 +03:00
if ( cgi_variable ( CHG_R_PASSWD_FLAG ) ) {
1998-11-12 00:37:44 +03:00
chg_passwd ( ) ;
}
}
/****************************************************************************
display a printers editing page
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-03-08 17:14:49 +03:00
static void printers_page ( void )
{
2003-01-03 11:28:12 +03:00
const char * share = cgi_variable ( " share " ) ;
1998-03-08 17:14:49 +03:00
char * s ;
int snum = - 1 ;
int i ;
2002-09-25 19:19:00 +04:00
int mode = 0 ;
unsigned int parm_filter = FLAG_BASIC ;
1998-03-08 17:14:49 +03:00
if ( share )
snum = lp_servicenumber ( share ) ;
2004-10-02 02:24:44 +04:00
printf ( " <H2>%s</H2> \n " , _ ( " Printer Parameters " ) ) ;
2001-09-24 19:55:09 +04:00
2004-10-02 02:24:44 +04:00
printf ( " <H3>%s</H3> \n " , _ ( " Important Note: " ) ) ;
2008-12-31 05:24:39 +03:00
printf ( " %s " , _ ( " Printer names marked with [*] in the Choose Printer drop-down box " ) ) ;
printf ( " %s " , _ ( " are autoloaded printers from " ) ) ;
2004-10-02 02:24:44 +04:00
printf ( " <A HREF= \" /swat/help/smb.conf.5.html#printcapname \" target= \" docs \" >%s</A> \n " , _ ( " Printcap Name " ) ) ;
printf ( " %s \n " , _ ( " Attempting to delete these printers from SWAT will have no effect. " ) ) ;
1999-12-13 16:27:58 +03:00
1998-03-08 17:14:49 +03:00
if ( cgi_variable ( " Commit " ) & & snum > = 0 ) {
commit_parameters ( snum ) ;
1999-12-13 16:27:58 +03:00
if ( snum > = iNumNonAutoPrintServices )
save_reload ( snum ) ;
else
2009-11-30 01:31:45 +03:00
save_reload ( - 1 ) ;
2008-07-16 01:37:48 +04:00
snum = lp_servicenumber ( share ) ;
1998-03-08 17:14:49 +03:00
}
if ( cgi_variable ( " Delete " ) & & snum > = 0 ) {
lp_remove_service ( snum ) ;
2009-11-30 01:31:45 +03:00
save_reload ( - 1 ) ;
1998-03-08 17:14:49 +03:00
share = NULL ;
snum = - 1 ;
}
if ( cgi_variable ( " createshare " ) & & ( share = cgi_variable ( " newshare " ) ) ) {
snum = lp_servicenumber ( share ) ;
2008-07-16 01:37:48 +04:00
if ( snum < 0 | | snum > = iNumNonAutoPrintServices ) {
load_config ( False ) ;
lp_copy_service ( GLOBAL_SECTION_SNUM , share ) ;
snum = lp_servicenumber ( share ) ;
lp_do_parameter ( snum , " print ok " , " Yes " ) ;
save_reload ( snum ) ;
snum = lp_servicenumber ( share ) ;
}
1998-03-08 17:14:49 +03:00
}
2004-10-02 02:24:44 +04:00
printf ( " <FORM name= \" swatform \" method=post> \n " ) ;
1998-03-08 17:14:49 +03:00
2002-09-25 19:19:00 +04:00
if ( cgi_variable ( " ViewMode " ) )
2006-06-20 23:21:14 +04:00
mode = atoi ( cgi_variable_nonull ( " ViewMode " ) ) ;
2003-07-27 23:49:23 +04:00
if ( cgi_variable ( " BasicMode " ) )
mode = 0 ;
if ( cgi_variable ( " AdvMode " ) )
mode = 1 ;
2002-09-25 19:19:00 +04:00
ViewModeBoxes ( mode ) ;
switch ( mode ) {
case 0 :
parm_filter = FLAG_BASIC ;
break ;
case 1 :
parm_filter = FLAG_ADVANCED ;
break ;
}
2004-10-02 02:24:44 +04:00
printf ( " <table> \n " ) ;
printf ( " <tr><td><input type=submit name= \" selectshare \" value= \" %s \" ></td> \n " , _ ( " Choose Printer " ) ) ;
printf ( " <td><select name= \" share \" > \n " ) ;
1998-03-08 17:14:49 +03:00
if ( snum < 0 | | ! lp_print_ok ( snum ) )
2004-10-02 02:24:44 +04:00
printf ( " <option value= \" \" > \n " ) ;
1998-03-08 17:14:49 +03:00
for ( i = 0 ; i < lp_numservices ( ) ; i + + ) {
s = lp_servicename ( i ) ;
if ( s & & ( * s ) & & strcmp ( s , " IPC$ " ) & & lp_print_ok ( i ) ) {
1999-12-13 16:27:58 +03:00
if ( i > = iNumNonAutoPrintServices )
2004-10-02 02:24:44 +04:00
printf ( " <option %s value= \" %s \" >[*]%s \n " ,
1999-12-13 16:27:58 +03:00
( share & & strcmp ( share , s ) = = 0 ) ? " SELECTED " : " " ,
s , s ) ;
else
2004-10-02 02:24:44 +04:00
printf ( " <option %s value= \" %s \" >%s \n " ,
1998-03-08 17:14:49 +03:00
( share & & strcmp ( share , s ) = = 0 ) ? " SELECTED " : " " ,
s , s ) ;
}
}
2004-10-02 02:24:44 +04:00
printf ( " </select></td> " ) ;
1999-12-13 16:27:58 +03:00
if ( have_write_access ) {
2004-10-02 02:24:44 +04:00
printf ( " <td><input type=submit name= \" Delete \" value= \" %s \" ></td> \n " , _ ( " Delete Printer " ) ) ;
1999-12-13 16:27:58 +03:00
}
2004-10-02 02:24:44 +04:00
printf ( " </tr> " ) ;
printf ( " </table> \n " ) ;
1998-03-08 17:14:49 +03:00
1999-12-13 16:27:58 +03:00
if ( have_write_access ) {
2004-10-02 02:24:44 +04:00
printf ( " <table> \n " ) ;
printf ( " <tr><td><input type=submit name= \" createshare \" value= \" %s \" ></td> \n " , _ ( " Create Printer " ) ) ;
printf ( " <td><input type=text size=30 name= \" newshare \" ></td></tr> \n " ) ;
printf ( " </table> " ) ;
1999-12-13 16:27:58 +03:00
}
1998-03-08 17:14:49 +03:00
if ( snum > = 0 ) {
1998-11-14 05:29:38 +03:00
if ( have_write_access ) {
2004-10-02 02:24:44 +04:00
printf ( " <input type=submit name= \" Commit \" value= \" %s \" > \n " , _ ( " Commit Changes " ) ) ;
1998-11-14 05:29:38 +03:00
}
2004-10-02 02:24:44 +04:00
printf ( " <input type=reset name= \" Reset Values \" value= \" %s \" > \n " , _ ( " Reset Values " ) ) ;
printf ( " <p> \n " ) ;
1998-03-08 17:14:49 +03:00
}
if ( snum > = 0 ) {
2004-10-02 02:24:44 +04:00
printf ( " <table> \n " ) ;
2002-09-25 19:19:00 +04:00
show_parameters ( snum , 1 , parm_filter , 1 ) ;
2004-10-02 02:24:44 +04:00
printf ( " </table> \n " ) ;
1998-03-08 17:14:49 +03:00
}
2004-10-02 02:24:44 +04:00
printf ( " </FORM> \n " ) ;
1998-03-08 17:14:49 +03:00
}
2007-08-27 15:41:05 +04:00
/*
when the _ ( ) translation macro is used there is no obvious place to free
the resulting string and there is no easy way to give a static pointer .
All we can do is rotate between some static buffers and hope a single d_printf ( )
doesn ' t have more calls to _ ( ) than the number of buffers
*/
2007-12-04 04:17:05 +03:00
const char * lang_msg_rotate ( TALLOC_CTX * ctx , const char * msgid )
2007-08-27 15:41:05 +04:00
{
2007-12-04 04:17:05 +03:00
const char * msgstr ;
const char * ret ;
2007-08-27 15:41:05 +04:00
2007-12-04 04:17:05 +03:00
msgstr = lang_msg ( msgid ) ;
if ( ! msgstr ) {
return msgid ;
}
2007-08-27 15:41:05 +04:00
2007-12-04 04:17:05 +03:00
ret = talloc_strdup ( ctx , msgstr ) ;
2007-08-27 15:41:05 +04:00
2007-12-04 04:17:05 +03:00
lang_msg_free ( msgstr ) ;
if ( ! ret ) {
return msgid ;
}
2007-08-27 15:41:05 +04:00
2007-12-04 04:17:05 +03:00
return ret ;
2007-08-27 15:41:05 +04:00
}
2001-11-19 05:49:53 +03:00
/**
* main function for SWAT .
* */
1998-09-21 15:34:44 +04:00
int main ( int argc , char * argv [ ] )
1998-03-08 17:14:49 +03:00
{
2003-04-03 05:51:13 +04:00
const char * page ;
2003-03-20 14:16:14 +03:00
poptContext pc ;
struct poptOption long_options [ ] = {
POPT_AUTOHELP
2003-03-26 06:40:24 +03:00
{ " disable-authentication " , ' a ' , POPT_ARG_VAL , & demo_mode , True , " Disable authentication (demo mode) " } ,
2005-08-30 15:41:45 +04:00
{ " password-menu-only " , ' P ' , POPT_ARG_VAL , & passwd_only , True , " Show only change password menu " } ,
2003-04-14 07:30:20 +04:00
POPT_COMMON_SAMBA
POPT_TABLEEND
2003-03-20 14:16:14 +03:00
} ;
2007-11-16 01:19:52 +03:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
1998-03-08 17:14:49 +03:00
1999-12-13 16:27:58 +03:00
fault_setup ( NULL ) ;
2001-05-30 10:12:21 +04:00
umask ( S_IWGRP | S_IWOTH ) ;
1999-12-13 16:27:58 +03:00
# if defined(HAVE_SET_AUTH_PARAMETERS)
set_auth_parameters ( argc , argv ) ;
# endif /* HAVE_SET_AUTH_PARAMETERS */
1998-03-08 17:14:49 +03:00
/* just in case it goes wild ... */
alarm ( 300 ) ;
2001-10-14 16:10:29 +04:00
setlinebuf ( stdout ) ;
2000-04-11 11:14:12 +04:00
/* we don't want any SIGPIPE messages */
BlockSignals ( True , SIGPIPE ) ;
2010-10-29 07:19:32 +04:00
debug_set_logfile ( " /dev/null " ) ;
1998-03-08 17:14:49 +03:00
1999-12-13 16:27:58 +03:00
/* we don't want stderr screwing us up */
close ( 2 ) ;
open ( " /dev/null " , O_WRONLY ) ;
2010-10-29 07:19:32 +04:00
setup_logging ( " swat " , DEBUG_FILE ) ;
1999-12-13 16:27:58 +03:00
2010-10-29 14:10:31 +04:00
load_case_tables ( ) ;
2003-03-20 14:16:14 +03:00
pc = poptGetContext ( " swat " , argc , ( const char * * ) argv , long_options , 0 ) ;
/* Parse command line options */
2005-08-30 15:41:45 +04:00
while ( poptGetNextOpt ( pc ) ! = - 1 ) { }
2003-03-20 14:16:14 +03:00
poptFreeContext ( pc ) ;
1998-03-08 17:14:49 +03:00
2010-10-29 07:19:32 +04:00
/* This should set a more apporiate log file */
1999-12-13 16:27:58 +03:00
load_config ( True ) ;
2010-10-29 07:19:32 +04:00
reopen_logs ( ) ;
2006-01-26 00:58:06 +03:00
load_interfaces ( ) ;
1999-12-13 16:27:58 +03:00
iNumNonAutoPrintServices = lp_numservices ( ) ;
2010-12-23 14:14:21 +03:00
if ( pcap_cache_loaded ( ) ) {
load_printers ( server_event_context ( ) ,
server_messaging_context ( ) ) ;
}
1998-11-21 04:41:14 +03:00
2007-12-10 22:30:37 +03:00
cgi_setup ( get_dyn_SWATDIR ( ) , ! demo_mode ) ;
1998-03-08 17:14:49 +03:00
print_header ( ) ;
2001-09-24 19:55:09 +04:00
2001-09-24 08:49:14 +04:00
cgi_load_variables ( ) ;
1998-03-08 17:14:49 +03:00
2008-10-17 14:48:19 +04:00
if ( ! file_exist ( get_dyn_CONFIGFILE ( ) ) ) {
1999-12-13 16:27:58 +03:00
have_read_access = True ;
have_write_access = True ;
} else {
/* check if the authenticated user has write access - if not then
don ' t show write options */
2007-12-10 22:30:37 +03:00
have_write_access = ( access ( get_dyn_CONFIGFILE ( ) , W_OK ) = = 0 ) ;
1999-12-13 16:27:58 +03:00
/* if the user doesn't have read access to smb.conf then
don ' t let them view it */
2007-12-10 22:30:37 +03:00
have_read_access = ( access ( get_dyn_CONFIGFILE ( ) , R_OK ) = = 0 ) ;
1999-12-13 16:27:58 +03:00
}
2005-12-20 05:23:51 +03:00
show_main_buttons ( ) ;
1998-03-08 17:14:49 +03:00
2005-12-20 05:23:51 +03:00
page = cgi_pathinfo ( ) ;
2005-09-30 21:13:37 +04:00
2005-12-20 05:23:51 +03:00
/* Root gets full functionality */
if ( have_read_access & & strcmp ( page , " globals " ) = = 0 ) {
globals_page ( ) ;
1999-12-13 16:27:58 +03:00
} else if ( have_read_access & & strcmp ( page , " shares " ) = = 0 ) {
1998-11-14 05:14:30 +03:00
shares_page ( ) ;
1999-12-13 16:27:58 +03:00
} else if ( have_read_access & & strcmp ( page , " printers " ) = = 0 ) {
1998-11-14 05:14:30 +03:00
printers_page ( ) ;
1999-12-13 16:27:58 +03:00
} else if ( have_read_access & & strcmp ( page , " status " ) = = 0 ) {
1998-11-14 05:14:30 +03:00
status_page ( ) ;
2005-12-20 05:23:51 +03:00
} else if ( have_read_access & & strcmp ( page , " viewconfig " ) = = 0 ) {
viewconfig_page ( ) ;
1998-11-14 05:14:30 +03:00
} else if ( strcmp ( page , " passwd " ) = = 0 ) {
passwd_page ( ) ;
2002-09-25 19:19:00 +04:00
} else if ( have_read_access & & strcmp ( page , " wizard " ) = = 0 ) {
wizard_page ( ) ;
} else if ( have_read_access & & strcmp ( page , " wizard_params " ) = = 0 ) {
wizard_params_page ( ) ;
2005-12-20 05:23:51 +03:00
} else if ( have_read_access & & strcmp ( page , " rewritecfg " ) = = 0 ) {
rewritecfg_file ( ) ;
1998-03-08 17:14:49 +03:00
} else {
1998-11-14 05:14:30 +03:00
welcome_page ( ) ;
1998-03-08 17:14:49 +03:00
}
1998-11-14 05:14:30 +03:00
1998-03-08 17:14:49 +03:00
print_footer ( ) ;
2007-11-16 01:19:52 +03:00
TALLOC_FREE ( frame ) ;
1998-03-08 17:14:49 +03:00
return 0 ;
}
2001-11-19 05:49:53 +03:00
/** @} **/