calendar(1): Use login caps for 'calendar -a'
* Use 'fork()' and 'setusercontext(LOGIN_SETALL)' for every user. With
this change, the complex function 'cal()' that parses user-owned
calendars is now executed with appropriate user privileges.
Previously it was run with privileges dropped only temporary for
execution of 'cal()', and fully dropped only before invoking 'sendmail'.
* In 'calendar -a' mode, the 'getenv("HOME")' in 'cal_fopen()' function
always returns the root's home directory instead of the current user's
home (after fork() and setusercontext()), which makes 'chdir(home)'
fail.
Fix this issue by moving the 'chdir(home)' to the 'main()' function in
'calendar.c'. In the meantime, back to home directory in
'cal_fopen()' function after opening the calendar file.
Partially based on FreeBSD's commit:
https://github.com/freebsd/freebsd/commit/7ff75f4a5a3d9ada5bd68384fdded357fa4c1105
UnifiedSplitRaw