1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19: #include <hurd.h>
20: #include <hurd/port.h>
21: #include <hurd/id.h>
22: #include "set-hooks.h"
23:
24:
25: DEFINE_HOOK (_hurd_reauth_hook, (auth_t new_auth));
26:
27: #include <cthreads.h>
28: static struct mutex reauth_lock = MUTEX_INITIALIZER;
29:
30:
31:
32:
33: error_t
34: _hurd_setauth (auth_t new)
35: {
36: error_t err;
37: unsigned int d;
38: mach_port_t newport, ref;
39:
40:
41:
42: if (err = __mach_port_mod_refs (__mach_task_self (), new,
43: MACH_PORT_RIGHT_SEND, 1))
44: return err;
45:
46: HURD_CRITICAL_BEGIN;
47:
48:
49:
50: __mutex_lock (&reauth_lock);
51:
52:
53: __mutex_lock (&_hurd_id.lock);
54: _hurd_port_set (&_hurd_ports[INIT_PORT_AUTH], new);
55: _hurd_id.valid = 0;
56: if (_hurd_id.rid_auth)
57: {
58: __mach_port_deallocate (__mach_task_self (), _hurd_id.rid_auth);
59: _hurd_id.rid_auth = MACH_PORT_NULL;
60: }
61: __mutex_unlock (&_hurd_id.lock);
62:
63: if (_hurd_init_dtable != NULL)
64:
65:
66: for (d = 0; d < _hurd_init_dtablesize; ++d)
67: if (_hurd_init_dtable[d] != MACH_PORT_NULL)
68: {
69: mach_port_t new;
70: ref = __mach_reply_port ();
71: if (! __io_reauthenticate (_hurd_init_dtable[d],
72: ref, MACH_MSG_TYPE_MAKE_SEND) &&
73: ! HURD_PORT_USE (&_hurd_ports[INIT_PORT_AUTH],
74: __auth_user_authenticate
75: (port,
76: ref, MACH_MSG_TYPE_MAKE_SEND,
77: &new)))
78: {
79: __mach_port_deallocate (__mach_task_self (),
80: _hurd_init_dtable[d]);
81: _hurd_init_dtable[d] = new;
82: }
83: __mach_port_destroy (__mach_task_self (), ref);
84: }
85:
86: ref = __mach_reply_port ();
87: if (__USEPORT (CRDIR,
88: ! __io_reauthenticate (port,
89: ref, MACH_MSG_TYPE_MAKE_SEND) &&
90: ! __auth_user_authenticate (new,
91: ref, MACH_MSG_TYPE_MAKE_SEND,
92: &newport)))
93: _hurd_port_set (&_hurd_ports[INIT_PORT_CRDIR], newport);
94: __mach_port_destroy (__mach_task_self (), ref);
95:
96: ref = __mach_reply_port ();
97: if (__USEPORT (CWDIR,
98: ! __io_reauthenticate (port,
99: ref, MACH_MSG_TYPE_MAKE_SEND) &&
100: ! __auth_user_authenticate (new,
101: ref, MACH_MSG_TYPE_MAKE_SEND,
102: &newport)))
103: _hurd_port_set (&_hurd_ports[INIT_PORT_CWDIR], newport);
104: __mach_port_destroy (__mach_task_self (), ref);
105:
106:
107: RUN_HOOK (_hurd_reauth_hook, (new));
108:
109: __mutex_unlock (&reauth_lock);
110:
111: HURD_CRITICAL_END;
112:
113: return 0;
114: }
115:
116: int
117: __setauth (auth_t new)
118: {
119: error_t err = _hurd_setauth (new);
120: return err ? __hurd_fail (err) : 0;
121: }
122:
123: weak_alias (__setauth, setauth)