home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1999 March B
/
SCO_CASTOR4RRT.iso
/
inet
/
root.2
/
usr
/
lib
/
scoadmin
/
netosa
/
ftpOsa
/
ftpOsa~
Wrap
Text File
|
1998-08-19
|
99KB
|
3,817 lines
# Copyright (c) 1992-1998 The Santa Cruz Operation, Inc.. All Rights Reserved.
#
# THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE
# SANTA CRUZ OPERATION INC.
#
# The copyright notice above does not evidence any actual or intended
# publication of such source code.
#******************************************************************************
#
# Copyright (C) 1992-1998 The Santa Cruz Operation, Inc.
# All Rights Reserved.
#
# The information in this file is provided for the exclusive use of
# the licensees of The Santa Cruz Operation, Inc. Such users have the
# right to use, modify, and incorporate this code into other products
# for purposes authorized by the license agreement provided they include
# this notice and the associated copyright notice with any such product.
# The information in this file is provided "AS IS" without warranty.
#
#===============================================================================
#@package: SCO_FTPOSA_MSGS SCO_FTPOSA_MSGS
proc SCO_FTPOSA_MSGS {} {}
global SCO_FTPOSA_MSGS
set SCO_FTPOSA_MSGS(@catalog@) {ftpOsa.cat@sa 1}
set SCO_FTPOSA_MSGS(ERR_CONFIG) {1 {Configuration error}}
set SCO_FTPOSA_MSGS(ERR_SYNTAX) {2 {Syntax error in configuration file ftpaccess near : %1s}}
set SCO_FTPOSA_MSGS(ERR_BUG_ERR) {3 {Syntax error in configuration file}}
set SCO_FTPOSA_MSGS(ERR_OPEN_SHUTDOWN_FILE) {4 {Unable to open shutdown file}}
set SCO_FTPOSA_MSGS(ERR_SHUTDOWN_SYNTAX) {5 {Syntax error in shutdown file %1s}}
set SCO_FTPOSA_MSGS(ERR_SHUTDOWN_SYNTAX2) {6 {Syntax error in shutdown file %1$s near : %2$s}}
set SCO_FTPOSA_MSGS(ERR_ANON_CREATE) {7 {Failed to create the anonymous FTP user account}}
set SCO_FTPOSA_MSGS(ERR_ANON_MODIFY) {8 {Failed to modify the anonymous FTP user account}}
set SCO_FTPOSA_MSGS(ERR_ANON_MODIFY_AGED) {9 {Failed to modify the anonymous FTP user account\nUser ID has not aged sufficently, choose another.}}
set SCO_FTPOSA_MSGS(ERR_ANON_DELETE) {10 {Failed to delete the anonymous FTP user account}}
set SCO_FTPOSA_MSGS(ERR_ANON_INVALID_ACTION) {11 {Invalid action on anonymous FTP user account}}
set sco_ftpShutdown_CDT(attributes) {
{
year
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
month
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
day
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
deny_offset
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
{ description HHMM }
}
}
{
disc_offset
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
{ description HHMM }
}
}
{
stext
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
{ description {Shutdown message. A list of lists, where one list corresponds to one line.} }
}
}
{
hour
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
minute
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
}
set sco_ftpShutdown_CDT(groups) {}
set sco_ftpShutdown_CDT(operations) {
{
get
{
{ granularity perObject }
{ function ftpShutdown_get }
}
}
{
replace
{
{ granularity perObject }
{ function ftpShutdown_create }
}
}
{
delete
{
{ function ftpShutdown_delete }
{ granularity perObject }
}
}
{
create
{
{ function ftpShutdown_create }
{ granularity perObject }
}
}
{
action
{
{ function ftpShutdown_action }
{ granularity perObject }
}
}
}
set sco_ftpShutdown_CDT(class) {sco ftpShutdown}
set sco_ftpShutdown_CDT(superior) {}
set sco_ftpShutdown_CDT(subordinates) {}
set sco_ftpDenyHost_CDT(attributes) {
{
host
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
file
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
}
set sco_ftpDenyHost_CDT(groups) {}
set sco_ftpDenyHost_CDT(operations) {
{
get
{
{ granularity perAttribute }
{ function ftpDenyHost_get }
}
}
{
replace
{
{ granularity perObject }
{ function ftpDenyHost_replace }
}
}
{
create
{
{ function ftpDenyHost_create }
{ granularity perObject }
}
}
{
delete
{
{ function ftpDenyHost_delete }
{ granularity perObject }
}
}
{
list
{
{ granularity perObject }
{ function ftpDenyHost_list }
}
}
}
set sco_ftpDenyHost_CDT(class) {sco ftpDenyHost}
set sco_ftpDenyHost_CDT(superior) {sco ftp}
set sco_ftpDenyHost_CDT(subordinates) {{sco ftpDenyHost}}
set sco_ftpVirtual_CDT(attributes) {
{
address
{
{ validOperations {get} }
{ validFilters {} }
{ dataType single }
}
}
{
banner
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
root
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
logfile
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
}
set sco_ftpVirtual_CDT(groups) {}
set sco_ftpVirtual_CDT(operations) {
{
delete
{
{ function ftpVirtual_delete }
{ granularity perObject }
}
}
{
list
{
{ granularity perObject }
{ function ftpVirtual_list }
}
}
{
replace
{
{ granularity perObject }
{ function ftpVirtual_replace }
}
}
{
get
{
{ granularity perAttribute }
{ function ftpVirtual_get }
}
}
{
create
{
{ function ftpVirtual_create }
{ granularity perObject }
}
}
}
set sco_ftpVirtual_CDT(class) {sco ftpVirtual}
set sco_ftpVirtual_CDT(superior) {sco ftp}
set sco_ftpVirtual_CDT(subordinates) {{sco ftpVirtual}}
set sco_ftpMessage_CDT(attributes) {
{
file
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
{ description {path to message file} }
}
}
{
type
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
{ description {type of message
(readme or message)} }
}
}
{
when
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
{ description {when to display message} }
}
}
{
class
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
{ description {only display readme to members of this class} }
}
}
}
set sco_ftpMessage_CDT(groups) {}
set sco_ftpMessage_CDT(operations) {
{
get
{
{ granularity perAttribute }
{ function ftpMessage_get }
}
}
{
replace
{
{ granularity perObject }
{ function ftpMessage_replace }
}
}
{
create
{
{ function ftpMessage_create }
{ granularity perObject }
}
}
{
delete
{
{ function ftpMessage_delete }
{ granularity perObject }
}
}
{
list
{
{ granularity perObject }
{ function ftpMessage_list }
}
}
}
set sco_ftpMessage_CDT(class) {sco ftpMessage}
set sco_ftpMessage_CDT(superior) {sco ftp}
set sco_ftpMessage_CDT(subordinates) {{sco ftpMessage}}
set sco_ftpAccess_CDT(attributes) {
{
home
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
dir
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
upload
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
{ syntax boolean }
}
}
{
owner
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
group
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
mode
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
subdirs
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
{ syntax boolean }
}
}
}
set sco_ftpAccess_CDT(groups) {}
set sco_ftpAccess_CDT(operations) {
{
get
{
{ granularity perAttribute }
{ function ftpAccess_get }
}
}
{
replace
{
{ granularity perObject }
{ function ftpAccess_replace }
}
}
{
create
{
{ function ftpAccess_create }
{ granularity perObject }
}
}
{
delete
{
{ function ftpAccess_delete }
{ granularity perObject }
}
}
{
list
{
{ granularity perObject }
{ function ftpAccess_list }
}
}
}
set sco_ftpAccess_CDT(class) {sco ftpAccess}
set sco_ftpAccess_CDT(superior) {sco ftp}
set sco_ftpAccess_CDT(subordinates) {{sco ftpAccess}}
set sco_ftpLog_CDT(attributes) {
{
current_time
{
{ validOperations get }
{ validFilters {} }
{ dataType single }
}
}
{
transfer_time
{
{ validOperations get }
{ validFilters {} }
{ dataType single }
}
}
{
remote_host
{
{ validOperations get }
{ validFilters {} }
{ dataType single }
}
}
{
file_size
{
{ validOperations get }
{ validFilters {} }
{ dataType single }
}
}
{
filename
{
{ validOperations get }
{ validFilters {} }
{ dataType single }
}
}
{
transfer_type
{
{ validOperations get }
{ validFilters {} }
{ dataType single }
}
}
{
action
{
{ validOperations get }
{ validFilters {} }
{ dataType single }
}
}
{
direction
{
{ validOperations get }
{ validFilters {} }
{ dataType single }
}
}
{
access_mode
{
{ validOperations get }
{ validFilters {} }
{ dataType single }
}
}
{
username
{
{ validOperations get }
{ validFilters {} }
{ dataType single }
}
}
{
service_name
{
{ validOperations get }
{ validFilters {} }
{ dataType single }
}
}
{
auth_method
{
{ validOperations get }
{ validFilters {} }
{ dataType single }
}
}
{
user_id
{
{ validOperations get }
{ validFilters {} }
{ dataType single }
}
}
{
domain
{
{ validOperations get }
{ validFilters {} }
{ dataType single }
{ description {address of virtual domain or localhost} }
}
}
}
set sco_ftpLog_CDT(groups) {}
set sco_ftpLog_CDT(operations) {
{
get
{
{ granularity perObject }
{ function ftpLog_get }
}
}
{
action
{
{ function ftpLog_action }
{ granularity perObject }
}
}
}
set sco_ftpLog_CDT(class) {sco ftpLog}
set sco_ftpLog_CDT(superior) {}
set sco_ftpLog_CDT(subordinates) {}
set sco_ftpAnon_CDT(attributes) {
{
home
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
uid
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
}
set sco_ftpAnon_CDT(groups) {}
set sco_ftpAnon_CDT(operations) {
{
get
{
{ granularity perAttribute }
{ function ftpAnon_get }
}
}
{
replace
{
{ granularity perObject }
{ function ftpAnon_replace }
}
}
{
action
{
{ function ftpAnon_action }
{ granularity perObject }
}
}
}
set sco_ftpAnon_CDT(class) {sco ftpAnon}
set sco_ftpAnon_CDT(superior) {}
set sco_ftpAnon_CDT(subordinates) {}
set sco_ftpAnonHome_CDT(attributes) {}
set sco_ftpAnonHome_CDT(groups) {}
set sco_ftpAnonHome_CDT(operations) {
{
action
{
{ function ftpAnonHome_action }
{ granularity perObject }
}
}
}
set sco_ftpAnonHome_CDT(class) {sco ftpAnonHome}
set sco_ftpAnonHome_CDT(superior) {}
set sco_ftpAnonHome_CDT(subordinates) {}
set sco_ftpLimit_CDT(attributes) {
{
limitID
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
class
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
users
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
times
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
file
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
}
set sco_ftpLimit_CDT(groups) {}
set sco_ftpLimit_CDT(operations) {
{
get
{
{ granularity perAttribute }
{ function ftpLimit_get }
}
}
{
replace
{
{ granularity perObject }
{ function ftpLimit_replace }
}
}
{
delete
{
{ function ftpLimit_delete }
{ granularity perObject }
}
}
{
create
{
{ function ftpLimit_create }
{ granularity perObject }
}
}
{
list
{
{ granularity perObject }
{ function ftpLimit_list }
}
}
}
set sco_ftpLimit_CDT(class) {sco ftpLimit}
set sco_ftpLimit_CDT(superior) {sco ftp}
set sco_ftpLimit_CDT(subordinates) {{sco ftpLimit}}
set sco_ftpDenyUser_CDT(attributes) {
{
denied
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
user
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
}
set sco_ftpDenyUser_CDT(groups) {}
set sco_ftpDenyUser_CDT(operations) {
{
get
{
{ granularity perAttribute }
{ function ftpDenyUser_get }
}
}
{
replace
{
{ granularity perObject }
{ function ftpDenyUser_replace }
}
}
{
create
{
{ function ftpDenyUser_create }
{ granularity perObject }
}
}
{
delete
{
{ function ftpDenyUser_delete }
{ granularity perObject }
}
}
{
list
{
{ granularity perObject }
{ function ftpDenyUser_list }
}
}
}
set sco_ftpDenyUser_CDT(class) {sco ftpDenyUser}
set sco_ftpDenyUser_CDT(superior) {sco ftp}
set sco_ftpDenyUser_CDT(subordinates) {{sco ftpDenyUser}}
set sco_ftp_CDT(attributes) {
{
guestgroup
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType set }
}
}
{
loginfails
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
private
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
email
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
log_commands
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType set }
}
}
{
log_incoming
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType set }
}
}
{
log_outgoing
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType set }
}
}
{
shutdown
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
chmod
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType set }
}
}
{
delete
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType set }
}
}
{
overwrite
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType set }
}
}
{
passwd_check
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
banner
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
{
timeout
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
{ description {session timeout} }
}
}
{
maxtime
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
{ description {max session timeout} }
}
}
}
set sco_ftp_CDT(groups) {}
set sco_ftp_CDT(operations) {
{
get
{
{ granularity perAttribute }
{ function ftp_get }
}
}
{
replace
{
{ granularity perAttribute }
{ function ftp_replace }
}
}
{
list
{
{ granularity perObject }
{ function ftp_list }
}
}
{
action
{
{ function ftp_action }
{ granularity perObject }
}
}
}
set sco_ftp_CDT(class) {sco ftp}
set sco_ftp_CDT(superior) {sco ftp}
set sco_ftp_CDT(subordinates) {{sco ftpDenyHost} {sco ftpVirtual} {sco ftpMessage} {sco ftpAccess} {sco ftpLimit} {sco ftpDenyUser} {sco ftpClass}}
set sco_ftpClass_CDT(attributes) {
{
typeList
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType set }
}
}
{
addrList
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType set }
}
}
{
autogroup
{
{ validOperations {get replace} }
{ validFilters {} }
{ dataType single }
}
}
}
set sco_ftpClass_CDT(groups) {}
set sco_ftpClass_CDT(operations) {
{
get
{
{ granularity perAttribute }
{ function ftpClass_get }
}
}
{
replace
{
{ granularity perObject }
{ function ftpClass_replace }
}
}
{
create
{
{ function ftpClass_create }
{ granularity perObject }
}
}
{
delete
{
{ function ftpClass_delete }
{ granularity perObject }
}
}
{
list
{
{ granularity perObject }
{ function ftpClass_list }
}
}
}
set sco_ftpClass_CDT(class) {sco ftpClass}
set sco_ftpClass_CDT(superior) {sco ftp}
set sco_ftpClass_CDT(subordinates) {{sco ftpClass}}
proc copy_file {oldname newname} {
global isOwner
if {![file isfile $oldname]} {
return 0
}
if {$isOwner} {
CallNonStdCmd /sbin/tfadmin "cpfile $oldname $newname" SCO_FTPOSA_ERR_CONFIG errStack
} else {
CallNonStdCmd /bin/cp "$oldname $newname" SCO_FTPOSA_ERR_CONFIG errStack
}
return 0
}
proc move_file {oldname newname} {
global isOwner
if {![file isfile $oldname]} {
return 0
}
if {$isOwner} {
CallNonStdCmd /sbin/tfadmin "cpfile $oldname $newname" SCO_FTPOSA_ERR_CONFIG errStack
CallNonStdCmd /sbin/tfadmin "swUser root /bin/rm -f $oldname" SCO_FTPOSA_ERR_CONFIG errStack
} else {
CallNonStdCmd /bin/cp "$oldname $newname" SCO_FTPOSA_ERR_CONFIG errStack
CallNonStdCmd /bin/rm "-f $oldname" SCO_FTPOSA_ERR_CONFIG errStack
}
return 0
}
proc backup_file {name} {
copy_file $name $name-
}
proc log:exists { path } {
return [expr {[file exists $path] && [file readable $path]}]
}
proc logRead {} {
global ftp_log ftp_virtual ftp_Logfile ftp_Loglen ftp_Logmask isOwner
set active_logs ""
if {[log:exists $ftp_Logfile]} {
if {$isOwner} {
if {! [catch {open "|/sbin/tfadmin readfile $ftp_Logfile" r} fd(primary)]} {
set active_logs primary
set active_files(primary) $ftp_Logfile
}
} else {
if {! [catch {open $ftp_Logfile r} fd(primary)]} {
set active_logs primary
set active_files(primary) $ftp_Logfile
}
}
}
if {[info exists ftp_virtual]} {
foreach domain [array names ftp_virtual] {
keylget ftp_virtual($domain) logfile filename
if {$filename == ""} {
continue
}
if {[log:exists $filename]} {
if {$isOwner} {
if {[catch {open "|/sbin/tfadmin readfile $filename" r} fd($domain)]} {
continue
}
} else {
if {[catch {open $filename r} fd($domain)]} {
continue
}
}
lappend active_logs $domain
set active_files($domain) $filename
}
}
}
set active_logs [intersect $active_logs $ftp_Logmask]
if {[lempty active_logs]} {
return {}
}
set ftp_log {}
set need_lines $active_logs
while {![lempty $active_logs]} {
foreach log $need_lines {
if {[gets $fd($log) line($log)] == -1} {
close $fd($log)
lvarpop active_logs [lsearch $active_logs $log]
} else {
set rec_time [lrange $line($log) 0 4]
set timestamp($log) [convertclock "$rec_time"]
}
}
if {[lempty $active_logs]} {
break
}
set need_lines ""
set least_log [lindex $active_logs 0]
set least_timestamp $timestamp($least_log)
foreach log $active_logs {
if {$timestamp($log) < $least_timestamp} {
set least_log $log
set least_timestamp $timestamp($log)
}
}
if {$least_log != ""} {
set need_lines $least_log
set fields $line($least_log)
set rec {}
keylset rec domain $least_log
keylset rec current_time [lrange $fields 0 4]
keylset rec transfer_time [lindex $fields 5]
keylset rec remote_host [lindex $fields 6]
keylset rec file_size [lindex $fields 7]
keylset rec filename [lindex $fields 8]
keylset rec transfer_type [lindex $fields 9]
keylset rec action [lindex $fields 10]
keylset rec direction [lindex $fields 11]
keylset rec access_mode [lindex $fields 12]
keylset rec username [lindex $fields 13]
keylset rec service_name [lindex $fields 14]
keylset rec auth_method [lindex $fields 15]
keylset rec user_id [lindex $fields 16]
lappend ftp_log $rec
if {$ftp_Loglen > 0 && [llength $ftp_log] >= $ftp_Loglen} {
lvarpop ftp_log
}
} else {
error "there are log files but no next record"
}
}
}
proc setup_ftp_scancontexts {} {
global ftp_scontext
set ftp_scontext [scancontext create]
scanmatch $ftp_scontext {^} {
global ftp_lines ftp_lineindexes
set lineindex $matchInfo(handle).$matchInfo(linenum)
lappend ftp_lineindexes $lineindex
set ftp_lines($lineindex) $matchInfo(line)
}
scanmatch $ftp_scontext {(^[ ]*;)|(^[ ]*$)|(^[ ]*#)} {
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*loginfails[ $]} {
global ftp_loginfails
if {[llength $matchInfo(line)] < 2} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
} else {
set ftp_loginfails($lineindex) [lindex $matchInfo(line) 1]
}
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*private[ $]} {
global ftp_private
if {[llength $matchInfo(line)] < 2} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
} else {
set ftp_private($lineindex) [lindex $matchInfo(line) 1]
}
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*banner[ $]} {
global ftp_banner
if {[llength $matchInfo(line)] < 2} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
} else {
set ftp_banner($lineindex) [lindex $matchInfo(line) 1]
}
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*email[ $]} {
global ftp_email
if {[llength $matchInfo(line)] < 2} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
} else {
set ftp_email($lineindex) [lindex $matchInfo(line) 1]
}
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*shutdown[ $]} {
global ftp_shutdown
if {[llength $matchInfo(line)] < 2} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
} else {
set ftp_shutdown($lineindex) [lindex $matchInfo(line) 1]
}
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*virtual[ $]} {
global ftp_virtual ftp_virtual_lines
set line $matchInfo(line)
if {[llength $line] < 4} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
set address [lindex $line 1]
set token [lindex $line 2]
set path [lindex $line 3]
if {[lsearch [list root type banner logfile] $token] == -1} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
if [info exists ftp_virtual($address)] {
set record $ftp_virtual($address)
set record_lines $ftp_virtual_lines($address)
} else {
set record {{banner ""} {root ""} {logfile ""}}
set record_lines {{banner ""} {root ""} {logfile ""}}
}
keylset record_lines $token $lineindex
keylset record $token $path
set ftp_virtual_lines($address) $record_lines
set ftp_virtual($address) $record
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*class[ $]} {
global ftp_classes
set line $matchInfo(line)
if {[llength $line] < 4} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
set class [lindex $line 1]
if [info exists ftp_classes($class)] {
set record $ftp_classes($class)
keylget record lines lines
lappend lines $lineindex
keylset record lines $lines
} else {
set record {}
keylset record groups {}
keylset record lines $lineindex
}
keylset record typelist [split [lindex $line 2] ","]
keylset record addrs [lrange $line 3 end]
set ftp_classes($class) $record
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*autogroup[ $]} {
global ftp_classes
set line $matchInfo(line)
if {[llength $line] < 3} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
foreach class [lrange $line 2 end] {
if [info exists ftp_classes($class)] {
set record $ftp_classes($class)
keylget record groups groups
lappend groups [lindex $line 1]
keylset record groups $groups
keylget record lines lines
lappend lines $lineindex
keylset record lines $lines
} else {
set record {}
keylset record lines $lineindex
keylset record typelist {}
keylset record addrs {}
keylset record groups [lindex $line 1]
}
set ftp_classes($class) $record
}
}
scanmatch -nocase $ftp_scontext {^[ ]*deny[ $]} {
global ftp_deny_hosts
if { ! [regsub {;.*$} $matchInfo(line) {} line]} {
set line $matchInfo(line)
}
if {[llength $line] < 2} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
set ftp_deny_hosts($lineindex) [lrange $line 1 end]
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*guestgroup[ $]} {
global ftp_guestgroup
if { ! [regsub {;.*$} $matchInfo(line) {} line]} {
set line $matchInfo(line)
}
if {[llength $line] < 2} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
set ftp_guestgroup($lineindex) [lrange $line 1 end]
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*limit[ $]} {
global ftp_limit limit_index
if { ! [regsub {;.*$} $matchInfo(line) {} line$]} {
set line $matchInfo(line)
}
set l [llength $line]
if {$l < 4} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
set ftp_limit($lineindex) "$limit_index [lrange $line 1 end]"
incr limit_index
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*readme[ ]} {
global ftp_message
if { ! [regsub {;.*$} $matchInfo(line) {} line]} {
set line $matchInfo(line)
}
if {[llength $line] < 2} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
set file [lindex $line 1]
set when [lindex $line 2]
if {($when == {}) || ($when == "login")} {
set when "LOGIN"
} else {
regsub -nocase "^cwd=" $when "" when
}
set class [lrange $line 3 [llength $line]]
set ftp_message($lineindex) [list README_$when $when $file $class]
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*message[ $]} {
global ftp_message
if { ! [regsub {;.*$} $matchInfo(line) {} line]} {
set line $matchInfo(line)
}
if {[llength $line] < 2} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
set file [lindex $line 1]
set when [lindex $line 2]
if {($when == {}) || ($when == "login")} {
set when "LOGIN"
} else {
regsub -nocase "^cwd=" $when "" when
}
set class [lrange $line 3 [llength $line]]
set ftp_message($lineindex) [list MESSAGE_$when $when $file $class]
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*log[ $]} {
global ftp_log_commands ftp_log_incoming ftp_log_outgoing
if { ! [regsub {;.*$} $matchInfo(line) {} line]} {
set line $matchInfo(line)
}
if {[lindex $line 1] == "commands"} {
if {[llength $line] < 2} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
set typelist [split [lindex $line 2] ","]
set ftp_log_commands($lineindex) $typelist
} else {
if {[llength $line] < 3} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
set typelist [split [lindex $line 2] ","]
set directions [split [lindex $line 3] ","]
foreach dir $directions {
if {$dir == "inbound"} {
set ftp_log_incoming($lineindex) $typelist
} else {
set ftp_log_outgoing($lineindex) $typelist
}
}
}
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*chmod[ $]} {
global ftp_chmod
if { ! [regsub {;.*$} $matchInfo(line) {} line]} {
set line $matchInfo(line)
}
if {[llength $line] < 3} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
set typelist [split [lindex $line 2] ","]
set ftp_chmod($lineindex) "[lindex $line 1] $typelist"
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*delete[ $]} {
global ftp_delete
if { ! [regsub {;.*$} $matchInfo(line) {} line]} {
set line $matchInfo(line)
}
if {[llength $line] < 3} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
set typelist [split [lindex $line 2] ","]
set ftp_delete($lineindex) "[lindex $line 1] $typelist"
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*overwrite[ $]} {
global ftp_overwrite
if { ! [regsub {;.*$} $matchInfo(line) {} line]} {
set line $matchInfo(line)
}
if {[llength $line] < 3} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
set typelist [split [lindex $line 2] ","]
set ftp_overwrite($lineindex) "[lindex $line 1] $typelist"
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*passwd-check[ $]} {
global ftp_passwd_check
if { ! [regsub {;.*$} $matchInfo(line) {} line]} {
set line $matchInfo(line)
}
if {[llength $line] < 2} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
if {[llength $line] == 2} {
lappend line "warn"
}
set ftp_passwd_check($lineindex) [lrange $line 1 end]
continue
}
scanmatch -nocase $ftp_scontext {^[ ]*upload[ $]} {
global ftp_access ftp_access_index
if { ! [regsub {;.*$} $matchInfo(line) {} line]} {
set line $matchInfo(line)
}
set l [llength $line]
if {$l < 4} {
ErrorPush {} 1 SCO_FTPOSA_ERR_SYNTAX "$matchInfo(line)"
continue
}
set home [lindex $line 1]
set dir [lindex $line 2]
set uploads [string tolower [lindex $line 3]]
if {$l > 5} {
set owner [lindex $line 4]
set group [lindex $line 5]
} else {
set owner ""
set group ""
}
if {$l > 6} {
set mode [lindex $line 6]
} else {
set mode ""
}
if {$l > 7 || $l == 5} {
set subdirs [string tolower [lindex $line end]]
if {![cequal $subdirs dirs] && ![cequal $subdirs nodirs]} {
set subdirs nodirs
}
} else {
set subdirs nodirs
}
set ftp_access($lineindex) [list $ftp_access_index $home $dir $uploads $owner $group $mode $subdirs]
incr ftp_access_index
continue
}
}
proc ftp_addline {before line} {
global ftp_lines ftp_lineindexes ftp_newindex_ftpaccess ftp_modified_ftpaccess
if {$before == "end"} {
if {[catch {llength $ftp_lineindexes} index]} {
set index 0
}
} else {
if {[catch {llength $ftp_lineindexes} index]} {
set index 0
} else {
if {[set index [lsearch $ftp_lineindexes $before]] == -1} {
ErrorPush {} 1 SCO_FTPOSA_ERR_BUG_ERR
return
}
}
}
set newindex new.$ftp_newindex_ftpaccess
if {[catch {llength $ftp_lineindexes} index]} {
set ftp_lineindexes $newindex
} else {
set ftp_lineindexes [linsert $ftp_lineindexes $index $newindex]
}
set ftp_lines($newindex) $line
incr ftp_newindex_ftpaccess
set ftp_modified_ftpaccess 1
return $newindex
}
proc ftp_rmline {line} {
global ftp_lineindexes ftp_modified_ftpaccess
if {[set index [lsearch -exact $ftp_lineindexes $line]] == -1} {
ErrorPush {} 1 SCO_FTPOSA_ERR_BUG_ERR
return
}
lvarpop ftp_lineindexes $index
set ftp_modified_ftpaccess 1
}
proc list_guestgroup {} {
global ftp_guestgroup
if [catch {array names ftp_guestgroup} linelist] {
return {}
}
set result ""
foreach line [lsort $linelist] {
lappend result $ftp_guestgroup($line)
}
return $result
}
proc rm_guestgroup {group} {
global ftp_guestgroup ftp_lines ftp_modified_ftpaccess
if [catch {array names ftp_guestgroup} linelist] {
return
}
foreach line $linelist {
set grouplist $ftp_guestgroup($line)
loop index 0 [llength $grouplist] {
if {[lindex $grouplist $index] == $group} {
break
}
}
if {[lindex $grouplist $index] != $group} {
continue
}
if {[llength $grouplist] == 1} {
unset ftp_guestgroup($line)
ftp_rmline $line
} else {
lvarpop ftp_guestgroup($line) $index
incr index
lvarpop ftp_lines($line) $index
set ftp_modified_ftpaccess 1
}
}
}
proc add_guestgroup {value} {
global ftp_guestgroup
set index [ftp_addline end "guestgroup $value"]
set ftp_guestgroup($index) $value
}
proc get_loginfails {} {
global ftp_loginfails
if [catch {array names ftp_loginfails} linelist] {
return {}
}
if {[lempty $linelist]} {
return {}
}
set result $ftp_loginfails([lindex $linelist 0])
return $result
}
proc rm_loginfails {} {
global ftp_loginfails
if [catch {array names ftp_loginfails} linelist] {
return {}
}
foreach line $linelist {
unset ftp_loginfails($line)
ftp_rmline $line
}
}
proc set_loginfails {value} {
global ftp_loginfails
set line "loginfails $value"
set index [ftp_addline end $line]
set ftp_loginfails($index) $value
}
proc get_private {} {
global ftp_private
if [catch {array names ftp_private} linelist] {
return {}
}
if {[lempty $linelist]} {
return {}
}
set result $ftp_private([lindex $linelist 0])
return $result
}
proc rm_private {} {
global ftp_private
if [catch {array names ftp_private} linelist] {
return {}
}
if {[lempty $linelist]} {
return {}
}
foreach line $linelist {
unset ftp_private($line)
ftp_rmline $line
}
}
proc set_private {value} {
global ftp_private
set line "private $value"
set index [ftp_addline end $line]
set ftp_private($index) $value
}
proc get_email {} {
global ftp_email
if [catch {array names ftp_email} linelist] {
return {}
}
if {[lempty $linelist]} {
return {}
}
set result $ftp_email([lindex $linelist 0])
return $result
}
proc rm_email {} {
global ftp_email
if [catch {array names ftp_email} linelist] {
return {}
}
if {[lempty $linelist]} {
return {}
}
foreach line $linelist {
unset ftp_email($line)
ftp_rmline $line
}
}
proc set_email {value} {
global ftp_email
set line "email $value"
set index [ftp_addline end $line]
set ftp_email($index) $value
}
proc write_inetd_conf {} {
global inetd_conf_lines ftp_ConfigDir isOwner
if {[catch {array names inetd_conf_lines} indices]} {
return -1
}
set indices [lsort -integer $indices]
set inetd_conf_file $ftp_ConfigDir/inetd.conf
backup_file $inetd_conf_file
if {$isOwner} {
if {[catch {open "|/sbin/tfadmin writefile $inetd_conf_file" w} fd]} {
catch {exec /sbin/tfadmin cpfile $inetd_conf_file- $inetd_conf_file}
return -1
}
} else {
if {[catch {open $inetd_conf_file w} fd]} {
catch {exec /bin/cp $inetd_conf_file- $inetd_conf_file}
return -1
}
}
foreach index $indices {
puts $fd $inetd_conf_lines($index)
}
close $fd
}
proc read_inetd_conf {} {
global inetd_conf_lines ftp_ConfigDir isOwner
catch {unset inetd_conf_lines}
set inetd_conf_file $ftp_ConfigDir/inetd.conf
if {$isOwner} {
if {[catch {open "|/sbin/tfadmin readfile inetd_conf_file" r} fd]} {
return -1
}
} else {
if {[catch {open $inetd_conf_file r} fd]} {
return -1
}
}
set lineindex 0
set ftp_index -1
set sc [scancontext create]
scanmatch $sc {^ftp[ ].*$} {
set ftp_index $lineindex
}
scanmatch $sc {.*} {
set inetd_conf_lines($lineindex) $matchInfo(line)
incr lineindex
continue
}
scanfile $sc $fd
close $fd
scancontext delete $sc
return $ftp_index
}
proc get_inetd_conf {what {hasArg 0}} {
global inetd_conf_lines
set ftp_index [read_inetd_conf]
if {$ftp_index == -1} {
return { 0 }
}
if {[llength $inetd_conf_lines($ftp_index)] < 7} {
return { 0 }
}
set args [lrange $inetd_conf_lines($ftp_index) 7 end]
set len_args [llength $args]
for {set index 0} {$index < $len_args} {incr index} {
set next_index [expr $index + 1]
if {[cequal [lindex $args $index] "$what"]} {
if {$hasArg && $next_index < $len_args} {
return [list 1 [lindex $args $next_index]]
} elseif {$hasArg} {
return { 0 }
} else {
return { 1 }
}
}
}
return { 0 }
}
proc poke_inetd_conf {} {
global inetd_path isOwner
if {[catch {open "|/bin/ps -e -opid -oargs" r} fd]} {
return
}
set pid_list {}
while {! [eof $fd]} {
gets $fd line
set pid [lindex $line 0]
set com [lindex $line 1]
if {$com == $inetd_path} {
lappend pid_list $pid
}
}
foreach pid $pid_list {
if {$isOwner} {
catch {exec /sbin/tfadmin kill 1 $pid}
} else {
catch {kill 1 $pid}
}
}
}
proc set_inetd_conf {what {hasArg 0} {isAdd 1} {value ""}} {
global inetd_conf_lines
set ftp_index [read_inetd_conf]
if {$ftp_index == -1} {
return 0
}
if {[llength $inetd_conf_lines($ftp_index)] < 7} {
return 0
}
set pre_args [lrange $inetd_conf_lines($ftp_index) 0 6]
set args [lrange $inetd_conf_lines($ftp_index) 7 end]
set len_args [llength $args]
for {set index 0} {$index < $len_args} {incr index} {
set next_index [expr $index + 1]
if {[cequal [lindex $args $index] "$what"]} {
if {$hasArg && $next_index < $len_args} {
if {$isAdd} {
lvarpop args $next_index $value
} else {
lvarpop args $next_index
lvarpop args $index
}
set inetd_conf_lines($ftp_index) [concat $pre_args $args]
write_inetd_conf
return 1
} elseif {$hasArg} {
if {$isAdd} {
lappend args $value
} else {
lvarpop args $index
}
set inetd_conf_lines($ftp_index) [concat $pre_args $args]
write_inetd_conf
return 1
} else {
if {$isAdd} {
} else {
lvarpop args $index
}
set inetd_conf_lines($ftp_index) [concat $pre_args $args]
write_inetd_conf
return 1
}
}
}
if {$isAdd} {
lappend args $what
if {$hasArg} {
lappend args $value
}
}
set inetd_conf_lines($ftp_index) [concat $pre_args $args]
write_inetd_conf
return 1
}
proc OSA:get_banner {} {
global ftp_banner
if [catch {array names ftp_banner} linelist] {
return {}
}
if {[lempty $linelist]} {
return {}
}
set result $ftp_banner([lindex $linelist 0])
return $result
}
proc rm_banner {} {
global ftp_banner
if [catch {array names ftp_banner} linelist] {
return {}
}
if {[lempty $linelist]} {
return {}
}
foreach line $linelist {
unset ftp_banner($line)
ftp_rmline $line
}
}
proc set_banner {value} {
global ftp_banner
set line "banner $value"
set index [ftp_addline end $line]
set ftp_banner($index) $value
}
proc list_log_commands {} {
global ftp_log_commands
if [catch {array names ftp_log_commands} linelist] {
return {}
}
set result {}
foreach line [lsort $linelist] {
set result [concat $result $ftp_log_commands($line)]
}
return $result
}
proc rm_log_commands {type} {
global ftp_log_commands ftp_lines ftp_modified_ftpaccess
if [catch {array names ftp_log_commands} linelist] {
return
}
foreach line $linelist {
set typelist $ftp_log_commands($line)
loop index 0 [llength $typelist] {
if {[lindex $typelist $index] == $type} {
break
}
}
if {[lindex $typelist $index] != $type} {
continue
}
if {[llength $typelist] == 1} {
unset ftp_log_commands($line)
ftp_rmline $line
} else {
lvarpop ftp_log_commands($line) $index
incr index
lvarpop ftp_lines($line) $index
set ftp_modified_ftpaccess 1
}
}
}
proc add_log_commands {value} {
global ftp_log_commands
set index [ftp_addline end "log commands $value"]
set ftp_log_commands($index) $value
}
proc list_log_incoming {} {
global ftp_log_incoming
if [catch {array names ftp_log_incoming} linelist] {
return {}
}
set result {}
foreach line [lsort $linelist] {
set result [concat $result $ftp_log_incoming($line)]
}
return $result
}
proc rm_log_incoming {value} {
global ftp_log_incoming ftp_log_outgoing ftp_lines ftp_modified_ftpaccess
if [catch {array names ftp_log_incoming} linelist] {
return
}
foreach line $linelist {
set typelist $ftp_log_incoming($line)
set found 0
loop index 0 [llength $typelist] {
if {[lindex $typelist $index] == $value} {
set found 1
break
}
}
if {$found} {
if [info exists ftp_log_outgoing($line)] {
set newindex [ftp_addline end "log transfers $typelist outbound"]
set ftp_log_outgoing($newindex) $typelist
unset ftp_log_outgoing($line)
}
if {[llength $typelist] == 1} {
unset ftp_log_incoming($line)
ftp_rmline $line
} else {
lvarpop ftp_log_incoming($line) $index
incr index
set ftp_lines($line) "log transfers $ftp_log_incoming($line) inbound"
set ftp_modified_ftpaccess 1
}
}
}
}
proc add_log_incoming {value} {
global ftp_log_incoming
set index [ftp_addline end "log transfers $value inbound"]
set ftp_log_incoming($index) "$value"
}
proc list_log_outgoing {} {
global ftp_log_outgoing
if [catch {array names ftp_log_outgoing} linelist] {
return {}
}
set result {}
foreach line [lsort $linelist] {
set result [concat $result $ftp_log_outgoing($line)]
}
return $result
}
proc rm_log_outgoing {value} {
global ftp_log_incoming ftp_log_outgoing ftp_lines ftp_modified_ftpaccess
if [catch {array names ftp_log_outgoing} linelist] {
return
}
foreach line $linelist {
set typelist $ftp_log_outgoing($line)
set found 0
loop index 0 [llength $typelist] {
if {[lindex $typelist $index] == $value} {
set found 1
break
}
}
if {$found} {
if [info exists ftp_log_incoming($line)] {
set newindex [ftp_addline end "log transfers $typelist inbound"]
set ftp_log_incoming($newindex) $typelist
unset ftp_log_incoming($line)
}
if {[llength $typelist] == 1} {
unset ftp_log_outgoing($line)
ftp_rmline $line
} else {
lvarpop ftp_log_outgoing($line) $index
incr index
set ftp_lines($line) "log transfers $ftp_log_outgoing($line) outbound"
set ftp_modified_ftpaccess 1
}
}
}
}
proc add_log_outgoing {value} {
global ftp_log_outgoing
set index [ftp_addline end "log transfers $value outbound"]
set ftp_log_outgoing($index) "$value"
}
proc get_shutdown {} {
global ftp_shutdown
if [catch {array names ftp_shutdown} linelist] {
return {}
}
if {[lempty $linelist]} {
return {}
}
set result $ftp_shutdown([lindex $linelist 0])
return $result
}
proc rm_shutdown {} {
global ftp_shutdown
if [catch {array names ftp_shutdown} linelist] {
return {}
}
foreach line $linelist {
unset ftp_shutdown($line)
ftp_rmline $line
}
}
proc set_shutdown {value} {
global ftp_shutdown
set line "shutdown $value"
set index [ftp_addline end $line]
set ftp_shutdown($index) $value
}
proc list_chmod {} {
global ftp_chmod
if [catch {array names ftp_chmod} linelist] {
return {}
}
set result "anonymous real guest"
foreach line [lsort $linelist] {
set type [lindex $ftp_chmod($line) 0]
set users [lrange $ftp_chmod($line) 1 end]
if {$type == "no"} {
set result [lindex [intersect3 $result $users] 0]
}
}
return $result
}
proc rm_chmod {value} {
global ftp_chmod ftp_lines ftp_modified_ftpaccess
if [catch {array names ftp_chmod} linelist] {
set index [ftp_addline end "chmod no $value"]
set ftp_chmod($index) "no $value"
return
}
foreach line $linelist {
set type [lindex $ftp_chmod($line) 0]
set users [lrange $ftp_chmod($line) 1 end]
set found 0
loop index 0 [llength $users] {
if {([lindex $users $index] == $value) && ($type == "yes")} {
set found 1
break
}
}
if {$found} {
if {[llength $users] == 1} {
unset ftp_chmod($line)
ftp_rmline $line
} else {
lvarpop ftp_chmod($line) $index
incr index
lvarpop ftp_lines($line) $index
set ftp_modified_ftpaccess 1
}
}
}
set index [ftp_addline end "chmod no $value"]
set ftp_chmod($index) "no $value"
}
proc add_chmod {value} {
global ftp_chmod
if [catch {array names ftp_chmod} linelist] {
set index [ftp_addline end "chmod yes $value"]
set ftp_chmod($index) "yes $value"
} else {
set found 0
foreach line [lsort $linelist] {
set type [lindex $ftp_chmod($line) 0]
set users [lrange $ftp_chmod($line) 1 end]
set found 0
loop index 0 [llength $users] {
if {($type == "no") && ([lindex $users $index] == $value)} {
set found 1
break
}
}
if {$found} {
if {[llength $users] == 1} {
unset ftp_chmod($line)
ftp_rmline $line
} else {
lvarpop ftp_chmod($line) $index
incr index
lvarpop ftp_lines($line) $index
set ftp_modified_ftpaccess 1
}
}
}
set index [ftp_addline end "chmod yes $value"]
set ftp_chmod($index) "yes $value"
}
}
proc list_delete {} {
global ftp_delete
if [catch {array names ftp_delete} linelist] {
return {}
}
set result "anonymous real guest"
foreach line [lsort $linelist] {
set type [lindex $ftp_delete($line) 0]
set users [lrange $ftp_delete($line) 1 end]
if {$type == "no"} {
set result [lindex [intersect3 $result $users] 0]
}
}
return $result
}
proc rm_delete {value} {
global ftp_delete ftp_lines ftp_modified_ftpaccess
if [catch {array names ftp_delete} linelist] {
set index [ftp_addline end "delete no $value"]
set ftp_delete($index) "no $value"
return
}
foreach line $linelist {
set type [lindex $ftp_delete($line) 0]
set users [lrange $ftp_delete($line) 1 end]
set found 0
loop index 0 [llength $users] {
if {([lindex $users $index] == $value) && ($type == "yes")} {
set found 1
break
}
}
if {$found} {
if {[llength $users] == 1} {
unset ftp_delete($line)
ftp_rmline $line
} else {
lvarpop ftp_delete($line) $index
incr index
lvarpop ftp_lines($line) $index
set ftp_modified_ftpaccess 1
}
}
}
set index [ftp_addline end "delete no $value"]
set ftp_delete($index) "no $value"
}
proc add_delete {value} {
global ftp_delete ftp_lines ftp_modified_ftpaccess
if [catch {array names ftp_delete} linelist] {
set index [ftp_addline end "delete yes $value"]
set ftp_delete($index) "yes $value"
} else {
set found 0
foreach line [lsort $linelist] {
set type [lindex $ftp_delete($line) 0]
set users [lrange $ftp_delete($line) 1 end]
set found 0
loop index 0 [llength $users] {
if {($type == "no") && ([lindex $users $index] == $value)} {
set found 1
break
}
}
if {$found} {
if {[llength $users] == 1} {
unset ftp_delete($line)
ftp_rmline $line
} else {
lvarpop ftp_delete($line) $index
incr index
lvarpop ftp_lines($line) $index
set ftp_modified_ftpaccess 1
}
}
}
set index [ftp_addline end "delete yes $value"]
set ftp_delete($index) "yes $value"
}
}
proc list_overwrite {} {
global ftp_overwrite
if [catch {array names ftp_overwrite} linelist] {
return {}
}
set result "anonymous real guest"
foreach line [lsort $linelist] {
set type [lindex $ftp_overwrite($line) 0]
set users [lrange $ftp_overwrite($line) 1 end]
if {$type == "no"} {
set result [lindex [intersect3 $result $users] 0]
}
}
return $result
}
proc rm_overwrite {value} {
global ftp_overwrite ftp_lines ftp_modified_ftpaccess
if [catch {array names ftp_overwrite} linelist] {
set index [ftp_addline end "overwrite no $value"]
set ftp_overwrite($index) "no $value"
return
}
foreach line $linelist {
set type [lindex $ftp_overwrite($line) 0]
set users [lrange $ftp_overwrite($line) 1 end]
set found 0
loop index 0 [llength $users] {
if {([lindex $users $index] == $value) && ($type == "yes")} {
set found 1
break
}
}
if {$found} {
if {[llength $users] == 1} {
unset ftp_overwrite($line)
ftp_rmline $line
} else {
lvarpop ftp_overwrite($line) $index
incr index
lvarpop ftp_lines($line) $index
set ftp_modified_ftpaccess 1
}
}
}
set index [ftp_addline end "overwrite no $value"]
set ftp_overwrite($index) "no $value"
}
proc add_overwrite {value} {
global ftp_overwrite ftp_lines ftp_modified_ftpaccess
if [catch {array names ftp_overwrite} linelist] {
set index [ftp_addline end "overwrite yes $value"]
set ftp_overwrite($index) "yes $value"
} else {
set found 0
foreach line [lsort $linelist] {
set type [lindex $ftp_overwrite($line) 0]
set users [lrange $ftp_overwrite($line) 1 end]
set found 0
loop index 0 [llength $users] {
if {($type == "no") && ([lindex $users $index] == $value)} {
set found 1
break
}
}
if {$found} {
if {[llength $users] == 1} {
unset ftp_overwrite($line)
ftp_rmline $line
} else {
lvarpop ftp_overwrite($line) $index
incr index
lvarpop ftp_lines($line) $index
set ftp_modified_ftpaccess 1
}
}
}
set index [ftp_addline end "overwrite yes $value"]
set ftp_overwrite($index) "yes $value"
}
}
proc get_passwd_check {} {
global ftp_passwd_check
if [catch {array names ftp_passwd_check} linelist] {
return {}
}
if {[lempty $linelist]} {
return {}
}
set result $ftp_passwd_check([lindex $linelist 0])
return $result
}
proc rm_passwd_check {} {
global ftp_passwd_check
if [catch {array names ftp_passwd_check} linelist] {
return {}
}
foreach line $linelist {
unset ftp_passwd_check($line)
ftp_rmline $line
}
}
proc set_passwd_check {value} {
global ftp_passwd_check
set line "passwd-check $value"
set index [ftp_addline end $line]
set ftp_passwd_check($index) $value
}
proc find_deny {name} {
global ftp_deny_hosts
if [catch {array names ftp_deny_hosts} linelist] {
return {}
}
foreach line $linelist {
if {[lindex $ftp_deny_hosts($line) 0] == $name} {
return $line
}
}
return {}
}
proc get_denyfile {name} {
global ftp_deny_hosts
if {[set line [find_deny $name]] == {} } {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$name"
}
return [lindex $ftp_deny_hosts($line) 1]
}
proc find_access {name} {
global ftp_access
if [catch {array names ftp_access} linelist] {
return {}
}
foreach line $linelist {
if {[lindex $ftp_access($line) 0] == $name} {
return $line
}
}
return {}
}
proc find_limit {name} {
global ftp_limit
if [catch {array names ftp_limit} linelist] {
return {}
}
foreach line $linelist {
if {[lindex $ftp_limit($line) 0] == $name} {
return $line
}
}
return {}
}
proc find_message {name} {
global ftp_message
if [catch {array names ftp_message} linelist] {
return {}
}
foreach line $linelist {
if {[lindex $ftp_message($line) 0] == "$name"} {
return $line
}
}
return {}
}
proc ftp_readfile_ftpaccess {} {
global ftp_scontext ftp_modified_ftpaccess ftp_newindex_ftpaccess
global ftp_ConfigDir limit_index isOwner
set file $ftp_ConfigDir/ftpaccess
set limit_index 0
if {$isOwner} {
if {![catch {open "|/sbin/tfadmin readfile $file" r} infile]} {
scanfile $ftp_scontext $infile
close $infile
}
} else {
if {![catch {open $file r} infile]} {
scanfile $ftp_scontext $infile
close $infile
}
}
set ftp_modified_ftpaccess 0
set ftp_newindex_ftpaccess 0
}
proc ftp_writefile_ftpaccess {} {
global ftp_modified_ftpaccess ftp_lines ftp_lineindexes ftp_ConfigDir
global isOwner
set file $ftp_ConfigDir/ftpaccess
if {!$ftp_modified_ftpaccess} {
return
}
backup_file $file
if {$isOwner} {
if [catch {open "|/sbin/tfadmin writefile $file" w} outfile] {
ErrorPush {} 1 SCO_FTPOSA_ERR_CONFIG
return
}
} else {
if [catch {open $file w} outfile] {
ErrorPush {} 1 SCO_FTPOSA_ERR_CONFIG
return
}
}
foreach line $ftp_lineindexes {
puts $outfile $ftp_lines($line)
}
close $outfile
set ftp_modified_ftpaccess 0
}
proc ftp_readfile_ftpusers {} {
global ftp_modified_ftpusers ftp_ConfigDir ftp_deny_users
global isOwner ftp_ftpusers_comments
set file $ftp_ConfigDir/ftpusers
if {$isOwner} {
if {[catch {open "|/sbin/tfadmin readfile $file" r} infile]} {
set ftp_modified_ftpusers 0
return
}
} else {
if {[catch {open $file r} infile]} {
set ftp_modified_ftpusers 0
return
}
}
while {! [eof $infile]} {
gets $infile user
if {[csubstr $user 0 1] == "#"} {
lappend ftp_ftpusers_comments $user
} elseif {[set user [string trim $user]] == ""} {
continue
} else {
set ftp_deny_users($user) yes
}
}
close $infile
set ftp_modified_ftpusers 0
}
proc ftp_writefile_ftpusers {} {
global ftp_modified_ftpusers ftp_ConfigDir ftp_deny_users
global isOwner ftp_ftpusers_comments
set file $ftp_ConfigDir/ftpusers
if {! $ftp_modified_ftpusers} {
return
}
backup_file $file
if {$isOwner} {
if {[catch {open "|/sbin/tfadmin writefile $file" w} outfile]} {
ErrorPush {} 1 SCO_FTPOSA_ERR_CONFIG
return
}
} else {
if {[catch {open $file w} outfile]} {
ErrorPush {} 1 SCO_FTPOSA_ERR_CONFIG
return
}
}
if {[info exists ftp_ftpusers_comments]} {
foreach line $ftp_ftpusers_comments {
puts $outfile $line
}
}
if {! [catch {array names ftp_deny_users} users]} {
foreach user $users {
if {$ftp_deny_users($user) == "yes"} {
puts $outfile $user
}
}
}
close $outfile
set ftp_modified_ftpusers 0
}
proc ftp_init {} {
global ftp_ConfigDir ftp_log ftp_OsaDir ftp_Logfile
global ftp_Loglen ftp_Logmask inetd_path ageduid_file
global ftp_access_index isOwner
set isOwner [isOwner]
set ftp_access_index 0
set ftp_log {}
set ftp_Loglen 0
set ftp_Logmask ""
set ftp_ConfigDir /etc/inet
set ftp_OsaDir /usr/lib/scoadmin/netosa
set ftp_Logfile /var/adm/xferlog
set ftp_Default /var/ftp
set inetd_path /usr/sbin/inetd
if {![file exists $ftp_Default]} {
if {$isOwner} {
exec /sbin/tfadmin swUser root /bin/mkdir -p $ftp_Default
} else {
mkdir -path $ftp_Default
}
}
setup_ftp_scancontexts
ftp_readfile_ftpaccess
ftp_readfile_ftpusers
ftp_readshutdownfile
}
proc ftp_get {class object refObject op subOp data attr attrValueList osaData} {
switch -exact $attr {
timeout {
set result [get_inetd_conf "-t" 1]
if {[lindex $result 0] == 1} {
set result [lindex $result 1]
} else {
set result "900"
}
}
maxtime {
set result [get_inetd_conf "-T" 1]
if {[lindex $result 0] == 1} {
set result [lindex $result 1]
} else {
set result "7200"
}
}
guestgroup {
set result [list_guestgroup]
}
loginfails {
set result [get_loginfails]
}
private {
set result [get_private]
}
email {
set result [get_email]
}
banner {
set result [OSA:get_banner]
}
log_commands {
set result [list_log_commands]
}
log_incoming {
set result [list_log_incoming]
}
log_outgoing {
set result [list_log_outgoing]
}
shutdown {
set result [get_shutdown]
}
chmod {
set result [list_chmod]
}
delete {
set result [list_delete]
}
overwrite {
set result [list_overwrite]
}
passwd_check {
set result [get_passwd_check]
}
default {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ATTRIBUTE [list "$attr" "$class"]
}
}
return [list [list $attr $result]]
}
proc ftp_replace {class object refObject op subOp data attr attrValueList osaData} {
set value [keylget attrValueList $attr]
switch -exact $attr {
timeout {
if {$value != ""} {
set_inetd_conf "-t" 1 1 $value
} else {
set_inetd_conf "-t" 1 0
}
}
maxtime {
if {$value != ""} {
set_inetd_conf "-T" 1 1 $value
} else {
set_inetd_conf "-T" 1 0
}
}
guestgroup {
foreach group [list_guestgroup] {
rm_guestgroup $group
}
foreach group $value {
add_guestgroup $group
}
writeGuestShutdownFile
}
loginfails {
rm_loginfails
if {$value != {}} {
set_loginfails $value
}
}
private {
rm_private
if {$value != {}} {
set_private $value
}
}
email {
rm_email
if {$value != {}} {set_email $value}
}
banner {
rm_banner
if {$value != {}} {set_banner $value}
}
log_commands {
foreach type [list_log_commands] {
rm_log_commands $type
}
foreach type $value {
add_log_commands $type
}
}
log_incoming {
foreach type [list_log_incoming] {
rm_log_incoming $type
}
foreach type $value {
add_log_incoming $type
}
}
log_outgoing {
foreach type [list_log_outgoing] {
rm_log_outgoing $type
}
foreach type $value {
add_log_outgoing $type
}
}
shutdown {
rm_shutdown
if {$value != {}} {set_shutdown $value}
}
chmod {
foreach type [list_chmod] {
rm_chmod $type
}
foreach type $value {
add_chmod $type
}
}
delete {
foreach type [list_delete] {
rm_delete $type
}
foreach type $value {
add_delete $type
}
}
overwrite {
foreach type [list_overwrite] {
rm_overwrite $type
}
foreach type $value {
add_overwrite $type
}
}
passwd_check {
rm_passwd_check
set_passwd_check $value
}
default {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ATTRIBUTE [list "$attr" "$class"]
}
}
ftp_writefile_ftpaccess
set attrs [keylkeys attrValueList]
if {([lsearch $attrs timeout] != -1 || [lsearch $attrs maxtime] != -1) && [cequal $attr [lindex $attrs end]]} {
poke_inetd_conf
}
}
proc ftp:File_Action_ListFiles {dir} {
set fileList {}
if {[catch {glob $dir} dirContents]} {
return ""
}
foreach entry $dirContents {
if {![file isdirectory $entry]} {
lappend fileList $entry
}
}
return $fileList
}
proc ftp:File_Action_ListDirs {dir} {
set dirList {}
if {[catch {glob $dir} dirContents]} {
return ""
}
foreach entry $dirContents {
if {[file isdirectory $entry]} {
lappend dirList $entry
}
}
return $dirList
}
proc ftp_action {class object refObject op subOp data attr attrValueList osaData} {
switch $subOp {
listFiles { return [ftp:File_Action_ListFiles $object] }
listDirs { return [ftp:File_Action_ListDirs $object] }
default { ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ACTION $subOp }
}
return
}
proc ftpClass_list {class object refObject op subOp data attr attrValueList osaData} {
global ftp_classes
if [catch {array names ftp_classes} classes] {
return {}
} else {
return $classes
}
}
proc ftpClass_get {class object refObject op subOp data attr attrValueList osaData} {
global ftp_classes
if {! [info exists ftp_classes($object)]} {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
set objrec $ftp_classes($object)
switch -exact $attr {
typeList { set result [keylget objrec typelist] }
addrList { set result [keylget objrec addrs] }
autogroup { set result [keylget objrec groups] }
default { ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ATTRIBUTE [list "$attr"]}
}
return [list [list $attr $result]]
}
proc ftpClass_replace {class object refObject op subOp data attr attrValueList osaData} {
global ftp_classes ftp_lines ftp_modified_ftpaccess
if {! [info exists ftp_classes($object)]} {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
set objrec $ftp_classes($object)
keylget attrValueList typeList typelist
keylget attrValueList addrList addrlist
keylget attrValueList autogroup groups
keylset objrec typelist $typelist
keylset objrec addrs $addrlist
keylset objrec groups $groups
keylget objrec lines lines
foreach line $lines {
ftp_rmline $line
}
set line "class $object [join $typelist ,] $addrlist"
set index [ftp_addline end $line]
lappend newlines $index
foreach group $groups {
set line "autogroup $group $object"
set index [ftp_addline end $line]
lappend newlines $index
}
keylset objrec lines $newlines
set ftp_classes($object) $objrec
set ftp_modified_ftpaccess 1
ftp_writefile_ftpaccess
}
proc ftpClass_create {class object refObject op subOp data attr attrValueList osaData} {
global ftp_classes
if [info exists ftp_classes($object)] {
ErrorPush {} 1 SCO_OSA_ERR_DUPLICATE_MANAGED_OBJECT_INSTANCE "$object"
}
keylget attrValueList typeList typelist
keylget attrValueList addrList addrlist
keylget attrValueList autogroup groups
keylset objrec typelist $typelist
keylset objrec addrs $addrlist
keylset objrec groups $groups
set line "class $object [join $typelist ,] $addrlist"
set index [ftp_addline end $line]
lappend newlines $index
foreach group $groups {
set line "autogroup $group $object"
set index [ftp_addline end $line]
lappend newlines $index
}
keylset objrec lines $newlines
set ftp_classes($object) $objrec
ftp_writefile_ftpaccess
return 1
}
proc ftpClass_delete {class object refObject op subOp data attr attrValueList osaData} {
global ftp_classes
if {! [info exists ftp_classes($object)]} {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
set objrec $ftp_classes($object)
keylget objrec lines lines
foreach line $lines {
ftp_rmline $line
}
unset ftp_classes($object)
ftp_writefile_ftpaccess
return 1
}
proc ftpLimit_list {class object refObject op subOp data attr attrValueList osaData} {
global ftp_limit
if [catch {array names ftp_limit} linelist] {
return {}
}
set result {}
foreach line [lsort $linelist] {
lappend result [lindex $ftp_limit($line) 0]
}
return $result
}
proc ftpLimit_get {class object refObject op subOp data attr attrValueList osaData} {
global ftp_limit
if {[set line [find_limit $object]] == {} } {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
set objdef $ftp_limit($line)
switch -exact $attr {
limitID { set result $object }
class { set result [lindex $objdef 1] }
users { set result [lindex $objdef 2] }
times { set result [lindex $objdef 3] }
file { set result [lindex $objdef 4] }
default { ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ATTRIBUTE [list "$attr" "$limitID"]}
}
return [list [list $attr $result]]
}
proc ftpLimit_replace {class object refObject op subOp data attr attrValueList osaData} {
global ftp_limit ftp_lines ftp_modified_ftpaccess
if {[set line [find_limit $object]] == {} } {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
keylget attrValueList limitID limitID
keylget attrValueList class class
keylget attrValueList users users
keylget attrValueList times times
keylget attrValueList file file
set ftp_limit($line) [lreplace $ftp_limit($line) 0 0 $limitID]
set ftp_limit($line) [lreplace $ftp_limit($line) 1 1 $class]
set ftp_limit($line) [lreplace $ftp_limit($line) 2 2 $users]
set ftp_limit($line) [lreplace $ftp_limit($line) 3 3 $times]
if {[llength $ftp_limit($line)] > 4} {
set ftp_limit($line) [lreplace $ftp_limit($line) 4 4 $file]
} else {
set ftp_limit($line) [linsert $ftp_limit($line) 4 $file]
}
set ftp_lines($line) "limit $class $users $times $file"
set ftp_modified_ftpaccess 1
ftp_writefile_ftpaccess
}
proc ftpLimit_delete {class object refObject op subOp data attr attrValueList osaData} {
global ftp_limit
if {[set line [find_limit $object]] == {} } {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
unset ftp_limit($line)
ftp_rmline $line
ftp_writefile_ftpaccess
return 1
}
proc ftpLimit_create {class object refObject op subOp data attr attrValueList osaData} {
global ftp_limit
if {[find_limit $object] != {}} {
ErrorPush {} 1 SCO_OSA_ERR_DUPLICATE_MANAGED_OBJECT_INSTANCE "$object"
}
if [catch {set class [keylget attrValueList class]}] {
error "need class attribute"
}
if [catch {set users [keylget attrValueList users]}] {
error "need users attribute"
}
if [catch {set times [keylget attrValueList times]}] {
error "need times attribute"
}
if [catch {set file [keylget attrValueList file]}] {
error "need file attribute"
}
set line "limit $class $users $times $file"
set index [ftp_addline end $line]
set ftp_limit($index) "$object [lrange $line 1 end]"
ftp_writefile_ftpaccess
return 1
}
proc ftpAccess_list {class object refObject op subOp data attr attrValueList osaData} {
global ftp_access
if [catch {array names ftp_access} linelist] {
return {}
}
set result {}
foreach line [lsort $linelist] {
lappend result [lindex $ftp_access($line) 0]
}
return $result
}
proc ftpAccess_get {class object refObject op subOp data attr attrValueList osaData} {
global ftp_access
if {[set line [find_access $object]] == {} } {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
set objdef $ftp_access($line)
switch -exact $attr {
home { set result [lindex $objdef 1] }
dir { set result [lindex $objdef 2] }
upload { set result [lindex $objdef 3] }
owner { set result [lindex $objdef 4] }
group { set result [lindex $objdef 5] }
mode { set result [lindex $objdef 6] }
subdirs { set result [lindex $objdef 7] }
default { ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ATTRIBUTE [list "$attr" "$class"]}
}
return [list [list $attr $result]]
}
proc ftpAccess_replace {class object refObject op subOp data attr attrValueList osaData} {
global ftp_access ftp_lines ftp_modified_ftpaccess
if {[set line [find_access $object]] == {} } {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
keylget attrValueList dir dir
keylget attrValueList home home
keylget attrValueList upload upload
keylget attrValueList owner owner
keylget attrValueList group group
keylget attrValueList mode mode
keylget attrValueList subdirs subdirs
set ftp_access($line) [lreplace $ftp_access($line) 1 1 $home]
set ftp_access($line) [lreplace $ftp_access($line) 2 2 $dir]
set ftp_access($line) [lreplace $ftp_access($line) 3 3 $upload]
set ftp_access($line) [lreplace $ftp_access($line) 4 4 $owner]
set ftp_access($line) [lreplace $ftp_access($line) 5 5 $group]
set ftp_access($line) [lreplace $ftp_access($line) 6 6 $mode]
set ftp_access($line) [lreplace $ftp_access($line) 7 7 $subdirs]
set ftp_lines($line) "upload $home $dir $upload $owner $group $mode $subdirs"
set ftp_modified_ftpaccess 1
ftp_writefile_ftpaccess
}
proc ftpAccess_create {class object refObject op subOp data attr attrValueList osaData} {
global ftp_access ftp_access_index
if {[find_access $object] != {}} {
ErrorPush {} 1 SCO_OSA_ERR_DUPLICATE_MANAGED_OBJECT_INSTANCE "$object"
}
if [catch {set upload [keylget attrValueList upload]}] {
error "need upload attribute"
}
keylget attrValueList home home
keylget attrValueList dir dir
set owner {}
set group {}
set mode {}
set subdirs {}
if {$upload == "yes"} {
if [catch {set owner [keylget attrValueList owner]}] {
error "need owner attribute"
}
if [catch {set group [keylget attrValueList group]}] {
error "need group attribute"
}
if [catch {set mode [keylget attrValueList mode]}] {
error "need mode attribute"
}
}
keylget attrValueList subdirs subdirs
set line "upload $home $dir $upload $owner $group $mode $subdirs"
set index [ftp_addline end $line]
set object $ftp_access_index
incr ftp_access_index
set ftp_access($index) [list $object $home $dir $upload $owner $group $mode $subdirs]
ftp_writefile_ftpaccess
return $object
}
proc ftpAccess_delete {class object refObject op subOp data attr attrValueList osaData} {
global ftp_access
if {[set line [find_access $object]] == {} } {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
unset ftp_access($line)
ftp_rmline $line
ftp_writefile_ftpaccess
return 1
}
proc ftpMessage_list {class object refObject op subOp data attr attrValueList osaData} {
global ftp_message
if [catch {array names ftp_message} linelist] {
return {}
}
set result {}
foreach line [lsort $linelist] {
lappend result [lindex $ftp_message($line) 0]
}
return $result
}
proc ftpMessage_get {class object refObject op subOp data attr attrValueList osaData} {
global ftp_message
if {[set line [find_message $object]] == {} } {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
set objdef $ftp_message($line)
switch -exact $attr {
type {
if [string match "README_*" $object] {
set result "README"
} else {
set result "MESSAGE"
}
}
when { set result [lindex $objdef 1] }
file { set result [lindex $objdef 2] }
class {
set result [lindex $objdef 3]
}
default { ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ATTRIBUTE [list "$attr" "$class"]}
}
return [list [list $attr $result]]
}
proc ftpMessage_replace {class object refObject op subOp data attr attrValueList osaData} {
global ftp_message ftp_lines ftp_modified_ftpaccess
if {[set line [find_message $object]] == {} } {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
keylget attrValueList type type
keylget attrValueList when when
keylget attrValueList file file
keylget attrValueList class class
set ftp_message($line) [lreplace $ftp_message($line) 1 1 $when]
set ftp_message($line) [lreplace $ftp_message($line) 2 2 $file]
set ftp_message($line) [lreplace $ftp_message($line) 3 3 $class]
if {[string tolower $when] != "login"} {
set newline "[string tolower $type] $file cwd=$when $class"
} else {
set newline "[string tolower $type] $file $when $class"
}
set ftp_lines($line) $newline
set ftp_modified_ftpaccess 1
ftp_writefile_ftpaccess
}
proc ftpMessage_create {class object refObject op subOp data attr attrValueList osaData} {
global ftp_message
if [catch {set type [keylget attrValueList type]}] {
error "need type attribute"
}
set when "LOGIN"
keylget attrValueList when when
set object "${type}_$when"
if {[find_message $object] != {}} {
ErrorPush {} 1 SCO_OSA_ERR_DUPLICATE_MANAGED_OBJECT_INSTANCE "$object"
}
if [catch {set file [keylget attrValueList file]}] {
error "need file attribute"
}
set class ""
keylget attrValueList class class
if {[string tolower $when] != "login"} {
set line "[string tolower $type] $file cwd=$when $class"
} else {
set line "[string tolower $type] $file $when $class"
}
set index [ftp_addline end $line]
set ftp_message($index) [list $object $when $file $class]
ftp_writefile_ftpaccess
return 1
}
proc ftpMessage_delete {class object refObject op subOp data attr attrValueList osaData} {
global ftp_message
if {[set line [find_message $object]] == {} } {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
unset ftp_message($line)
ftp_rmline $line
ftp_writefile_ftpaccess
return 1
}
######################################################################
proc ftpDenyHost_list {class object refObject op subOp data attr attrValueList osaData} {
global ftp_deny_hosts
if [catch {array names ftp_deny_hosts} linelist] {
return {}
}
set result {}
foreach line [lsort $linelist] {
lappend result [lindex $ftp_deny_hosts($line) 0]
}
return $result
}
proc ftpDenyHost_get {class object refObject op subOp data attr attrValueList osaData} {
switch -exact $attr {
host { set result $object }
file { set result [get_denyfile $object] }
default { ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ATTRIBUTE [list "$attr" "$class"]}
}
return [list [list $attr $result]]
}
proc ftpDenyHost_replace {class object refObject op subOp data attr attrValueList osaData} {
global ftp_deny_hosts ftp_lines ftp_modified_ftpaccess
if {[set line [find_deny $object]] == {} } {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
keylget attrValueList host host
keylget attrValueList file file
set ftp_deny_hosts($line) [lreplace $ftp_deny_hosts($line) 0 0 $host]
if {[llength $ftp_deny_hosts($line)] > 1} {
set ftp_deny_hosts($line) [lreplace $ftp_deny_hosts($line) 1 1 $file]
} else {
set ftp_deny_hosts($line) [linsert $ftp_deny_hosts($line) 1 $file]
}
set ftp_lines($line) "deny $host $file"
set ftp_modified_ftpaccess 1
ftp_writefile_ftpaccess
}
proc ftpDenyHost_create {class object refObject op subOp data attr attrValueList osaData} {
global ftp_deny_hosts ftp_modified_ftpaccess
if {[find_deny $object] != {}} {
ErrorPush {} 1 SCO_OSA_ERR_DUPLICATE_MANAGED_OBJECT_INSTANCE "$object"
}
if [catch {set file [keylget attrValueList file]}] {
error "need file attribute"
}
set line "deny $object $file"
set index [ftp_addline end $line]
set ftp_deny_hosts($index) [lrange $line 1 end]
set ftp_modified_ftpaccess 1
ftp_writefile_ftpaccess
return 1
}
proc ftpDenyHost_delete {class object refObject op subOp data attr attrValueList osaData} {
global ftp_deny_hosts ftp_modified_ftpaccess
if {[set line [find_deny $object]] == {} } {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
unset ftp_deny_hosts($line)
ftp_rmline $line
set ftp_modified_ftpaccess 1
ftp_writefile_ftpaccess
return 1
}
######################################################################
proc ftpDenyUser_list {class object refObject op subOp data attr attrValueList osaData} {
global ftp_deny_users
if {[catch {array names ftp_deny_users} users]} {
return {}
}
return $users
}
proc ftpDenyUser_get {class object refObject op subOp data attr attrValueList osaData} {
global ftp_deny_users
if [catch {set denied $ftp_deny_users($object)}] {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
switch -exact $attr {
user { set result $object }
denied { set result $ftp_deny_users($object) }
default { ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ATTRIBUTE [list "$attr" "$class"]}
}
return [list [list $attr $result]]
}
proc ftpDenyUser_replace {class object refObject op subOp data attr attrValueList osaData} {
global ftp_deny_host ftp_modified_ftpusers
if [catch {set denied $ftp_deny_users($object)}] {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
if [catch {keylget attrValueList denied denied}] {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ATTRIBUTE [list "$object" "$class"]
}
if {$denied != "yes" && $denied != "no"} {
ErrorPush {} 1 SCO_OSA_ERR_PROCESSING_FAILURE_ON_ATTRIBUTE "$object"
}
set ftp_deny_host($object) $denied
set ftp_modified_ftpusers 1
ftp_writefile_ftpusers
return {}
}
proc ftpDenyUser_create {class object refObject op subOp data attr attrValueList osaData} {
global ftp_deny_users ftp_modified_ftpusers
if [catch {array names ftp_deny_users} users] {
set users {}
}
if {[lsearch $users $object] != -1} {
ErrorPush {} 1 SCO_OSA_ERR_DUPLICATE_MANAGED_OBJECT_INSTANCE "$object"
}
if [catch {set denied [keylget attrValueList denied]}] {
set denied yes
}
if {$denied != "yes" && $denied != "no"} {
ErrorPush {} 1 SCO_OSA_ERR_PROCESSING_FAILURE_ON_ATTRIBUTE "$object"
}
set ftp_deny_users($object) $denied
set ftp_modified_ftpusers 1
ftp_writefile_ftpusers
return 1
}
proc ftpDenyUser_delete {class object refObject op subOp data attr attrValueList osaData} {
global ftp_deny_users ftp_modified_ftpusers
if [catch {array names ftp_deny_users} users] {
set users {}
}
if {[lsearch $users $object] == -1} {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
unset ftp_deny_users($object)
set ftp_modified_ftpusers 1
ftp_writefile_ftpusers
return 1
}
######################################################################
proc virtual_do_mkdir {what where} {
global isOwner
switch -exact $what {
root {
set dir $where
set bas ""
}
banner -
logfile {
set dir [file dirname $where]
set bas [file tail $where]
}
default {
set dir ""
set bas ""
}
}
if {$dir != "" && ![file exists $dir]} {
if {$isOwner} {
exec /sbin/tfadmin swUser root /bin/mkdir -p $dir
} else {
mkdir -path $dir
}
}
}
proc ftpVirtual_list {class object refObject op subOp data attr attrValueList osaData} {
global ftp_virtual
if [catch {array names ftp_virtual} addresses] {
return {}
} else {
return $addresses
}
}
proc ftpVirtual_get {class object refObject op subOp data attr attrValueList osaData} {
global ftp_virtual ftp_virtual_lines
if {[catch {set record $ftp_virtual($object)}]} {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
switch -exact $attr {
address { set result $object }
logfile { set result [keylget record logfile] }
banner { set result [keylget record banner] }
root { set result [keylget record root] }
default { ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ATTRIBUTE [list "$attr" "$class"] }
}
return [list [list $attr $result]]
}
proc ftpVirtual_replace {class object refObject op subOp data attr attrValueList osaData} {
global ftp_virtual ftp_virtual_lines ftp_modified_ftpaccess ftp_lines
if {[catch {set record $ftp_virtual($object)}]} {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
set record_lines $ftp_virtual_lines($object)
set last_line end
foreach rec_attr [keylkeys record_lines] {
keylget record_lines $rec_attr line
if {$line != ""} {
set last_line $line
}
}
if {[lsearch [keylkeys attrValueList] root] == -1} {
set rootChanged 0
} else {
set rootChanged 1
}
foreach bmip_attr [keylkeys attrValueList] {
if {[catch {keylget record $bmip_attr rec_attrValue}]} {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ATTRIBUTE [list "$bmip_attr $class"]
}
keylget record_lines $bmip_attr rec_attrLine
keylget attrValueList $bmip_attr bmip_attrValue
if {$bmip_attrValue == ""} {
if {$rec_attrValue == ""} {
} else {
ftp_rmline $rec_attrLine
keylset record $bmip_attr ""
keylset record_lines $bmip_attr ""
}
} else {
if {$rec_attrValue == ""} {
set line [ftp_addline $last_line "virtual $object $bmip_attr $bmip_attrValue"]
keylset record $bmip_attr $bmip_attrValue
keylset record_lines $bmip_attr $line
virtual_do_mkdir $bmip_attr $bmip_attrValue
} else {
set ftp_lines($rec_attrLine) "virtual $object $bmip_attr $bmip_attrValue"
keylset record $bmip_attr $bmip_attrValue
virtual_do_mkdir $bmip_attr $bmip_attrValue
}
}
}
set ftp_virtual($object) $record
set ftp_virtual_lines($object) $record_lines
if {$rootChanged} {
writeVirtualShutdownFile $object
}
set ftp_modified_ftpaccess 1
ftp_writefile_ftpaccess
return {}
}
proc ftpVirtual_create {class object refObject op subOp data attr attrValueList osaData} {
global ftp_virtual ftp_modified_ftpaccess ftp_lines ftp_virtual_lines
if [catch {array names ftp_virtual} addresses] {
set addresses {}
}
if {[lsearch $addresses $object] != -1} {
ErrorPush {} 1 SCO_OSA_ERR_DUPLICATE_MANAGED_OBJECT_INSTANCE "$object"
}
set record {{banner ""} {logfile ""} {root ""}}
set record_lines {{banner ""} {logfile ""} {root ""}}
foreach bmip_attr [keylkeys attrValueList] {
if [catch {set bmip_attrValue [keylget attrValueList $bmip_attr]}] {
ErrorPush {} 1 SCO_OSA_ERR_PROCESSING_FAILURE_ON_ATTRIBUTE "$object"
}
if {[lsearch [keylkeys record] $bmip_attr] == -1} {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ATTRIBUTE [list "$bmip_attr $class"]
}
if {$bmip_attrValue == ""} {
continue
}
keylset record $bmip_attr $bmip_attrValue
set line [ftp_addline end "virtual $object $bmip_attr $bmip_attrValue"]
keylset record_lines $bmip_attr $line
virtual_do_mkdir $bmip_attr $bmip_attrValue
}
set ftp_virtual($object) $record
set ftp_virtual_lines($object) $record_lines
writeVirtualShutdownFile $object
set ftp_modified_ftpaccess 1
ftp_writefile_ftpaccess
return 1
}
proc ftpVirtual_delete {class object refObject op subOp data attr attrValueList osaData} {
global ftp_virtual ftp_modified_ftpaccess ftp_lines ftp_virtual_lines
if [catch {array names ftp_virtual} addresses] {
set addresses {}
}
if {[lsearch $addresses $object] == -1} {
ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_OBJECT_INSTANCE "$object"
}
set record_lines $ftp_virtual_lines($object)
foreach rec_attr [keylkeys record_lines] {
set rec_attrValue [keylget record_lines $rec_attr]
if {$rec_attrValue != ""} {
ftp_rmline $rec_attrValue
}
}
unset ftp_virtual($object)
unset ftp_virtual_lines($object)
set ftp_modified_ftpaccess 1
ftp_writefile_ftpaccess
return 1
}
proc writeVirtualShutdownFile {{objects ""}} {
global ftp_virtual isOwner
set filename [get_shutdown]
if {[cequal $filename ""]} {
return
}
if {![info exist ftp_virtual]} {
return
}
if {[cequal $objects ""]} {
set objects [array names ftp_virtual]
}
foreach object $objects {
keylget ftp_virtual($object) root root
set dir [file dirname $root/$filename]
if {$isOwner} {
catch {exec /sbin/tfadmin swUser root /bin/mkdir -p $dir}
exec /sbin/tfadmin cpfile $filename $root/$filename
} else {
catch {mkdir -path $dir}
exec /bin/cp $filename $root/$filename
}
}
}
proc writeGuestShutdownFile {{objects ""}} {
global ftp_guestgroup isOwner
set filename [get_shutdown]
if {[cequal $filename ""]} {
return
}
if {[cequal $objects ""]} {
set objects [list_guestgroup]
}
set pw_info [SaGetPwEnts]
foreach user [keylkeys pw_info] {
keylget pw_info $user.pw_gid group
keylget pw_info $user.pw_dir root
if {[lsearch $objects $group] == -1} {
continue
}
set dir [file dirname $root/$filename]
if {$isOwner} {
catch {exec /sbin/tfadmin swUser root /bin/mkdir -p $dir}
exec /sbin/tfadmin cpfile $filename $root/$filename
} else {
catch {mkdir -path $dir}
exec /bin/cp $filename $root/$filename
}
}
}
proc writeAnonShutdownFile {} {
global ftp_virtual isOwner
set filename [get_shutdown]
if {[cequal $filename ""]} {
return
}
set pw_info [SaGetPwEnts]
set ftp_info ""
keylget pw_info ftp ftp_info
set root ""
keylget ftp_info pw_dir root
if {[cequal $root ""]} {
return
}
set dir [file dirname $root/$filename]
if {$isOwner} {
catch {exec /sbin/tfadmin swUser root /bin/mkdir -p $dir}
exec /sbin/tfadmin cpfile $filename $root/$filename
} else {
catch {mkdir -path $dir}
exec /bin/cp $filename $root/$filename
}
}
######################################################################
proc ftpLog_get {class object refObject op subOp data attr attrValueList osaData} {
global ftp_log
logRead
if {$attrValueList == {}} {
set attrValueList { domain current_time transfer_time remote_host \
file_size filename transfer_type action \
direction access_mode username \
service_name auth_method user_id }
}
set results {}
foreach entry $ftp_log {
set rec {}
foreach attr $attrValueList {
keylset rec $attr [keylget entry $attr]
}
lappend results $rec
}
return $results
}
proc ftpLog_action {class object refObject op subOp data attr attrValueList osaData} {
global ftp_Loglen ftp_Logmask
switch $subOp {
length {
set num [lindex $data 0]
if {[ctype digit $num] && ($num >= 0)} {
set ftp_Loglen $num
}
}
mask {
set ftp_Logmask $data
}
default { ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ACTION $subOp }
}
return
}
############################################################
proc OSA:get_ftp_info {field} {
global Main
if {[catch {SaGetPwEnts} pw_ents]} {
return
}
if {[catch {keylget pw_ents ftp} ftp_ent]} {
return
}
return [keylget ftp_ent $field]
}
proc OSA:set_ftp_info {what {home ""} {uid ""}} {
global errorCode isOwner
set opti "-i"
set optU "-U"
set optn "-n 0"
if {$home != ""} {
set home "-d $home"
}
switch -exact $what {
create {
if {$uid != ""} {
set uid "-u $uid $opti"
}
if {$isOwner} {
catch {exec /sbin/tfadmin swUser root /bin/mkdir -p $home}
set com "/sbin/tfadmin useradd -g 1 -s /bin/true -c \"Anonymous FTP\" $home $uid ftp"
} else {
catch {exec /bin/mkdir -p $home}
set com "/usr/sbin/useradd -g 1 -s /bin/true -c \"Anonymous FTP\" $home $uid ftp"
}
set err SCO_FTPOSA_ERR_ANON_CREATE
}
modify {
if {$uid != ""} {
set uid "-u $uid $optU"
}
if {$isOwner} {
catch {exec /sbin/tfadmin swUser root /bin/mkdir -p $home}
set com "/sbin/tfadmin usermod $home $uid ftp"
} else {
catch {exec /bin/mkdir -p $home}
set com "/usr/sbin/usermod $home $uid ftp"
}
set err SCO_FTPOSA_ERR_ANON_MODIFY
}
delete {
if {$isOwner} {
set com "/sbin/tfadmin userdel $optn ftp"
} else {
set com "/usr/sbin/userdel $optn ftp"
}
set err SCO_FTPOSA_ERR_ANON_DELETE
}
default {
set res 1
set err SCO_FTPOSA_ERR_ANON_INVALID_ACTION
}
}
set com "exec $com"
set rc 0
if {[catch {eval $com} out]} {
if {[cequal $what "modify"] && [lindex $errorCode 2] == 4} {
set err SCO_FTPOSA_ERR_ANON_MODIFY_AGED
}
ErrorPush {} 1 $err
}
}
proc ftpAnon_get {class object refObject op subOp data attr attrValueList osaData} {
switch $attr {
home { set result [OSA:get_ftp_info pw_dir]}
uid { set result [OSA:get_ftp_info pw_uid]}
default { ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ATTRIBUTE [list "$attr" "$class"] }
}
return [list [list $attr $result]]
}
proc ftpAnon_replace {class object refObject op subOp data attr attrValueList osaData} {
set ftp_home [OSA:get_ftp_info pw_dir]
set ftp_uid [OSA:get_ftp_info pw_uid]
if {[catch {keylget attrValueList home} attr_home]} {
set attr_home ""
}
if {[catch {keylget attrValueList uid} attr_uid]} {
set attr_uid ""
}
if {$ftp_home != "" && $ftp_uid != "" && ($attr_home != "" || $attr_uid != "")} {
if {$attr_home == ""} {
set attr_home $ftp_home
}
if {$attr_uid == ""} {
set attr_uid $ftp_uid
}
if {$attr_home != $ftp_home || $attr_uid != $ftp_uid} {
OSA:set_ftp_info modify $attr_home $attr_uid
}
} elseif {$ftp_home != "" && $ftp_uid != ""} {
OSA:set_ftp_info delete
} elseif {$attr_home != "" && $attr_uid != ""} {
OSA:set_ftp_info create $attr_home $attr_uid
} elseif {$attr_home != "" || $attr_uid != ""} {
ErrorPush {} 1 SCO_FTPOSA_ERR_ANON_INVALID_ACTION
} else {
}
return
}
proc ftpAnon_action {class object refObject op subOp data attr attrValueList osaData} {
switch $subOp {
ageduid { set result [get_ageduid]}
default { ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ACTION $subOp }
}
return $result
}
proc get_ageduid {} {
global isOwner
if {![file exists /etc/security/ia/ageduid]} {
return
}
if {$isOwner} {
set fd [open "| /sbin/tfadmin readfile /etc/security/ia/ageduid" r]
} else {
set fd [open "/etc/security/ia/ageduid" r]
}
set uids ""
while {! [eof $fd]} {
gets $fd line
set line [split $line ":"]
if {[lindex $line 0] != ""} {
lappend uids [lindex $line 0]
}
}
close $fd
return [lrmdups $uids]
}
############################################################
proc ftp_readshutdownfile {} {
readShutdownFile
}
proc isValidShutdownData {keep} {
global ftp_shutdown_data
set valid 1
set year $ftp_shutdown_data(year)
set month $ftp_shutdown_data(month)
set day $ftp_shutdown_data(day)
set hour $ftp_shutdown_data(hour)
set minute $ftp_shutdown_data(minute)
set deny_offset $ftp_shutdown_data(deny_offset)
set disc_offset $ftp_shutdown_data(disc_offset)
if {$year < 1970 || $year > 2036 || \
$month < 0 || $month > 11 || \
$day < 1 || $day > 31 || \
$hour < 0 || $hour > 23 || \
$minute < 0 || $minute > 59} {
set year [fmtclock [getclock] "%Y"]
set month [expr [fmtclock [getclock] "%m"] - 1]
set day [fmtclock [getclock] "%d"]
set hour [fmtclock [getclock] "%H"]
set minute [fmtclock [getclock] "%M"]
set valid 0
}
if {[clength $deny_offset] != 4} {
set deny_offset 0030
set valid 0
}
set h [crange $deny_offset 0 1]
set m [crange $deny_offset 2 3]
if {$h < 0 || $h > 23} {
set h 01
set valid 0
}
if {$m < 0 || $m > 49} {
set m 00
set valid 0
}
set deny_offset ${h}${m}
if {[clength $disc_offset] != 4} {
set disc_offset 0010
set valid 0
}
set h [crange $disc_offset 0 1]
set m [crange $disc_offset 2 3]
if {$h < 0 || $h > 23} {
set h 01
set valid 0
}
if {$m < 0 || $m > 49} {
set m 00
set valid 0
}
set disc_offset ${h}${m}
if {$keep} {
set ftp_shutdown_data(year) $year
set ftp_shutdown_data(month) $month
set ftp_shutdown_data(day) $day
set ftp_shutdown_data(hour) $hour
set ftp_shutdown_data(minute) $minute
set ftp_shutdown_data(deny_offset) $deny_offset
set ftp_shutdown_data(disc_offset) $disc_offset
}
return $valid
}
proc isShutdownFileModified {} {
global ftp_shutdown_data
set filename [get_shutdown]
if {![file exists $filename]} {
return TRUE
}
if {[file mtime $filename] != $ftp_shutdown_data(MTIME)} {
return TRUE
}
return FALSE
}
proc readShutdownFile {} {
global ftp_shutdown_data isOwner
set filename [get_shutdown]
set ftp_shutdown_data(year) 9999
set ftp_shutdown_data(month) 0
set ftp_shutdown_data(day) 0
set ftp_shutdown_data(hour) 0
set ftp_shutdown_data(minute) 0
set ftp_shutdown_data(deny_offset) 0
set ftp_shutdown_data(disc_offset) 0
set ftp_shutdown_data(stext) ""
set ftp_shutdown_data(STATE) enabled
set ftp_shutdown_data(MTIME) 0
if {$isOwner} {
if {[catch {open "|/sbin/tfadmin readfile $filename" r} fd]} {
return SCO_FTPOSA_ERR_OPEN_SHUTDOWN_FILE
}
} else {
if {[catch {open $filename r} fd]} {
return SCO_FTPOSA_ERR_OPEN_SHUTDOWN_FILE
}
}
set stime [lgets $fd]
set stext "[read $fd]"
close $fd
if {[llength $stime] == 7} {
set ftp_shutdown_data(year) [lindex $stime 0]
set ftp_shutdown_data(month) [lindex $stime 1]
set ftp_shutdown_data(day) [lindex $stime 2]
set ftp_shutdown_data(hour) [lindex $stime 3]
set ftp_shutdown_data(minute) [lindex $stime 4]
set ftp_shutdown_data(deny_offset) [lindex $stime 5]
set ftp_shutdown_data(disc_offset) [lindex $stime 6]
}
set ftp_shutdown_data(stext) $stext
if {! [isValidShutdownData 0]} {
set ftp_shutdown_data(year) 9999
}
if {$ftp_shutdown_data(year) == 9999} {
set ftp_shutdown_data(STATE) enabled
} else {
set ftp_shutdown_data(STATE) disabled
}
}
proc writeShutdownFile {} {
global ftp_shutdown_data isOwner
set filename [get_shutdown]
if {$isOwner} {
if {[catch {open "|/sbin/tfadmin writefile $filename" w} fd]} {
return SCO_FTPOSA_ERR_OPEN_SHUTDOWN_FILE
}
} else {
if {[catch {open $filename w} fd]} {
return SCO_FTPOSA_ERR_OPEN_SHUTDOWN_FILE
}
}
if {$ftp_shutdown_data(STATE) == "enabled"} {
set ftp_shutdown_data(year) 9999
puts $fd ""
} else {
puts $fd "$ftp_shutdown_data(year) $ftp_shutdown_data(month) $ftp_shutdown_data(day) $ftp_shutdown_data(hour) $ftp_shutdown_data(minute) $ftp_shutdown_data(deny_offset) $ftp_shutdown_data(disc_offset)"
}
puts $fd $ftp_shutdown_data(stext)
close $fd
set ftp_shutdown_data(MTIME) [file mtime $filename]
writeAnonShutdownFile
writeVirtualShutdownFile
writeGuestShutdownFile
}
proc ftpShutdown_create {class object refObject op subOp data attr attrValueList osaData} {
global ftp_shutdown_data
foreach attr [keylkeys attrValueList] {
set ftp_shutdown_data($attr) "[keylget attrValueList $attr]"
}
set ftp_shutdown_data(STATE) disabled
writeShutdownFile
return $attrValueList
}
proc ftpShutdown_delete {class object refObject op subOp data attr attrValueList osaData} {
global ftp_shutdown_data
set ftp_shutdown_data(STATE) enabled
writeShutdownFile
return {}
}
proc ftpShutdown_get {class object refObject op subOp data attr attrValueList osaData} {
global ftp_shutdown_data
set results {}
foreach attr $attrValueList {
keylset results $attr "$ftp_shutdown_data($attr)"
}
return $results
}
proc ftpShutdown_action {class object refObject op subOp data attr attrValueList osaData} {
switch $subOp {
server_state { return [OSA:getServerState]}
default { ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ACTION $subOp }
}
return ""
}
proc offset2time {offset} {
set h [crange $offset 0 1]
set m [crange $offset 2 3]
return [expr $h * 3600 + $m * 60]
}
proc OSA:getServerState {} {
global ftp_shutdown_data
set results {{server unknown} {shutdown unknown}}
keylset results server $ftp_shutdown_data(STATE)
if {[isShutdownFileModified]} {
readShutdownFile
}
if {$ftp_shutdown_data(STATE) == "disabled"} {
set shutdown_time [convertclock "$ftp_shutdown_data(hour):$ftp_shutdown_data(minute) [expr 1 + $ftp_shutdown_data(month)]/$ftp_shutdown_data(day)/$ftp_shutdown_data(year)"]
set deny_time [offset2time $ftp_shutdown_data(deny_offset)]
set disc_time [offset2time $ftp_shutdown_data(disc_offset)]
set now [getclock]
if {$now < $shutdown_time-$deny_time} {
keylset results shutdown scheduled
} elseif {$now >= $shutdown_time-$deny_time && $now < $shutdown_time-$disc_time} {
keylset results shutdown deny
} elseif {$now >= $shutdown_time-$disc_time && $now < $shutdown_time} {
keylset results shutdown disc
} elseif {$now >= $shutdown_time} {
keylset results shutdown complete
}
} else {
keylset results shutdown none
}
return $results
}
############################################################
proc execute_anonhome {args} {
global ftp_OsaDir isOwner
set args [join $args]
if {$isOwner} {
set com "exec /sbin/tfadmin swUser root $ftp_OsaDir/anonhome $args"
} else {
set com "exec $ftp_OsaDir/anonhome $args"
}
if {[catch {eval "$com"} output]} {
return ""
}
return $output
}
proc report_anonhome {args} {
global ftp_OsaDir
set args [lindex $args 0]
set filename [lindex $args 0]
set report [lindex $args 1]
if {[catch {open "$filename" a} fd]} {
ErrorPush {} 1 SCO_OSA_ERR_PROCESSING_FAILURE
return 1
}
puts $fd $report
puts $fd "----------------------------------------"
close $fd
return
}
proc ftpAnonHome_action {class object refObject op subOp data attr attrValueList osaData} {
global isOwner
set result ""
switch $subOp {
execute {
set result [execute_anonhome $data]
}
shutdown {
set root $object
set filename [get_shutdown]
set dir [file dirname $root/$filename]
if {$isOwner} {
catch {exec /sbin/tfadmin swUser root /bin/mkdir -p $dir}
exec /sbin/tfadmin cpfile $filename $root/$filename
} else {
catch {mkdir -path $dir}
exec /bin/cp $filename $root/$filename
}
set result ""
}
report { set result [report_anonhome $data] }
default { ErrorPush {} 1 SCO_OSA_ERR_NO_SUCH_ACTION $subOp }
}
return $result
}
############################################################
ftp_init
OFBinding sco_ftp_CDT
OFBinding sco_ftpClass_CDT
OFBinding sco_ftpLimit_CDT
OFBinding sco_ftpAccess_CDT
OFBinding sco_ftpMessage_CDT
OFBinding sco_ftpDenyHost_CDT
OFBinding sco_ftpDenyUser_CDT
OFBinding sco_ftpLog_CDT
OFBinding sco_ftpShutdown_CDT
OFBinding sco_ftpVirtual_CDT
OFBinding sco_ftpAnon_CDT
OFBinding sco_ftpAnonHome_CDT