CptS 360 (System Programming) Unit 8: System Data Files Bob Lewis - - PowerPoint PPT Presentation

cpts 360 system programming unit 8 system data files
SMART_READER_LITE
LIVE PREVIEW

CptS 360 (System Programming) Unit 8: System Data Files Bob Lewis - - PowerPoint PPT Presentation

Unit 8: System Data Files CptS 360 (System Programming) Unit 8: System Data Files Bob Lewis School of Engineering and Applied Sciences Washington State University Spring, 2020 Bob Lewis WSU CptS 360 (Spring, 2020) Unit 8: System Data Files


slide-1
SLIDE 1

Unit 8: System Data Files

CptS 360 (System Programming) Unit 8: System Data Files

Bob Lewis

School of Engineering and Applied Sciences Washington State University

Spring, 2020

Bob Lewis WSU CptS 360 (Spring, 2020)

slide-2
SLIDE 2

Unit 8: System Data Files

Motivation

◮ System programs often need to find things out about their

environment:

◮ users ◮ groups ◮ accounting information ◮ time and date

◮ These APIs are good examples for small-scale systems.

Bob Lewis WSU CptS 360 (Spring, 2020)

slide-3
SLIDE 3

Unit 8: System Data Files

Reference

◮ Stevens & Rago Ch. 6 ◮ relevant man pages

Bob Lewis WSU CptS 360 (Spring, 2020)

slide-4
SLIDE 4

Unit 8: System Data Files

Password File

Data in /etc/passwd (and LDAP and NIS and ?) now accessed via:

◮ getpwuid(2) and getpwuid r(2) ◮ getpwnam(2) and getpwnam r(2) ◮ getpwent(2) and getpwent r(2) ◮ setpwent(2) and setpwent r(2) ◮ endpwent(2) and endpwent r(2)

Q: What are the “_r” variations for? (They’re a GNU extension.) The passwords themselves are kept in /etc/shadow (or its

  • equivalent. Remember why?), so...

Bob Lewis WSU CptS 360 (Spring, 2020)

slide-5
SLIDE 5

Unit 8: System Data Files

Shadow Password File

Data in /etc/shadow (and elsewhere) now accessed by key:

◮ getspnam(2) and getspnam r(2)

  • r sequentially:

◮ setspent(2) and setspent r(2) ◮ getspent(2) and getspent r(2) ◮ endspent(2) and endspent r(2)

and similar functions.

Bob Lewis WSU CptS 360 (Spring, 2020)

slide-6
SLIDE 6

Unit 8: System Data Files

Group File

Data in /etc/group (and elsewhere) now accessed via key:

◮ getgrgid(2) and getgrgid r(2) ◮ getgrnam(2) and getgrnam r(2)

  • r sequentially:

◮ setgrent(2) ◮ getgrent(2) ◮ endgrent(2)

This data does not depend on the calling process.

Bob Lewis WSU CptS 360 (Spring, 2020)

slide-7
SLIDE 7

Unit 8: System Data Files

Supplementary Group IDs

◮ getgroups(2)

gets supplementary group IDs (non-login groups of process

  • wner) of the calling process

◮ setgroups(2)

sets supplementary group IDs of the calling process (privilege CAP_SETGID to call)

◮ initgroups(2)

initializes supplementary group IDs for a given user

Bob Lewis WSU CptS 360 (Spring, 2020)

slide-8
SLIDE 8

Unit 8: System Data Files

Other Data “Files”

See Stevens & Rago Figure 6.6 (”Similar Routines ...”) used for

◮ hosts (e.g. gethostbyaddr(3) and gethostbyaddr r(3)) ◮ networks (e.g. getnetbyaddr(3) and getnetbyaddr r(3)) ◮ protocols (e.g. getprotobyaddr(3) and getprotobyaddr r(3)) ◮ services (e.g. getservbyaddr(3) and getservbyaddr r(3))

Same pattern (set – get – end) for sequential access.

Bob Lewis WSU CptS 360 (Spring, 2020)

slide-9
SLIDE 9

Unit 8: System Data Files

Login Accounting

Two files:

◮ /var/run/utmp

who’s currently logged on

◮ /var/log/wtmp

history of logins/logouts Keyed access:

◮ getutid(3) ◮ setutline(3)

Sequential access:

◮ getutent(3) ◮ setutent(3) ◮ endutent(3)

Bob Lewis WSU CptS 360 (Spring, 2020)

slide-10
SLIDE 10

Unit 8: System Data Files

System Identification

◮ uname(2) ◮ gethostname(2)

Bob Lewis WSU CptS 360 (Spring, 2020)

slide-11
SLIDE 11

Unit 8: System Data Files

Kernel Timekeeping

◮ The epoch is 00:00:00 on Thursday, Jan 1, 1970, UTC.

(Earlier dates are negative.)

◮ Time and date are kept as single quantity. ◮ kernel functions:

◮ time(2) ◮ returns a time_t (signed int) scalar ◮ standard ◮ allows 1 sec precision ◮ gettimeofday(2) ◮ fills in a struct timeval * ◮ allows µsec precision ◮ use timer*(3) functions to do timeval arithmetic ◮ timezone support is implementation-dependent

What’s so special about 03:14:07 UTC on Tuesday, January 19, 2038? How about Sunday, December 4, 292,277,026,596 (AD)?

Bob Lewis WSU CptS 360 (Spring, 2020)

slide-12
SLIDE 12

Unit 8: System Data Files

Utility Time Functions

◮ asctime(3) and asctime r(3) ◮ ctime(3) and ctime r(3) ◮ gmtime(3) and gmtime r(3) ◮ localtime(3) and localtime r(3) ◮ mktime(3) ◮ strftime(3) and strftime r(3) ◮ ctime(3) and ctime r(3)

Equivalent to asctime(localtime(t)). All have “_r” variations and work with time_t’s.

Bob Lewis WSU CptS 360 (Spring, 2020)

slide-13
SLIDE 13

Unit 8: System Data Files

Timekeeping Function Interdependencies

kernel time_t time(2) struct timeval gettimeofday(2) struct timespec clock_gettime(2) string (fixed) string (formatted) ctime(3) struct tm localtime(3) gmtime(3) asctime(3) strftime(3) mktime(3)

From Stevens & Rago Figure 6.8 (”Relationship of the various ...”). The dashed conversions depend on the local time zone.

Bob Lewis WSU CptS 360 (Spring, 2020)