-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccessControl.c
More file actions
97 lines (82 loc) · 2.49 KB
/
AccessControl.c
File metadata and controls
97 lines (82 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* AccessControl.c
Name: Jordan Guinn
SID: 910293311
File allows user to read to or write from
various files within a directory, if they
have permission to use such functionality
COMPILE AND RUN THIS FILE
*/
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include "AccessControlLists.c"
/* Read from file if permitted */
void myRead(char buffer[], int bufSize, int file, int access)
{
if(allfiles[file][access] == 'r' || allfiles[file][access] == 'x')
{
int fd = open(files[file], O_RDONLY);
int beenRead = read(fd, buffer, bufSize);
printf("%i bytes read.\nHere's your file:\n\n", beenRead);
for(int i = 0; buffer[i] != '\0'; i++)
printf("%c", buffer[i]);
}
else
printf("You don't have permission to read this file.\n");
}
/* Write to file if permitted */
void myWrite(int file, int access)
{
if(allfiles[file][access] == 'w' || allfiles[file][access] == 'x')
{
int fd = open(files[file], O_WRONLY | O_RDONLY | O_APPEND);
char buffer[] = {"\nYou just wrote to a file. CONGRATULATIONS."};
int written = write(fd, buffer, strlen(buffer));
printf("%i bytes written.\n", written);
}
else
printf("You don't have permission to write to this file.\n");
}
/* Get user ID */
int userAccess()
{
return getuid();
}
/* Test myRead and myWrite functions */
int main()
{
int access, method, fd, file = 0;
initFilePermissions();
while(file != -1)
{
char buffer[10000];
printf("Please choose a file within the directory to edit.\n");
printf("For exploit.c, enter 1.\n");
printf("For findMessage.java, enter 2.\n");
printf("For hideMessage.java, enter 3.\n");
printf("For shellcode.c, enter 4.\n");
printf("For stack.c, enter 5.\n");
printf("To exit, enter 0.\n");
/* Exit if requested */
scanf("%d", &file);
if(file == 0)
return 0;
printf("Would you like to read(1) or write(2)?\n");
scanf("%d", &method);
/* Determine if user actually has permission to manipulate file how they'd like */
if(userAccess() == 0)
access = 1;
else
access = 0;
/* Call read or write function */
file = file - 1;
if(method == 1)
myRead(buffer, sizeof(buffer), file, access);
else if(method == 2)
myWrite(file, access);
printf("\n");
}
return 0;
}