AtBoot : At boot execution program for NT - Unix-style cron utility
-------------------------------------------------------------------
Version 2.08

Didier CASSEREAU - Laboratoire Ondes et Acoustique, ESPCI
10 rue Vauquelin, 75005 PARIS, FRANCE
E-mail : Didier.Cassereau@espci.fr

Please report any comments, suggestions, bugs, ... and if you are satisfied too !



This package contains :
   - atboot.exe   : atboot executable file
   - at.exe       : at executable file
   - readme.txt   : this file
   - register.txt : contains the registration conditions
   - atboot.ini   : sample of initialization file
   - cron.config  : sample of cron configuration file

This program is free ; if you like it and use it frequently, a voluntary contribution for 
supporting the development would be appreciated.

Some new functionnalities are submitted to a registration. See register.txt for registration
conditions.


Installation
------------

Copy the files atboot.exe, atboot.ini and cron.config anywhere on your disk.
Edit the file atboot.ini and make the required changes. The different items that can be defined
are the following :

    [SERVICE]
    ServiceName=
    ServiceDisplayName=

ServiceName is the name of the service as registered in the services database.
ServiceDisplayName is the name of the service that appears in the Control Panel
Default values :  ServiceName=AtBoot-dc
                  ServiceDisplayName=NT AtBoot Srv (Didier CASSEREAU)

    [ATBOOT]
    Atboot Log=<full name of the atboot log file>
    Atboot Cmd Mask=<mask of the commands to be run at boot>
    Cron Log=<full name of the cron log file>
    Cron.Config=<full name of the cron configuration file>
    AT Log=<full name of the AT log file>
    AT File=<full name of the AT data file>
    AT AuthUsers=<list of authorized users>
    AT Run=1
    RunInBackground=1

If the log files are not specified, atboot does not log anything.

For compatibility reasons with previous versions :
- if the "Atboot Cmd Mask" parameter is not specified, the default is
    "\winnt\system32\atboot\*.bat"
- if the "Cron.Config" parameter is not specified, the default is
    "\winnt\system32\atboot\cron\cron.config"

Finally run "atboot -install" ; the file atboot.ini is read in the same directory as the exe file.

This installs and starts the "atboot" service ; it will be automatically restarted at each reboot
of your system.

The -install option can be followed by any user account name, and optionnally the corresponding
password. This allows the service to be started under the specified user id, instead of the default
(SYSTEM account). If you only specify the user account name on the command line, you will have to
enter the password (no echo).
The user account name can be part of a domain (Domain\username) or local to the machine (.\username).

The specified user must have the following privileges :
a) start a session as a service         (ouvrir une session en tant que service)
b) act as part of the operating system  (agir en tant que partie du systme d'exploitation)
c) increase quotas                      (augmenter les quotas)
d) replace a process-level token        (remplacer un jeton niveau de processus)
Privileges b), c) and d) are only required if you wish to run commands using a specific user id.


When Windows NT restarts :
1. the "atboot" starts and looks at all command files according to the specified mask
2. executes all these command files (do not specify windows applications)
3. creates a log file (if configured from atboot.ini) that contains all standard and
   errors outputs resulting from your command files
4. starts the cron utility
5. optionally starts the AT daemon

If you change "cron.config" while the service is running, the changes are automatically reloaded.

If the optional parameter RunInBackground is set to 1, the programs launched at boot are started in
a background mode, such that atboot does not block until these programs finish. In such case, all
outputs generated from these programs are lost.
By default, the parameter RunInBackground is set to 0.

The "AT File" parameter specifies the location for internal data storage ; if not specified, this
file is located in the same directory as the program atboot.exe.
The "AT AuthUsers" parameter specifies an optional list of authorized users that can remove queued 
requests they do not own.
The "AT Run" indicates if the AT daemon must be started (1) or not (0, default).



Using AT
--------

The program atboot.exe allows to specify scheduled requests that are removed from the queue once they have
been executed, such that the corresponding request are run once only.
The program at.exe allows to control the AT requests queued by any atboot server on the network. Using this
functionnality requires TCP/IP.

It is first required to set a tcp/ip port number that will be used by at/atboot. This port number must be
the same on all computers over the network, it must not be used by another network tool. Run the 
following command :

	atboot -insttcp <port number>

The port number can be any positive integer (greater than 1024 to avoid potential problems 
with unix systems).
Suggested value : 28000

This command just appends the following lines
    #
    # ATBOOT Daemon (Didier CASSEREAU)
    #
    atboot-dc  28000/tcp
to your file \winnt\system32\drivers\etc\services.


The program at.exe can be used with the following syntax :

    at [ -l | -q | -r ] [ -s server ] [ -i id ] [ -u user ] [ -p password ] [ -t sched ] -c cmd

-l : lists all queued requests on the specified server
-q : transmits a new request to be queued by the specified server
-r : removes an existing request on the specified server

-s : specifies the server (local hostname by default)
-i : specifies a request id (used with -r)
-u : specifies the user who must run the queued request (current user by default)
-p : specifies the user's password (if not specified, you have to enter it without echo)
-t : specifies the date/time for running the request
-c : specifies the command line to run 

To transmit a request, the "-c cmd" option must be the last one on the command line.

Date/time format specification : two formats are identified
    MM.DD.YYYY.hh:mm (month, day, year, hour, minute)
    hh:mm            (hour, minute)

A user can be specified as "username" or "domain\username".

Only the user who owns the request can remove it. 
Authorized users defined by "AT AuthUsers" (atboot.ini) can remove any request.

Example :
    at -q -s server -u "john doe" -t 10:25 -c "dir c:\ /s > c:\temp\dir.log"



Configuring cron commands for authorized users
----------------------------------------------

It is now possible to run cron commands in the security context of any authorized users.

To do this, it is first necessary to create a database of authorized users. The program atboot.exe
support new options that allow to manage this database :

   atboot -reguser [ user [ password ] ]
   atboot -reglist
   atboot -regdeny [ user ]

The "-reguser" option allows to add a new authorized user, or replace an existing one. For security
reasons, it is necessary to enter the user's password.

The "-reglist" option allows to list the currently authorized users.

The "-regdeny" option allows to remove an authorized user from the database.

The database file is located in the same directory as atboot.exe, with an extension .reg. For security
reasons, it is highly recommended that standard users cannot have any access to the files atboot.exe
and atboot.reg.

The username can reference a domain as follows : domain\username.


Once the authorized users are correctly configured, the file "cron.config" must be changed. If the file
contains a line like
    
    $user="<username>" or $user="<domain\username>"

all following cron entries are run in the security context of the specified user, assuming that he is
registered in the database with the correct password, until a new $user entry is found.
If the file does not contain any $user entry, all cron commands are run in the default security context.

The "$user" entry can be followed by optiona arguments : env_ttl=<num> pwd_ttl=<num>
   - env_ttl specifies the maximum time to live of the user environment, it must be specified in
     minutes and defaults to 1440 (24 hours)
   - pwd_ttl specifies the maximum time to live of the user authentification, it must be specified in
     minutes and defaults to 1440 (24 hours)


Warning : this functionnality may represent a serious security hole since atboot.exe must store some
informations about authorized users (name, password). Of course the file is crypted, but it is highly
recommended to protect these files if you want to use this possibility.


Rules to determine the user environment :

- atboot first checks if the user is the currently logged-on user ; if yes, the environment and
  user profile are read from HKEY_CURRENT_USER from the registry

- then atboot requests user information from the SAM database, including the profile path

- either the profile path is defined : this means that the user account manager explicitly 
  specifies the user profile that is generally located on the disk of the domain server
  in that case, atboot tries to read the user profile from the user specific registry stored in
  the user profile path ; in case of failure, it tries again with locally stored profiles

- or the profile path is not defined : this means that the user has local profiles only stored 
  on the different workstations he uses ; in that case, atboot tries to identify the correct 
  profile path and load the corresponding registry entries ; in case of failure, the environment
  variable is not defined




Log files
---------

AtBoot generates three log files :
1. one corresponding to the command files executed at the end of the boot procedure
   no default
2. one corresponding to the cron daemon
   no default
3. one corresponding to the AT daemon
   no default
   


Revisions
---------

2.07 --> 2.08 :
   * possibility to change the name/display name of the service

2.06 --> 2.07 :
   * the evaluation version can run some restricted at commands
   * previous versions of atboot change (if necessary, e.g. running a cron command with a specific user id)
     the DACL of the current desktop and windowstation in an incorrect manner, resulting in an excessive
     accumulation of incorrect DACLs : this yields an initialization failure of screen savers.
   * the DACL of the current desktop and windowstation is restored if a modification has been required
     (e.g. running a cron command with a specific user id)

2.05 --> 2.06 :
   * if the service is run under as user id that differs from the default (SYSTEM), the user environment
     is loaded as for authorized users
   * an excessive CPU usage is sometimes visible with atboot, particularly if the cron service has to
     start several tasks simultaneously ; the problem is now fixed
   * a new option "-check" to check the keycodes (if registered)

2.04 --> 2.05 :
   * the generation of randomly crypted files (at and cron/user) was incorrect ; the problem is fixed
   * when loading the user environment, the user defined path is appended to the system path 
   * the user environment and authentification can have a restricted validity in time, forcing a periodic
     check

2.03 --> 2.04 :
   * the unregistered version can run some restricted cron commands in the context of an authorized user
   * the AT and cron commands use the system and user environment settings

2.02 --> 2.03 :
   * cron commands can be run in the security context on any authorized user

2.01 --> 2.02 :
   * Access Violation if the log files are not defined ; the problem is now fixed.

2.00 --> 2.01 :
   * the AT daemon

1.11 --> 2.00 :
   * the cron configuration file can now start some tasks depending on the existence/upgrade of
     a specific control file on the disk.
   * possibility to launch the initial commands in a background mode.

1.10 --> 1.11 :
   * version 1.10 searches the cron.config file in winnt\system32\atboot\cron and does not take
     into account the specification from the initialization file ; this problem is fixed

1.09 --> 1.10 :
   * it is now possible to specify the location of the initial commands to run at boot, and the
     name of the cron configuration file ; thus it is no more required to install atboot in the
     winnt\system32\atboot directory.

1.08 --> 1.09 :
   * the service duplicates system handles, and one of them is not closed ! resulting in an increasing 
     amount of memory usage with time ; this fix is complementary to the problems fixed with v1.06 

1.07 --> 1.08 :
   * possibility to setup atboot running under a specified user id, instead of the default (SYSTEM)

1.06 --> 1.07 :
   * possibility to specify the name of the log files
   * some temporary debug informations in the log file
   
1.05 --> 1.06 :
   * running the cron services yields a permanently increasing memory usage, resulting in some excessive
     usage of system resources ; this problem has been fixed.

1.04 --> 1.05 :
   * if the last line of the cron config file does not terminate with a special character like <linefeed>
     or <return>, the last character of the corresponding string is removed ; this bug has been fixed.
    
1.03 --> 1.04 :
   * more stable memory management, without consequences in the context of this program  
    
1.02 --> 1.03 :
   * bug correction that makes the cron service unusable
   	
1.01 --> 1.02 :
   * Unix-style cron service

1.00 --> 1.01 : 
   * the AtBoot service terminates incorrectly, resulting in an error message (EventLog)
     this error message does not alter the functionnality of AtBoot
   * if AtBoot fails creating (updating) the appropriate log file, the error message is
     reported (EventLog)


Restrictions
------------

All functionnalities described in this file are available, except the following that are submitted 
to registration :

* possibility to start some tasks depending on the existence/upgrade of a specific control 
  file on the disk

* the AT daemon 

* the possibility for authorized userd to run cron commands is restricted as follows :
    - only one authorized user at a time
    - only three successive cron commands ; after cron commands are ignored

* changing the name/display name of the service

