This repository has been archived by the owner on Sep 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
201 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2023 Cisco and/or its affiliates. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: MIT OR GPL-2.0-only | ||
* | ||
* Licensed under the MIT license <LICENSE.MIT or https://opensource.org/licenses/MIT> or the GPLv2 license | ||
* <LICENSE.GPL or https://opensource.org/license/gpl-2-0>, at your option. This file may not be copied, | ||
* modified, or distributed except according to those terms. | ||
*/ | ||
|
||
#include "device_driver.h" | ||
#include "json.h" | ||
|
||
command_answer *send_accept_command(u16 port) | ||
{ | ||
JSON_Value *root_value = json_value_init_object(); | ||
JSON_Object *root_object = json_value_get_object(root_value); | ||
|
||
json_object_set_number(root_object, "port", port); | ||
|
||
command_answer *answer = send_command("accept", json_serialize_to_string(root_value), get_task_context()); | ||
|
||
return answer; | ||
} | ||
|
||
command_answer *send_connect_command(u16 port) | ||
{ | ||
JSON_Value *root_value = json_value_init_object(); | ||
JSON_Object *root_object = json_value_get_object(root_value); | ||
|
||
json_object_set_number(root_object, "port", port); | ||
|
||
command_answer *answer = send_command("connect", json_serialize_to_string(root_value), get_task_context()); | ||
|
||
return answer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright (c) 2023 Cisco and/or its affiliates. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: MIT OR GPL-2.0-only | ||
* | ||
* Licensed under the MIT license <LICENSE.MIT or https://opensource.org/licenses/MIT> or the GPLv2 license | ||
* <LICENSE.GPL or https://opensource.org/license/gpl-2-0>, at your option. This file may not be copied, | ||
* modified, or distributed except according to those terms. | ||
*/ | ||
|
||
#ifndef commands_h | ||
#define commands_h | ||
|
||
command_answer *send_accept_command(u16 port); | ||
command_answer *send_connect_command(u16 port); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2023 Cisco and/or its affiliates. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: MIT OR GPL-2.0-only | ||
* | ||
* Licensed under the MIT license <LICENSE.MIT or https://opensource.org/licenses/MIT> or the GPLv2 license | ||
* <LICENSE.GPL or https://opensource.org/license/gpl-2-0>, at your option. This file may not be copied, | ||
* modified, or distributed except according to those terms. | ||
*/ | ||
|
||
#include <linux/uaccess.h> | ||
#include <linux/sched/mm.h> | ||
#include <linux/file.h> | ||
#include <linux/path.h> | ||
#include <linux/dcache.h> | ||
#include <linux/fs.h> | ||
#include <linux/slab.h> | ||
|
||
#include "task_context.h" | ||
|
||
task_context *get_task_context(void) | ||
{ | ||
struct task_context *context = kmalloc(sizeof(struct task_context), GFP_KERNEL); | ||
|
||
strcpy(context->command_name, current->comm); | ||
context->command_path_buffer = kmalloc(COMMAND_PATH_BUFLEN, GFP_KERNEL); | ||
context->command_path = get_current_proc_path(context->command_path_buffer, COMMAND_PATH_BUFLEN); | ||
current_uid_gid(&context->uid, &context->gid); | ||
|
||
return context; | ||
} | ||
|
||
void free_task_context(struct task_context *context) | ||
{ | ||
if (context->command_path_buffer) | ||
{ | ||
kfree(context->command_path_buffer); | ||
} | ||
|
||
kfree(context); | ||
} | ||
|
||
char *get_current_proc_path(char *buf, int buflen) | ||
{ | ||
struct file *exe_file; | ||
char *result = ERR_PTR(-ENOENT); | ||
struct mm_struct *mm; | ||
|
||
mm = get_task_mm(current); | ||
if (!mm) | ||
{ | ||
goto out; | ||
} | ||
exe_file = mm->exe_file; | ||
if (exe_file) | ||
{ | ||
get_file(exe_file); | ||
path_get(&exe_file->f_path); | ||
} | ||
mmput(mm); | ||
if (exe_file) | ||
{ | ||
result = d_path(&exe_file->f_path, buf, buflen); | ||
path_put(&exe_file->f_path); | ||
fput(exe_file); | ||
} | ||
|
||
out: | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2023 Cisco and/or its affiliates. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: MIT OR GPL-2.0-only | ||
* | ||
* Licensed under the MIT license <LICENSE.MIT or https://opensource.org/licenses/MIT> or the GPLv2 license | ||
* <LICENSE.GPL or https://opensource.org/license/gpl-2-0>, at your option. This file may not be copied, | ||
* modified, or distributed except according to those terms. | ||
*/ | ||
|
||
#ifndef context_h | ||
#define context_h | ||
|
||
#include <linux/uaccess.h> | ||
|
||
#define COMMAND_PATH_BUFLEN 256 | ||
|
||
char *get_current_proc_path(char *buf, int buflen); | ||
|
||
typedef struct task_context | ||
{ | ||
char command_name[TASK_COMM_LEN]; | ||
char *command_path_buffer; | ||
char *command_path; | ||
kuid_t uid; | ||
kgid_t gid; | ||
} task_context; | ||
|
||
task_context *get_task_context(void); | ||
void free_task_context(struct task_context *context); | ||
|
||
#endif |