cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

user_config.c (1621B)


      1// SPDX-License-Identifier: GPL-2.0-or-later
      2/*
      3 *   Copyright (C) 2018 Samsung Electronics Co., Ltd.
      4 */
      5
      6#include <linux/slab.h>
      7#include <linux/mm.h>
      8
      9#include "user_config.h"
     10#include "../transport_ipc.h"
     11
     12struct ksmbd_user *ksmbd_login_user(const char *account)
     13{
     14	struct ksmbd_login_response *resp;
     15	struct ksmbd_user *user = NULL;
     16
     17	resp = ksmbd_ipc_login_request(account);
     18	if (!resp)
     19		return NULL;
     20
     21	if (!(resp->status & KSMBD_USER_FLAG_OK))
     22		goto out;
     23
     24	user = ksmbd_alloc_user(resp);
     25out:
     26	kvfree(resp);
     27	return user;
     28}
     29
     30struct ksmbd_user *ksmbd_alloc_user(struct ksmbd_login_response *resp)
     31{
     32	struct ksmbd_user *user = NULL;
     33
     34	user = kmalloc(sizeof(struct ksmbd_user), GFP_KERNEL);
     35	if (!user)
     36		return NULL;
     37
     38	user->name = kstrdup(resp->account, GFP_KERNEL);
     39	user->flags = resp->status;
     40	user->gid = resp->gid;
     41	user->uid = resp->uid;
     42	user->passkey_sz = resp->hash_sz;
     43	user->passkey = kmalloc(resp->hash_sz, GFP_KERNEL);
     44	if (user->passkey)
     45		memcpy(user->passkey, resp->hash, resp->hash_sz);
     46
     47	if (!user->name || !user->passkey) {
     48		kfree(user->name);
     49		kfree(user->passkey);
     50		kfree(user);
     51		user = NULL;
     52	}
     53	return user;
     54}
     55
     56void ksmbd_free_user(struct ksmbd_user *user)
     57{
     58	ksmbd_ipc_logout_request(user->name, user->flags);
     59	kfree(user->name);
     60	kfree(user->passkey);
     61	kfree(user);
     62}
     63
     64int ksmbd_anonymous_user(struct ksmbd_user *user)
     65{
     66	if (user->name[0] == '\0')
     67		return 1;
     68	return 0;
     69}
     70
     71bool ksmbd_compare_user(struct ksmbd_user *u1, struct ksmbd_user *u2)
     72{
     73	if (strcmp(u1->name, u2->name))
     74		return false;
     75	if (memcmp(u1->passkey, u2->passkey, u1->passkey_sz))
     76		return false;
     77
     78	return true;
     79}