Sunday, August 17, 2025

Source command

The command "source" command or "." is to run a command in the current shell (process), instead of spawning a new child process to run it.

For example, 

. ./program1 runs program 1 in the current shell.  The same command can be typed as source .program1

./program1 runs program1 in a child shell.

file redirection

In Linux, redirecting input and output of command uses  ">" or "<" characters.  For example, 

cat file1 file2 file3 1> outfile 2>&1

redirects the output of cat command to a file called outfile and error message also go to the same outfile.  The numbers 1, 2 etc are actually file descriptors.

Shorthand for 2>&1 is |&

Default file descriptor for ">" is 1 so 1 can be omitted

Default file descriptor for "<" is 0 (standard input)

BASH

The initialization of bash is different when it is started from login event or started as a shell after login.

When user login, Linux starts a shell based on configuration in /etc/passwd specified by admin.  If it is a bash shell, the command in /etc/profile will firstly be applied, then followed by all the script suffixed with .sh in /etc/profile.d.  The latter allow maintaining local customization to /etc/profile which may be replaced during upgrade.  Then .bach

-profile, .bash_login or .profile file in the user's home directory is executed to allow personalization.  When user log off, .bash_logout file will run to clean up like temp files.

When bash is invoked not from login, it will not run those files above.  Instead, it runs .bashrc in the user's home directory to initialize.  .bashrc usually call /etc/bashrc.

When bash is invoked in non-interactive mode (e.g. execute a script), none of the start up files above will be run.  The shell will only inherit the environment variables from its parent shell.

SUN RPC

When a server (service) using rpc starts, it registers with rpcbind (portmapper) process. It can either bind to a port it selected itself and register, or let rpcbind allocates a port afterwhich the server will bind itself to. 

When a client need to use rpc server, it send request to rpcbind which will return the port used by the server sought. The rpc library in client and server will handle encoding the request into rpc format and decide. 

Rpc client identify a rpc server using a rpc number that coded in /etc/rpc. The port is mapped in /etc/servcies 

Sunday, August 10, 2025

MySQL architecture

There are 3 layers. 

The layer handles connection, authentication and security 

The second layer is the optimizer, execution engine and cache. 

The bottom layer is the storage engines. The storage engine API make it transparent to the query. Transaction is implemented in this layer. 

Friday, August 8, 2025

Database logging

Logging allows the changed data to be updated to the table at a later time. Although logging is achieved by writing the data out to log, it has better performance than writing the data out to table  the reason is logging is always appending at the end of the log file as compare to randomly seek to the spot when writing to the table. The io is also less 

Isolation mode

Read uncommitted aka dirty read allows reading data that have not been committed by transaction. 

Read committed allows only retrieving rows that has been committed. But a repeating read may return different result as there are committed changes in between successive read

Repeatable read allows the same result to return in successive read but it still allows phantom read. Rows that inserted between successive read. T only protected the rows read from changing. 

Serializaruon is to do one query at a time thus preventing all changes until the current transaction commits. 

Sunday, August 3, 2025

Linux Link

ln command by default creates a hard link which is a file that share the same inode as the original file it links to.

Soft link (symbolic link) is a newer link type that addresses some disadvantage of hard link.  It can link to a directory.  It can like to entry in another file system.  It can link to an entry that does not exist currently (e.g. a file that is created from time to time).

When cd to a directory using symlink, the shell builtin pwd will display the name of the symlink that link to but /bin/pwd (utility) will display the destingation directory.  When you cd to .. it will return to the directory that holding the symlink.

Linux file and directory permissions

 To execute shell script, you mean r+x to the script file.  To execute a binary, you just need x.

The "+" after the permission indicated if the file has an ACL

Numbers to represent rwx is 1/2/4.  Or (add) the number to create composite permissions.  For example, 700 means 1+2+4 for owner and 0 for group/other.

Setuid/setgid change the permission x to s in the listing.  Set these permissions by specifying a 4th digit.  For example. 2700 or 4700 sets the setgid or setuid respectively.  "1" is to set the sticky bit to the program.

Kernel will not execute a script with setuid/setgid on.

Execute permission in directory indicated if the user can cd into the directory and access file that he has been permitted to.  If user has x but no r for a directory, he cannot display the directory file content (i.e. list of files in directory) using ls command.

Using ACL has overhead and should not enable ACL on system directory and files.  Not all file utility preserve ACL by default.  Destination filesystem may or may not support ACL.  In addition, the filesystem must be mounted with ACL enabled (default no ACL). 

ACL grant access to other user or group beside the owner's.  Beside ugo. ACL has a role called "mask" which specified the effective (maximum) permission ACL permitted for the directory or file.  Any ACL specified more than mask's will not be effective (i.e. denied).  Mask is usually set to the max permission allowed and individual ACL rule is more restrictive than mask's.

Registry tools

REGEDIT is a GUI tool to see and manipulate registry entries. 

REG.EXE is a CLI tool

REGINI is a CLI that can use a text file containing REG commands as input 

POWERSHELL has command to manipulate registry


.reg file

This is an exported registry file in text format. It is not the registry file itself. Content can be import into the registry. 

KHLM subkeys

SAM AND SECURITY

the former contains info that used to connect the pc to the domains it entitled to, including the local domain. The latter contains the security policy download from connected domain

SYSTEM

contain windows config, drives connected and file system info

SOFTWARE

contains info for windows installation and softwares installed. It is organised by vendor 

Registry structure

The registry is organized into 5 groups or sections. 

HKCR (class root) section keep info about registered software, OLE object class id and file associations

HKCU (current user) contains config options for the currently signed-in user like disvknlocation of the user folders, control panel settings and app config settings. 

HKLM (local machine) contains setting for the pc. It co tains the sub key files - SAM, security? System and software. Another file Hardware is created each time the pc starts containing detected plug and play hardware. This key also contain the files Components and BCD which contain boot configuration data. 

HKU (user) contain settings and options for the currently sign in user.

HKCC (current config) contains info gathered for the current session and will be discarded when season ends. 

HKEY_PERFORMANCE_DATA is not visible to Reddit. It contains performance data of the current session. It is discarded when the session ends

Saturday, August 2, 2025

Windows registry

First introduced in windows 95, registry is to consolidate ini files in windows 3.1. There are 5 main registry files residing in ststem32\config directory. 

SAM security access manager

Security

Software

System

User diff (used for OS upgrade)

Each user has its own registry files as well in the %userprifile% directory. They are 

ntuser.dat contain customisation for software and UsrClass.dat contains com related info specific to the user. 

Registry is managed by configuration manager in kernel. It has journaling to protect from corruption.