Lines Matching refs:user

105  *      - The user is in the list of users for their session.
107 * - This user can not access anything yet.
112 * - The user is in the list of users for their session.
113 * - References will be given out if the user is looked up.
114 * - The user can access files and pipes.
119 * - The user is in the list of users for their session.
120 * - References will not be given out if the user is looked up.
121 * - The trees the user connected are being disconnected.
122 * - The resources associated with the user remain.
127 * - The user is queued in the list of users of their session.
128 * - References will not be given out if the user is looked up.
129 * - The user has no more trees connected.
130 * - The resources associated with the user remain.
135 * new user object and adds it to the list of users for
141 * assigned in T0) update the state of this user object,
147 * makes the new user object available for requests.
154 * partially constructed user.
163 * with the user are deleted as well as the user. For the transition to
164 * occur, the user must be in the SMB_USER_STATE_LOGGED_OFF state and the
170 * The state machine of the user structures is controlled by 3 elements:
175 * There's a mutex embedded in the user structure used to protect its fields
178 * To insert the user into the list of users of the session and to remove
179 * the user from it, the lock must be entered in RW_WRITER mode.
181 * Rules of access to a user structure:
186 * while the user mutex is held.
188 * 2) All actions applied to a user require a reference count.
190 * 3) There are 2 ways of getting a reference count. One is when the user
191 * logs in. The other when the user is looked up.
193 * It should be noted that the reference count of a user registers the
194 * number of references to the user in other structures (such as an smb
197 * 1) The user is logged in. An user is anchored by their state. If there's
198 * no activity involving a user currently logged in, the reference
199 * count of that user is zero.
201 * 2) The user is queued in the list of users of the session. The fact of
223 * Create a new user.
235 smb_user_t *user;
242 user = kmem_cache_alloc(smb_cache_user, KM_SLEEP);
243 gen = (user->u_ssnid + 1) & 7;
244 bzero(user, sizeof (smb_user_t));
246 user->u_refcnt = 1;
247 user->u_session = session;
248 user->u_server = session->s_server;
249 user->u_logon_time = gethrestime_sec();
251 if (smb_idpool_alloc(&session->s_uid_pool, &user->u_uid))
253 user->u_ssnid = SMB_USER_SSNID(user) + gen;
255 mutex_init(&user->u_mutex, NULL, MUTEX_DEFAULT, NULL);
256 user->u_state = SMB_USER_STATE_LOGGING_ON;
257 user->u_magic = SMB_USER_MAGIC;
261 smb_llist_insert_tail(&session->s_user_list, user);
266 * If we added the first user to the session, cancel the
281 return (user);
284 if (user->u_uid != 0)
285 smb_idpool_free(&session->s_uid_pool, user->u_uid);
286 kmem_cache_free(smb_cache_user, user);
291 * Fill in the details of a user, meaning a transition
296 smb_user_t *user,
307 ASSERT(user->u_magic == SMB_USER_MAGIC);
312 mutex_enter(&user->u_mutex);
314 if (user->u_state != SMB_USER_STATE_LOGGING_ON) {
315 mutex_exit(&user->u_mutex);
323 authsock = user->u_authsock;
324 user->u_authsock = NULL;
325 tmo = user->u_auth_tmo;
326 user->u_auth_tmo = NULL;
328 user->u_state = SMB_USER_STATE_LOGGED_ON;
329 user->u_flags = flags;
330 user->u_name_len = strlen(account_name) + 1;
331 user->u_domain_len = strlen(domain_name) + 1;
332 user->u_name = smb_mem_strdup(account_name);
333 user->u_domain = smb_mem_strdup(domain_name);
334 user->u_audit_sid = audit_sid;
336 smb_user_setcred(user, cr, privileges);
338 mutex_exit(&user->u_mutex);
346 smb_authsock_close(user, authsock);
354 * Change the user state to "logging off" and disconnect trees.
355 * The user list must not be entered or modified here.
362 smb_user_t *user)
367 ASSERT(user->u_magic == SMB_USER_MAGIC);
369 mutex_enter(&user->u_mutex);
370 ASSERT(user->u_refcnt);
371 switch (user->u_state) {
373 authsock = user->u_authsock;
374 user->u_authsock = NULL;
375 tmo = user->u_auth_tmo;
376 user->u_auth_tmo = NULL;
377 user->u_state = SMB_USER_STATE_LOGGING_OFF;
378 mutex_exit(&user->u_mutex);
385 smb_authsock_close(user, authsock);
390 * The user is moved into a state indicating that the log off
393 user->u_state = SMB_USER_STATE_LOGGING_OFF;
394 mutex_exit(&user->u_mutex);
395 smb_session_disconnect_owned_trees(user->u_session, user);
396 smb_user_auth_logoff(user);
401 mutex_exit(&user->u_mutex);
406 mutex_exit(&user->u_mutex);
412 * Take a reference on a user. Do not return a reference unless the user is in
416 smb_user_hold(smb_user_t *user)
418 SMB_USER_VALID(user);
420 mutex_enter(&user->u_mutex);
422 if (user->u_state == SMB_USER_STATE_LOGGED_ON) {
423 user->u_refcnt++;
424 mutex_exit(&user->u_mutex);
428 mutex_exit(&user->u_mutex);
433 * Unconditionally take a reference on a user.
436 smb_user_hold_internal(smb_user_t *user)
438 SMB_USER_VALID(user);
440 mutex_enter(&user->u_mutex);
441 user->u_refcnt++;
442 mutex_exit(&user->u_mutex);
446 * Release a reference on a user. If the reference count falls to
447 * zero and the user has logged off, post the object for deletion.
453 smb_user_t *user)
455 smb_session_t *ssn = user->u_session;
457 SMB_USER_VALID(user);
462 mutex_enter(&user->u_mutex);
463 ASSERT(user->u_refcnt);
464 user->u_refcnt--;
466 switch (user->u_state) {
468 if (user->u_refcnt == 0) {
469 smb_session_t *ssn = user->u_session;
470 user->u_state = SMB_USER_STATE_LOGGED_OFF;
471 smb_llist_post(&ssn->s_user_list, user,
485 mutex_exit(&user->u_mutex);
489 * Timeout handler for user logons that stay too long in
493 * real work of logging off this user.
498 smb_user_t *user = arg;
501 SMB_USER_VALID(user);
507 sr = smb_request_alloc(user->u_session, 0);
512 * Check user state, and take a hold if it's
515 mutex_enter(&user->u_mutex);
516 if (user->u_state != SMB_USER_STATE_LOGGING_ON) {
517 mutex_exit(&user->u_mutex);
522 user->u_refcnt++;
523 mutex_exit(&user->u_mutex);
526 * The user hold is given to the SR, and released in
529 sr->uid_user = user;
530 sr->user_cr = user->u_cred;
534 user->u_server->sv_worker_pool,
560 * Determine whether or not the user is an administrator.
564 smb_user_is_admin(smb_user_t *user)
575 ASSERT(user);
576 ASSERT(user->u_cred);
578 if (SMB_USER_IS_ADMIN(user))
587 ksidlist = crgetsidlist(user->u_cred);
593 ksid2 = crgetsid(user->u_cred, KSID_USER);
601 user->u_flags |= SMB_USER_FLAG_ADMIN;
615 * This function should be called with a hold on the user.
618 smb_user_namecmp(smb_user_t *user, const char *name)
623 if (smb_strcasecmp(name, user->u_name, 0) == 0)
629 user->u_domain, user->u_name);
634 user->u_name, user->u_domain);
644 * If the enumeration request is for user data, handle the request
647 * This function should be called with a hold on the user.
650 smb_user_enum(smb_user_t *user, smb_svcenum_t *svcenum)
654 ASSERT(user);
655 ASSERT(user->u_magic == SMB_USER_MAGIC);
658 return (smb_user_enum_private(user, svcenum));
666 * Delete a user. The tree list should be empty.
668 * Remove the user from the session's user list before freeing resources
669 * associated with the user.
675 smb_user_t *user = (smb_user_t *)arg;
678 SMB_USER_VALID(user);
679 ASSERT(user->u_refcnt == 0);
680 ASSERT(user->u_state == SMB_USER_STATE_LOGGED_OFF);
681 ASSERT(user->u_authsock == NULL);
682 ASSERT(user->u_auth_tmo == NULL);
684 session = user->u_session;
688 smb_llist_remove(&session->s_user_list, user);
689 smb_idpool_free(&session->s_uid_pool, user->u_uid);
711 * This user is no longer on s_user_list, however...
717 mutex_enter(&user->u_mutex);
718 mutex_exit(&user->u_mutex);
720 user->u_magic = (uint32_t)~SMB_USER_MAGIC;
721 mutex_destroy(&user->u_mutex);
722 if (user->u_cred)
723 crfree(user->u_cred);
724 if (user->u_privcred)
725 crfree(user->u_privcred);
726 smb_mem_free(user->u_name);
727 smb_mem_free(user->u_domain);
728 kmem_cache_free(smb_cache_user, user);
732 smb_user_getcred(smb_user_t *user)
734 return (user->u_cred);
738 smb_user_getprivcred(smb_user_t *user)
740 return ((user->u_privcred)? user->u_privcred : user->u_cred);
745 * Assign the user cred and privileges.
747 * If the user has backup and/or restore privleges, dup the cred
751 smb_user_setcred(smb_user_t *user, cred_t *cr, uint32_t privileges)
827 user->u_cred = cr;
828 user->u_privcred = privcred;
829 user->u_privileges = privileges;
837 smb_user_enum_private(smb_user_t *user, smb_svcenum_t *svcenum)
854 rc = smb_user_netinfo_encode(user, pb, svcenum->se_bavail, &nbytes);
865 * Encode the NetInfo for a user into a buffer. NetInfo contains
866 * information that is often needed in user space to support RPC
870 smb_user_netinfo_encode(smb_user_t *user, uint8_t *buf, size_t buflen,
876 smb_user_netinfo_init(user, &info);
884 smb_user_netinfo_init(smb_user_t *user, smb_netuserinfo_t *info)
889 ASSERT(user);
890 ASSERT(user->u_domain);
891 ASSERT(user->u_name);
893 session = user->u_session;
901 info->ui_logon_time = user->u_logon_time;
902 info->ui_flags = user->u_flags;
903 info->ui_posix_uid = crgetuid(user->u_cred);
905 info->ui_domain_len = user->u_domain_len;
906 info->ui_domain = smb_mem_strdup(user->u_domain);
908 info->ui_account_len = user->u_name_len;
909 info->ui_account = smb_mem_strdup(user->u_name);
935 * Tell smbd this user is going away so it can clean up their
943 smb_user_auth_logoff(smb_user_t *user)
945 smb_server_t *sv = user->u_server;
951 audit_sid = user->u_audit_sid;