2021-03-16 10:49:09 +09:00
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright ( C ) 2018 Samsung Electronics Co . , Ltd .
*/
# include <linux/slab.h>
2021-04-02 12:47:14 +09:00
# include <linux/mm.h>
2021-03-16 10:49:09 +09:00
# include "user_config.h"
# include "../transport_ipc.h"
struct ksmbd_user * ksmbd_login_user ( const char * account )
{
struct ksmbd_login_response * resp ;
struct ksmbd_user * user = NULL ;
resp = ksmbd_ipc_login_request ( account ) ;
if ( ! resp )
return NULL ;
if ( ! ( resp - > status & KSMBD_USER_FLAG_OK ) )
goto out ;
user = ksmbd_alloc_user ( resp ) ;
out :
2021-04-02 12:47:14 +09:00
kvfree ( resp ) ;
2021-03-16 10:49:09 +09:00
return user ;
}
struct ksmbd_user * ksmbd_alloc_user ( struct ksmbd_login_response * resp )
{
struct ksmbd_user * user = NULL ;
2021-03-30 12:40:47 +09:00
user = kmalloc ( sizeof ( struct ksmbd_user ) , GFP_KERNEL ) ;
2021-03-16 10:49:09 +09:00
if ( ! user )
return NULL ;
user - > name = kstrdup ( resp - > account , GFP_KERNEL ) ;
user - > flags = resp - > status ;
user - > gid = resp - > gid ;
user - > uid = resp - > uid ;
user - > passkey_sz = resp - > hash_sz ;
2021-03-30 12:40:47 +09:00
user - > passkey = kmalloc ( resp - > hash_sz , GFP_KERNEL ) ;
2021-03-16 10:49:09 +09:00
if ( user - > passkey )
memcpy ( user - > passkey , resp - > hash , resp - > hash_sz ) ;
if ( ! user - > name | | ! user - > passkey ) {
kfree ( user - > name ) ;
2021-04-02 09:25:35 +09:00
kfree ( user - > passkey ) ;
kfree ( user ) ;
2021-03-16 10:49:09 +09:00
user = NULL ;
}
return user ;
}
void ksmbd_free_user ( struct ksmbd_user * user )
{
2021-10-13 17:28:31 +09:00
ksmbd_ipc_logout_request ( user - > name , user - > flags ) ;
2021-03-16 10:49:09 +09:00
kfree ( user - > name ) ;
2021-04-02 09:25:35 +09:00
kfree ( user - > passkey ) ;
kfree ( user ) ;
2021-03-16 10:49:09 +09:00
}
int ksmbd_anonymous_user ( struct ksmbd_user * user )
{
if ( user - > name [ 0 ] = = ' \0 ' )
return 1 ;
return 0 ;
}
2021-12-16 10:26:43 +09:00
bool ksmbd_compare_user ( struct ksmbd_user * u1 , struct ksmbd_user * u2 )
{
if ( strcmp ( u1 - > name , u2 - > name ) )
return false ;
if ( memcmp ( u1 - > passkey , u2 - > passkey , u1 - > passkey_sz ) )
return false ;
return true ;
}