Skip to content
This repository was archived by the owner on May 17, 2019. It is now read-only.

Commit a061c22

Browse files
author
NerdOfCode
committed
Patched.
Patched possible future bugs.
1 parent 72fa11e commit a061c22

10 files changed

Lines changed: 106 additions & 50 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#include <stdio.h>
22
#include <time.h>
33

4-
int main( void ){
4+
int main( int argc, char *argv[] ){
55

66
time_t current_time;
77
time(&current_time);
88

9-
printf("The local time is: %s\n",ctime(&current_time));
9+
printf("The local time is: %s",ctime(&current_time));
1010

1111
return 0;
1212
}

Bin/cmd_src/nano.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
#Call the global_bash_var file
4+
location="/etc/Restricted-Shell/"
5+
source "${location}Src/global_bash_var"
6+
7+
#Check if system has dependencies
8+
9+
readlink_status=$(which readlink)
10+
11+
if [[ $? != 0 ]]
12+
then
13+
echo -e "${RED_TEXT}Error: 2001${RESET}"
14+
exit -1
15+
fi
16+
17+
path="$(readlink -f $1)"
18+
19+
if [[ "$path" =~ "$DEFAULT_LOCATION"* ]]
20+
then
21+
echo -e "${RED_TEXT}Error: 1004${RESET}"
22+
exit -1
23+
fi
24+
25+
rnano_status=$(which rnano)
26+
27+
if [[ ! -z $rnano_status ]]
28+
then
29+
rnano $1
30+
else
31+
nano $1
32+
fi

Bin/cmd_src/version.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <stdio.h>
2+
#include "../../Src/globals.h"
3+
4+
//This program is in its own file due to the fact of increased modularity and the easier use of
5+
//implying restrictions on it.
6+
//Not to mention the improvements in small memory use and smaller CPU use
7+
8+
int main(void){
9+
10+
printf("Latest: v."LATEST_VERSION "\n");
11+
12+
return 0;
13+
}

Bin/ls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
ls "$@"
2+
ls $@

Bin/version

7.85 KB
Binary file not shown.

Makefile

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
all: shell commands
1+
C= gcc
2+
3+
all: clean shell commands clone_bash
4+
5+
clean:
6+
#Remove all binaries and also ignore error of trying to "rm" a directory
7+
-rm Bin/*
28

39
shell:
410
rm -f Src/shell~
511

6-
gcc -std=gnu11 -o Src/shell Src/shell.c
12+
$C -std=gnu11 -o Src/shell Src/shell.c
713

814
commands:
915

10-
rm -f Bin/test~
11-
rm -f Bin/clear~
12-
rm -f Bin/pwd~
13-
rm -f Bin/cd~
14-
rm -f Bin/rm~
15-
rm -f Bin/whoami~
16-
rm -f Bin/hostname~
17-
rm -f Bin/time~
18-
rm -f Bin/flags~
19-
rm -f Bin/history~
20-
rm -f Bin/alias~
21-
rm -f Bin/mkdir~
22-
23-
gcc -o Bin/test Bin/cmd_src/test.c
24-
gcc -o Bin/clear Bin/cmd_src/clear.c
25-
gcc -o Bin/pwd Bin/cmd_src/pwd.c
26-
gcc -o Bin/cd Bin/cmd_src/cd.c
27-
gcc -o Bin/rm Bin/cmd_src/rm.c
28-
gcc -o Bin/whoami Bin/cmd_src/whoami.c
29-
gcc -o Bin/hostname Bin/cmd_src/hostname.c
30-
gcc -o Bin/time Bin/cmd_src/time.c
31-
gcc -o Bin/flags Bin/cmd_src/flags.c
32-
gcc -o Bin/history Bin/cmd_src/history.c
33-
gcc -o Bin/alias Bin/cmd_src/alias.c
34-
gcc -o Bin/mkdir Bin/cmd_src/mkdir.c
16+
$C -o Bin/test Bin/cmd_src/test.c
17+
$C -o Bin/clear Bin/cmd_src/clear.c
18+
$C -o Bin/pwd Bin/cmd_src/pwd.c
19+
$C -o Bin/cd Bin/cmd_src/cd.c
20+
$C -o Bin/rm Bin/cmd_src/rm.c
21+
$C -o Bin/whoami Bin/cmd_src/whoami.c
22+
$C -o Bin/hostname Bin/cmd_src/hostname.c
23+
$C -o Bin/date Bin/cmd_src/date.c
24+
$C -o Bin/flags Bin/cmd_src/flags.c
25+
$C -o Bin/history Bin/cmd_src/history.c
26+
$C -o Bin/alias Bin/cmd_src/alias.c
27+
$C -o Bin/mkdir Bin/cmd_src/mkdir.c
28+
$C -o Bin/version Bin/cmd_src/version.c
3529

30+
clone_bash:
31+
cp -f Bin/cmd_src/ls.sh Bin/ls
32+
cp -f Bin/cmd_src/nano.sh Bin/nano
33+
#Make copied shell script executable
34+
chmod 755 Bin/ls
35+
chmod 755 Bin/nano

Src/global_bash_var

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
DEFAULT_LOCATION="/etc/Restricted-Shell/"
88

99
#Define last-updated date
10-
LAST_UPDATED="9/24/18"
10+
LAST_UPDATED="10/28/18"
1111

1212
#Define colors for color-coating output
1313
RED_TEXT='\033[0;31m'

Src/globals.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,23 @@
1717
*specific language governing permissions and limitations
1818
*under the License.
1919
20-
20+
NerdOfCode Copyrighted 2018
2121
*/
2222

23-
//EDIT BELOW:
23+
//Value Conventions:
24+
// On v. Off
25+
// On --> 1
26+
// Off --> 0
27+
28+
#define TRUE 1
29+
#define FALSE 0
2430

2531
//Used for displaying debug info for specific functions and commands (Experimental)
2632
#define DEBUG 0
2733

2834
//Used for User-command logging
29-
#define LOGGING 1
35+
//Default:0
36+
#define LOGGING 0
3037

3138
//Used for storing users commands to a specific file in their home directory
3239
//Such as aliases
@@ -50,9 +57,10 @@
5057
//Use 43m for background shading
5158
#define RESET "\x1B[0m"
5259

60+
#define LATEST_VERSION "0.011"
61+
5362
//Warning: If you're considering changing the below...
5463
//Make sure to adjust the Bin/nano file... Thank you!
55-
5664
//Default Directory of Shell
5765
#define DEFAULT_LOCATION "/etc/Restricted-Shell/"
5866

@@ -66,11 +74,8 @@
6674
//Default path to command Bin
6775
#define CMD_BIN DEFAULT_LOCATION"Bin/"
6876

69-
#define TRUE 1
70-
#define FALSE 0
71-
72-
7377
//Platform detection
78+
//On the wish list for now :)
7479
#if defined(__linux__)
7580
#define HOSTNAME "USER"
7681
#endif

Src/shell.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717
*under the License.
1818
1919
20-
21-
2220
#######################################################################################
2321
Author: NerdOfCode
2422
Tested on: Ubuntu Server 16.04
2523
Status: Working --> ^^^
2624
License: Apache-2.0
27-
Updated on: 9/29/18
25+
Updated on: 10/28/18
2826
#######################################################################################
2927
3028
#########################################################
@@ -83,10 +81,10 @@ int main ( int argc, char argv[64] ){
8381
//Test if user is allowed to use pwd and if allowed show the working directory
8482
//Also test if user is allowed to use hostname and whomai
8583
char *pwd_test;
86-
int return_pwd_test_value;
84+
short int return_pwd_test_value;
8785

8886
char *whoami_test;
89-
int return_whoami_test_value;
87+
short int return_whoami_test_value;
9088

9189
pwd_test = malloc(64 * sizeof(char));
9290
strcat(pwd_test,CMD_BIN);
@@ -162,8 +160,8 @@ int main ( int argc, char argv[64] ){
162160
memset(pwd_test,0,sizeof(pwd_test));
163161
memset(whoami_test,0,sizeof(whoami_test));
164162

165-
//TODO
166-
log_command(input);
163+
if(LOGGING)
164+
log_command(input);
167165

168166
//Not a good idea for case specific things, will need to make its own function for better use
169167

@@ -203,9 +201,17 @@ void change_to_home_dir( void ){
203201
//TODO
204202
//Create a better method for the following
205203
//Assume users directory is /home/logged_in_user
204+
205+
//For chdir() return code
206+
short int return_status = 0;
207+
206208
char current_user_home[64] = "/home/";
207209
strcat(current_user_home,logged_in_user);
208-
chdir(current_user_home);
210+
return_status = chdir(current_user_home);
211+
212+
if(return_status != 0)
213+
puts(RED_TEXT"Error: 1005"RESET);
214+
209215
}
210216

211217
int start_up( void ){
@@ -289,9 +295,8 @@ void commands(){
289295
puts("flags");
290296
puts("history");
291297
puts("rm");
292-
puts("time");
298+
puts("date");
293299
puts("mkdir");
294-
puts("");
295300

296301
}
297302

run.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,10 @@ then
180180
sed -i "s|${DEFAULT_LOCATION}|${location}|g" run.sh
181181
sed -i "s|${DEFAULT_LOCATION}|${location}|g" Src/globals.h
182182
sed -i "s|${DEFAULT_LOCATION}|${location}|g" Src/global_bash_var
183-
sed -i "s|${DEFAULT_LOCATION}|${location}|g" Bin/nano
183+
sed -i "s|${DEFAULT_LOCATION}|${location}|g" Bin/cmd_src/nano.sh
184184
break
185185
else
186+
#
186187
continue
187188
fi
188189
fi

0 commit comments

Comments
 (0)