| 1 | #include <glib.h> |
| 2 | #include <string.h> |
| 3 | struct rootjail * chrootjail_Init(){ |
| 4 | struct rootjail *this = (struct rootjail *) g_malloc(sizeof(struct rootjail)); |
| 5 | rootjailContext_Init(&this->_fsm, this); |
| 6 | this->pid=-1; |
| 7 | this->newroot = g_string_new(""); |
| 8 | return this; |
| 9 | } |
| 10 | void rootjail_savepid(struct rootjail *this, int pid){ |
| 11 | this->pid=pid; |
| 12 | } |
| 13 | void rootjail_savenewroot(struct rootjail *this, char *newroot){ |
| 14 | g_string_printf(this->newroot, newroot); |
| 15 | } |
| 16 | void rootjail_destroyfsm(struct rootjail *this){ |
| 17 | //remove fsm from fsm_list |
| 18 | removefsm(this); |
| 19 | g_string_free(this->newroot,TRUE); |
| 20 | g_free(this); |
| 21 | } |
| 22 | void rootjail_warning(struct rootjail *this){ |
| 23 | printf("WARNING: pid %d attempted to open a file before calling chdir()\n", this->pid); |
| 24 | } |
| 25 | int checknewdir(char * newdir){ |
| 26 | if(!strcmp(newdir, "/"))//returns 0 when strings are equal |
| 27 | return 1; |
| 28 | return 0; |
| 29 | } |
| 30 | int thisprocess(struct rootjail *this, int pid){ |
| 31 | if(this->pid==pid) |
| 32 | return 1; |
| 33 | return 0; |
| 34 | } |