T#8081 Moved users to usermngr

This commit is contained in:
Suvendhu Hansa 2022-12-02 11:29:39 +00:00 committed by Vivek Kumar Dutta
parent f635f43f24
commit 90ac63e15a
6 changed files with 45 additions and 278 deletions

View file

@ -28,7 +28,6 @@
#include "routing.h"
#include "firewall.h"
#include "dns.h"
#include "users.h"
#include "dsl.h"
#include "fast.h"
#include "dhcpv6.h"
@ -108,7 +107,6 @@ DMOBJ tDeviceObj[] = {
{"Routing", &DMREAD, NULL, NULL, "file:/etc/config/network", NULL, NULL, NULL, tRoutingObj, tRoutingParams, NULL, BBFDM_BOTH, NULL, "2.0"},
{"Firewall", &DMREAD, NULL, NULL, "file:/etc/config/firewall", NULL, NULL, NULL, tFirewallObj, tFirewallParams, NULL, BBFDM_BOTH, NULL, "2.0"},
{"DNS", &DMREAD, NULL, NULL, "file:/etc/config/network", NULL, NULL, NULL, tDNSObj, tDNSParams, NULL, BBFDM_BOTH, NULL, "2.0"},
{"Users", &DMREAD, NULL, NULL, "file:/etc/config/users", NULL, NULL, NULL, tUsersObj, tUsersParams, NULL, BBFDM_BOTH, NULL, "2.0"},
{"IEEE1905", &DMREAD, NULL, NULL, "file:/etc/config/ieee1905", NULL, NULL, NULL, tIEEE1905Obj, tIEEE1905Params, NULL, BBFDM_BOTH, NULL, "2.9"},
{"InterfaceStack", &DMREAD, NULL, NULL, "file:/etc/config/network", browseInterfaceStackInst, NULL, NULL, NULL, tInterfaceStackParams, NULL, BBFDM_BOTH, NULL, "2.0"},
{"USB", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tUSBObj, tUSBParams, NULL, BBFDM_BOTH, NULL, "2.0"},

View file

@ -1,256 +0,0 @@
/*
* Copyright (C) 2019 iopsys Software Solutions AB
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include "users.h"
/*************************************************************
* ENTRY METHOD
**************************************************************/
/*#Device.Users.User.{i}.!UCI:users/user/dmmap_users*/
static int browseUserInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("users", "user", "dmmap_users", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "user_instance", "user_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
/*************************************************************
* ADD & DEL OBJ
**************************************************************/
static int add_users_user(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s = NULL, *dmmap_user = NULL;
char sec_name[32];
snprintf(sec_name, sizeof(sec_name), "user_%s", *instance);
dmuci_add_section("users", "user", &s);
dmuci_rename_section_by_section(s, sec_name);
dmuci_set_value_by_section(s, "enabled", "0");
dmuci_set_value_by_section(s, "remote_access", "0");
dmuci_add_section_bbfdm("dmmap_users", "user", &dmmap_user);
dmuci_set_value_by_section(dmmap_user, "section_name", sec_name);
dmuci_set_value_by_section(dmmap_user, "user_instance", *instance);
return 0;
}
static int delete_users_user(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections_safe("users", "user", stmp, s) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_users", "user", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
/*************************************************************
* GET & SET PARAM
**************************************************************/
/*#Device.Users.UserNumberOfEntries!UCI:users/user/*/
static int get_users_user_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int cnt = get_number_of_entries(ctx, data, instance, browseUserInst);
dmasprintf(value, "%d", cnt);
return 0;
}
/*#Device.Users.User.{i}.Alias!UCI:dmmap_users/user,@i-1/user_alias*/
static int get_user_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "user_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
}
/*#Device.Users.User.{i}.Enable!UCI:users/user,@i-1/enabled*/
static int get_user_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "enabled", "1");
return 0;
}
static int get_user_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "section_name", value);
return 0;
}
/*#Device.Users.User.{i}.Password!UCI:users/user,@i-1/password*/
static int get_user_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = "";
return 0;
}
/*#Device.Users.User.{i}.RemoteAccessCapable!UCI:users/user,@i-1/remote_access*/
static int get_user_remote_accessable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "remote_access", "1");
return 0;
}
/*#Device.Users.User.{i}.Language!UCI:users/user,@i-1/language*/
static int get_user_language(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "language", value);
return 0;
}
static int set_user_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "user_alias", value);
return 0;
}
return 0;
}
static int set_user_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
switch (action) {
case VALUECHECK:
if (dm_validate_boolean(value))
return FAULT_9007;
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "enabled", b ? "1" : "0");
break;
}
return 0;
}
static int set_user_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
// Check if the value is empty
if (*value == '\0')
return FAULT_9007;
break;
case VALUESET:
// Update dmmap_users file
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "section_name", value);
// Update users config
dmuci_rename_section_by_section(((struct dmmap_dup *)data)->config_section, value);
break;
}
return 0;
}
static int set_user_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "password", value);
break;
}
return 0;
}
static int set_user_remote_accessable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
switch (action) {
case VALUECHECK:
if (dm_validate_boolean(value))
return FAULT_9007;
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "remote_access", b ? "1" : "0");
break;
}
return 0;
}
static int set_user_language(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 16, NULL, NULL))
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "language", value);
break;
}
return 0;
}
/**********************************************************************************************************************************
* OBJ & LEAF DEFINITION
***********************************************************************************************************************************/
/* *** Device.Users. *** */
DMOBJ tUsersObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys, version*/
{"User", &DMWRITE, add_users_user, delete_users_user, NULL, browseUserInst, NULL, NULL, NULL, tUsersUserParams, NULL, BBFDM_BOTH, LIST_KEY{"Username", "Alias", NULL}, "2.0"},
{0}
};
DMLEAF tUsersParams[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type, version*/
{"UserNumberOfEntries", &DMREAD, DMT_UNINT, get_users_user_number_of_entries, NULL, BBFDM_BOTH, "2.0"},
{0}
};
/* *** Device.Users.User.{i}. *** */
DMLEAF tUsersUserParams[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type, version*/
{"Alias", &DMWRITE, DMT_STRING, get_user_alias, set_user_alias, BBFDM_BOTH, "2.3"},
{"Enable", &DMWRITE, DMT_BOOL, get_user_enable, set_user_enable, BBFDM_BOTH, "2.0"},
{"Username", &DMWRITE, DMT_STRING, get_user_username, set_user_username, BBFDM_BOTH, "2.0"},
{"Password", &DMWRITE, DMT_STRING, get_user_password, set_user_password, BBFDM_BOTH, "2.0"},
{"RemoteAccessCapable", &DMWRITE, DMT_BOOL, get_user_remote_accessable, set_user_remote_accessable, BBFDM_BOTH, "2.0"},
{"Language", &DMWRITE, DMT_STRING, get_user_language, set_user_language, BBFDM_BOTH, "2.0"},
{0}
};

View file

@ -1,20 +0,0 @@
/*
* Copyright (C) 2019 iopsys Software Solutions AB
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
*/
#ifndef _USERS_H
#define _USERS_H
#include "libbbf_api/dmcommon.h"
extern DMOBJ tUsersObj[];
extern DMLEAF tUsersParams[];
extern DMLEAF tUsersUserParams[];
#endif

View file

@ -64,6 +64,20 @@ function generate_release()
cd ..
}
function install_libusermngr()
{
# clone and compile libusermngr
rm -rf /opt/dev/usermngr
exec_cmd git clone -b devel https://dev.iopsys.eu/iopsys/usermngr.git /opt/dev/usermngr
echo "Compiling libusermngr"
make clean -C /opt/dev/usermngr/src/
make -C /opt/dev/usermngr/src/
echo "installing libusermngr"
cp -f /opt/dev/usermngr/src/libusermngr.so /usr/lib/bbfdm
}
function install_libbbf()
{
COV_CFLAGS='-fprofile-arcs -ftest-coverage'
@ -85,6 +99,9 @@ function install_libbbf()
exec_cmd_verbose make install
ln -sf /usr/share/bbfdm/bbf.diag /usr/libexec/rpcd/bbf.diag
cd ..
echo "installing libusermngr"
install_libusermngr
}
function install_libbbf_test()

View file

@ -1042,6 +1042,16 @@ static void test_api_bbfdm_add_del_standard_object(void **state)
fault = dm_entry_param_method(ctx, CMD_DEL_OBJECT, "Device.Users.User.2.", "test_key", NULL);
assert_int_equal(fault, 0);
// delete the section from uci based on 'deleted' option since uci section is deleted from init script
struct uci_section *s = NULL, *stmp = NULL;
uci_foreach_sections_safe("users", "user", stmp, s) {
char *deleted = NULL;
dmuci_get_value_by_section_string(s, "deleted", &deleted);
if (deleted != NULL && strcmp(deleted, "1") == 0)
dmuci_delete_by_section(s, NULL, NULL);
}
dmuci_commit_package("users");
// Get name object after deleting instance 2 ==> expected "9005" error
fault = dm_entry_param_method(ctx, CMD_GET_NAME, "Device.Users.User.2.", "1", NULL);
assert_int_equal(fault, FAULT_9005);
@ -1050,6 +1060,16 @@ static void test_api_bbfdm_add_del_standard_object(void **state)
fault = dm_entry_param_method(ctx, CMD_DEL_OBJECT, "Device.Users.User.", "test_key", NULL);
assert_int_equal(fault, 0);
// delete the section from uci based on 'deleted' option since uci section is deleted from init script
s = NULL, stmp = NULL;
uci_foreach_sections_safe("users", "user", stmp, s) {
char *deleted = NULL;
dmuci_get_value_by_section_string(s, "deleted", &deleted);
if (deleted != NULL && strcmp(deleted, "1") == 0)
dmuci_delete_by_section(s, NULL, NULL);
}
dmuci_commit_package("users");
// Get name object after deleting all instances ==> expected "9005" error
fault = dm_entry_param_method(ctx, CMD_GET_NAME, "Device.Users.User.1.", "1", NULL);
assert_int_equal(fault, FAULT_9005);

View file

@ -79,6 +79,14 @@
"dm_files": [
"src/datamodel.c"
]
},
{
"repo": "https://dev.iopsys.eu/iopsys/usermngr.git",
"proto": "git",
"version": "devel",
"dm_files": [
"src/users.c"
]
}
],
"output": {