COMP3000 Operating Systems W22: Tutorial 4

From Soma-notes
Revision as of 01:34, 27 January 2022 by Lianyingzhao (talk | contribs) (Created page with "In this tutorial, you will learn about how user accounts and logging in work through exploring [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w22/tut4/3000userlogin.c...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In this tutorial, you will learn about how user accounts and logging in work through exploring 3000userlogin.c. You’ll also have a better understanding of the permission system and the shell/terminal environment.

Make sure you use the original code from 3000userlogin for each question/task.

Tutorials are graded based on participation and effort (so no need to try to have the “correct” answers — what matters is the process), but you should still turn in your work. Submit your answers on Brightspace as a single text file named "<username>-comp3000-t4.txt" (where username is your MyCarletonOne username). The first four lines of this file should be "COMP 3000 Tutorial 4", your name, student number, and the date of submission.

The deadline is usually four days after the tutorial date (see the actual due date and time on the submission entry). Note that the submission entry is enforced by the system, so you may fail to get the effort marks even if it is one minute past the deadline.

You should also check in with your assigned TA online (by responding to the poll in the Teams channel tutorials-public or the private channel). Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session.

You get 1.5 marks for submitting answers that shows your effort and 0.5 for checking in, making this tutorial worth 2 points total.

Logging in to a Linux system

As mentioned in the lecture, in order to log in to a Linux-like system (including UNIX), the following steps must occur (potentially not in this order).

  1. The user must use a terminal to connect to the system, locally or remotely (e.g., initiated by /usr/sbin/getty)
  2. The user must authenticate themselves, proving an identify with authorized access to the system. By default, this is done through a username and password (e.g., by exec’ing /usr/bin/login).
  3. After authentication, login changes uid and gid to that of the new user.
  4. Login sets up other aspects of the user's context (mainly setting key environment variables).
  5. Login does an exec of the user's chosen/default shell.

3000userlogin is a basic implementation of steps 3-5. (Steps 1 and 2 are accomplished by running 3000userlogin in a shell, as running an external command means the shell also creates a new process for it, assuming an authenticated session with a terminal.)

When 3000userlogin is properly compiled and set up, you can run:

./3000userlogin student

and you'll be logged in (again) as "student". This only works when you’re already logged in as student (see below).

You can add a user with the adduser command. For example, to create the user "someuser":

sudo adduser someuser

Note you'll have to answer several questions. Then you need to switch to someuser (su someuser).

If you just compile 3000userlogin normally, you won't be able to log in as anyone except the current user (be it student or someuser). To set up 3000userlogin properly, do the following:

sudo chown root:root 3000userlogin
sudo chmod u+s 3000userlogin

The chown command makes the binary owned by root, and the chmod command makes it setuid. Thus, when the program is exec'd it will have an effective user ID of root (euid=0). To facilitate the following tasks, you may also want to create different versions of 3000userlogin by naming them, e.g., 3000userlogin.setuid and 3000userlogin.orig, of your choice.