<jupyter_start><jupyter_text>User IDs Note: Run the notebook as regular user- every user on \*nix system has unique user ID number- **id** command can be used to display user's id<jupyter_code>! id
! id -u
! id user<jupyter_output>uid=1000(user) gid=1000(user) groups=1000(user),27(sudo)<jupyter_text>add 2 users to the system- add tom and jerry as users to play with notesearch program provided by Hacking book    - `$ sudo adduser tom`    - `$ sudo adduser jerry`<jupyter_code>! id tom
! id jerry
! finger tom<jupyter_output>Login: tom            			Name: <NAME>
Directory: /home/tom                	Shell: /bin/bash
Office: 123, x3132			Home Phone: 23-2323
Never logged in.
No mail.
No Plan.<jupyter_text>Setuid programs- some programs need to be accessed by all users- all users need to access and modify common files like /etc/passwd, /etc/shadow- how's that possible?    - **setuid** flag to the rescue- **setuid** programs have **s** in the ls -l output    - e.g., see passwd and chsh programs    - these programs are owned by root    - run as root user when any user run these programs    - the logic is written in such a way that only the line pertaining to the user can be modified by each user- running program can have both a real user ID and effective user ID    - can be retrieved using getuid() and geteuid() respectively    - see booksrc/uid_demo.c<jupyter_code># password file with user info
! ls -l /etc/passwd /etc/shadow
# password and chsh programs
! ls -l $(which passwd)  $(which chsh)<jupyter_output>-rwsr-xr-x 1 root root 47904 Jul 16  2019 /usr/bin/chsh
-rwsr-xr-x 1 root root 66284 Jul 16  2019 /usr/bin/passwd<jupyter_text>booksrc/uid_demo.c<jupyter_code>! cat ./booksrc/uid_demo.c
%%bash
in=./booksrc/uid_demo.c
out=uid_demo.out
gcc -o $out $in
! ./uid_demo.out
! ls -l uid_demo.out<jupyter_output><empty_output><jupyter_text>Modify the ownership to root from terminal as it requires sudo priviledge`sudo chown root:root ./uid_demo`<jupyter_code>%%bash
ls -l uid_demo.out
./uid_demo.out<jupyter_output><empty_output><jupyter_text>Set setuid flag using terminal`sudo chmod u+s ./uid_demo`<jupyter_code>%%bash
ls -l uid_demo.out
./uid_demo.out<jupyter_output><empty_output><jupyter_text>compile simplenote.c in booksrc- add several notes for the loggedin user- try adding notes for other users    - how do we fix the problem?    - better program... booksrc/notetaker.c<jupyter_code>! gcc -o simplenote.out ./booksrc/simplenote.c
! ls -al /tmp/notes<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09876543209876543, 'fraction_numerical': 0.020708880923934688, 'mean_word_length': 3.984126984126984, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '142320', 'license': 'MIT', 'n_tokens_mistral': 920, 'n_tokens_neox': 851, 'n_words': 303, 'path': 'UserIDs.ipynb', 'repo_name': 'rambasnet/CFundamentals', 'size': '2512'}