diff options
-rw-r--r-- | src/cli_new.c | 526 | ||||
-rw-r--r-- | src/cli_objects.c | 102 | ||||
-rw-r--r-- | src/cli_objects.h | 19 | ||||
-rw-r--r-- | src/cli_path_utils.c | 78 | ||||
-rw-r--r-- | src/cli_path_utils.h | 5 | ||||
-rw-r--r-- | src/cli_val.h | 42 | ||||
-rw-r--r-- | src/cli_val_engine.c | 41 | ||||
-rw-r--r-- | src/common/unionfs.c | 10 | ||||
-rw-r--r-- | src/common/unionfs.h | 16 |
9 files changed, 51 insertions, 788 deletions
diff --git a/src/cli_new.c b/src/cli_new.c index f746b7f..a5dc082 100644 --- a/src/cli_new.c +++ b/src/cli_new.c @@ -43,7 +43,6 @@ void *var_ref_handle = NULL; /* Local vars: */ static vtw_node *vtw_free_nodes; /* linked via left */ -static char val_name[] = VAL_NAME; static int cond1[TOP_COND] ={5, 0,-1,-1, 0, 1, 0, 0}; static int cond2[TOP_COND] ={5, 0, 1,-1,-1, 1, 1, 0}; static char const *cond_formats[DOMAIN_TYPE] = @@ -81,10 +80,11 @@ static valstruct validate_value_val; /* value being validated /* Local function declarations: */ +static void touch(void); static int check_comp(vtw_node *cur); static boolean check_syn_func(vtw_node *cur,const char *prepend_msg,boolean format, const char* func,int line); #define check_syn(cur,msg_buf,format) check_syn_func((cur),(msg_buf),(format),__FUNCTION__,__LINE__) -void copy_path(vtw_path *to, vtw_path *from); +static void copy_path(vtw_path *to, vtw_path *from); static int eval_va(valstruct *res, vtw_node *node); static int expand_string(char *p); static void free_node(vtw_node *node); @@ -93,28 +93,19 @@ static void free_reuse_list(void); void free_path(vtw_path *path); static void free_string(char *str); static vtw_node * get_node(void); -void subtract_values(char **lhs, const char *rhs); - - static void scan_ipv6(char *val, unsigned int *parts); - static int set_reference_environment(const char* var_reference, clind_path_ref *n_cfg_path, clind_path_ref *n_tmpl_path, clind_path_ref *n_cmd_path, int active); + /************************************************* GLOBAL FUNCTIONS ***************************************************/ const char *cli_operation_name = NULL; -/* it is executed as "eval `my_set` in order to be able to - modify BASH env - therefore, all error will be reported as - printf("echo \"bla-bla-bla%s\";", sptr) - note very important ';' as the end of the format -*/ void bye(const char *msg, ...) { va_list ap; @@ -123,35 +114,13 @@ void bye(const char *msg, ...) (cli_operation_name) ? cli_operation_name : "Operation"); va_start(ap, msg); - if (is_echo()) - printf("echo \""); vprintf(msg, ap); - printf(is_echo()? "\";":"\n"); + printf("\n"); va_end(ap); exit(1); } -/* msg: - print message, preceeded by "echo " if global - flag echo set. This flag is used by program - which are executed as eval `command` in order to - modify BASH env -*/ -void print_msg(const char *msg, ...) -{ - va_list ap; - - if (is_silent_msg()) - return; - va_start(ap, msg); - if (is_echo()) - printf("echo \""); - vprintf(msg, ap); - printf(is_echo()? "\";":"\n"); - va_end(ap); -} - int mkdir_p(const char *path) { if (mkdir(path, 0777) == 0) @@ -180,7 +149,8 @@ int mkdir_p(const char *path) return ret; } -void touch_dir(const char *dp) +static void +touch_dir(const char *dp) { struct stat statbuf; @@ -312,21 +282,6 @@ get_shell_command_output(const char *cmd, char *buf, unsigned int buf_size) return ret; } -void dt(vtw_sorted *srtp) -{ - int i; - for (i=0; i<srtp->num; ++i) - printf("%d %s\n", i, (char *)(srtp->ptrs[i])); -} - - -void di(vtw_sorted *srtp) -{ - int i; - for (i=0; i<srtp->num; ++i) - printf("%u %u\n", i, *(unsigned int *)(srtp->ptrs[i])); -} - #define LOCK_FILE "/opt/vyatta/config/.lock" #define COMMIT_CMD "/opt/vyatta/sbin/my_commit" @@ -469,229 +424,6 @@ get_config_lock() return ret; } -void internal_error(int line, const char *file) -{ - printf("\n\nInternal Error at line %d in %s\n", line, file); - exit (-1); -} - -/************************************************* - vtw_sort: - create sorted structure for the value, - allocates ptrs and parts in this structure -*/ -void vtw_sort(valstruct *valp, vtw_sorted *sortp) -{ - int i; - const char * format; - unsigned int *parts; - vtw_type_e type = valp->val_type; - char *cp; - - sortp->num = valp->cnt?valp->cnt : 1; -#ifdef CLI_DEBUG - printf("vtw_sort type=%d num=%d\n", type, sortp->num); - for (i = 0; i < sortp->num; i++) { - printf(" [%s]\n", (valp->cnt) ? valp->vals[i] : valp->val); - } -#endif - sortp->ptrs = my_malloc(sortp->num * sizeof(void *), "sort_ptrs"); - sortp->partnum = (type < DOMAIN_TYPE) ? cond_format_lens[type] : 0; - if (sortp->partnum) { - sortp->parts = my_malloc(sortp->partnum * sortp->num * sizeof(void *), - "sort_parts"); - }else{ - sortp->parts = NULL; - } - switch (type){ - case IPV6_TYPE: - case IPV6NET_TYPE: - for (i = 0; i < sortp->num; ++i) { - parts = sortp->parts + i * sortp->partnum; - scan_ipv6(valp->cnt?valp->vals[i]:valp->val, parts); - sortp->ptrs[i] = parts; - } - break; - case IPV4_TYPE: - case IPV4NET_TYPE: - case MACADDR_TYPE: - case INT_TYPE: - format = cond_formats[valp->val_type]; - for (i = 0; i < sortp->num; ++i) { - cp = valp->cnt?valp->vals[i]:valp->val; - parts = sortp->parts + i * sortp->partnum; - switch (sortp->partnum) { - case 1: - (void) sscanf(cp, format, parts); - break; - case 2: - (void) sscanf(cp, format, parts, parts+1); - break; - case 3: - (void) sscanf(cp, format, parts, parts+1, parts+2); - break; - case 4: - (void) sscanf(cp, format, parts, parts+1, parts+2, - parts+3); - break; - case 5: - (void) sscanf(cp, format, parts, parts+1, parts+2, - parts+3, parts+4); - break; - case 6: - (void) sscanf(cp, format, parts, parts+1, parts+2, - parts+3, parts+4, parts+5); - break; - } - sortp->ptrs[i] = parts; - } - break; - case TEXT_TYPE: - case BOOL_TYPE: - for (i = 0; i < sortp->num; ++i) { - sortp->ptrs[i] = valp->cnt?valp->vals[i]:valp->val; - } - break; - default: - bye("Unknown value in switch on line %d\n", __LINE__); - } - if (sortp->num < 2) - return; -#ifdef CLI_DEBUG - if (sortp->parts) { - int i, j; - printf("sortp parts:\n"); - for (i = 0; i < sortp->num; i++) { - printf(" "); - unsigned int *parts = (unsigned int *) sortp->ptrs[i]; - for (j = 0; j < sortp->partnum; j++) { - printf("%u ", parts[j]); - } - printf("\n"); - } - } -#endif - /* the following sort throws away the input ordering. */ - /* NOT doing this for now */ -#if 0 - /* now do a heap sort */ - /* build heap */ - /* from left to right, we start with the heap of only one (first) element*/ - for (i = 2; i <= sortp->num; ++i) - { - cur = i; - do { - curp = sortp->ptrs[cur - 1]; - par = cur >> 1; - parp = sortp->ptrs[par - 1]; - if (sortp->partnum){ - for(partnum = 0; partnum < sortp->partnum; ++partnum) { - if (*((unsigned int *)curp + partnum)> - *((unsigned int *)parp + partnum)){ - res = 1; - break; - } - if (*((unsigned int *)curp + partnum)< - *((unsigned int *)parp + partnum)){ - res = -1; - break; - } - res = 0; - } - }else{ - res = strcmp((char *)curp, (char *) parp); - } - if (res <= 0) - break; - /* swap them */ - sortp->ptrs[cur - 1] = parp; - sortp->ptrs[par - 1] = curp; - - } while ((cur = par) != 1); - } - /* convert heap into sorted array */ - unsorted = sortp->num; /* sortp->num must be >= 2 */ - while (TRUE) { - void *tp; - /* root to the sorted part */ - tp = sortp->ptrs[0]; - sortp->ptrs[0] = sortp->ptrs[--unsorted]; - sortp->ptrs[unsorted] = tp; - if (unsorted == 1) - break; - /* push down the new root */ - par = 1; - while(TRUE) { - left = par << 1; /* left child */ - if (left > unsorted) - break; /* no children */ - else { - if (left == unsorted) { - /* only left child */ - child = left; - } else { - /* both children */ - right = left+1; - leftp = sortp->ptrs[left - 1]; - rightp = sortp->ptrs[right - 1]; - /* find larger child */ - if (sortp->partnum){ - for(partnum = 0; partnum < sortp->partnum; ++partnum) { - if (*((unsigned int *)leftp + partnum) > - *((unsigned int *)rightp + partnum)) { - res = 1; - break; - } - if (*((unsigned int *)leftp + partnum) < - *((unsigned int *)rightp + partnum)) { - res = -1; - break; - } - res = 0; - } - }else{ - res = strcmp((char *)leftp, (char *) rightp); - } - if (res >= 0) { - child = left; /* left is larger or same*/ - } else { - child = right; - } - } - /* compare parent and larger child */ - parp = sortp->ptrs[par - 1]; - childp = sortp->ptrs[child - 1]; - if (sortp->partnum){ - for(partnum = 0; partnum < sortp->partnum; ++partnum) { - if (*((unsigned int *)parp + partnum) > - *((unsigned int *)childp + partnum)){ - res = 1; - break; - } - if (*((unsigned int *)parp + partnum) < - *((unsigned int *)childp + partnum)){ - res = -1; - break; - } - res = 0; - } - }else{ - res = strcmp((char *)parp, (char *) childp); - } - if (res >= 0) { - /* done with percolating down, parent larger than child */ - break; - } - /* child greater, exchage and continue */ - sortp->ptrs[par - 1] = childp; - sortp->ptrs[child - 1] = parp; - par = child; - } - } - } -#endif -} - /* returns FALSE if execution returns non-null, returns TRUE if every excution returns NULL */ @@ -844,10 +576,8 @@ int char2val_notext(vtw_def *def, int my_type, int my_type2, char *value, valstr (void)expand_string(def->def_type_help); sprintf(err_buf, "%s\n", exe_string); } else { - print_msg("Wrong type of value in %s, " - "need %s\n", - m_path.path_buf + m_path.print_offset, - type_buf); + printf("Wrong type of value in %s, need %s\n", + m_path.path_buf + m_path.print_offset, type_buf); token = yy_cli_val_lex(); @@ -866,10 +596,8 @@ int char2val_notext(vtw_def *def, int my_type, int my_type2, char *value, valstr (void)expand_string(def->def_type_help); sprintf(err_buf, "%s\n", exe_string); } else { - print_msg("Wrong type of value in %s, " - "need %s\n", - m_path.path_buf + m_path.print_offset, - type_buf); + printf("Wrong type of value in %s, need %s\n", + m_path.path_buf + m_path.print_offset, type_buf); token = yy_cli_val_lex(); @@ -890,7 +618,7 @@ int char2val_notext(vtw_def *def, int my_type, int my_type2, char *value, valstr if (def->multi) add_val(valp, get_cli_value_ptr()); else { - print_msg("Unexpected multivalue in %s\n", m_path.path); + printf("Unexpected multivalue in %s\n", m_path.path); free_val(get_cli_value_ptr()); } } @@ -903,8 +631,7 @@ int char2val_notext(vtw_def *def, int my_type, int my_type2, char *value, valstr token = yy_cli_val_lex(); sprintf(err_buf, "\"%s\" is not a valid value\n", value); - print_msg("Badly formed value in %s\n", - m_path.path + m_path.print_offset); + printf("Badly formed value in %s\n", m_path.path + m_path.print_offset); if (token == VALUE) { my_free(get_cli_value_ptr()->val); } @@ -975,7 +702,8 @@ int char2val_text(vtw_def *def, char *value, valstruct **valpp) compare two values per cond returns result of comparison ****************************************************/ -boolean val_cmp(const valstruct *left, const valstruct *right, vtw_cond_e cond) +static boolean +val_cmp(const valstruct *left, const valstruct *right, vtw_cond_e cond) { unsigned int left_parts[9], right_parts[9]; vtw_type_e val_type; @@ -1073,7 +801,6 @@ boolean val_cmp(const valstruct *left, const valstruct *right, vtw_cond_e cond) (res == cond2[cond])); if (ret && cond == IN_COND) { - set_in_cond_tik(rcur); /* for delete */ /* one success is enough for right cycle in case of IN_COND, continue left cycle */ break; @@ -1429,7 +1156,8 @@ static boolean check_syn_func(vtw_node *cur,const char *prepend_msg,boolean form copy path if destination path owns memory, free it **************************************************/ -void copy_path(vtw_path *to, vtw_path *from) +static void +copy_path(vtw_path *to, vtw_path *from) { if (to->path_buf) my_free(to->path_buf); @@ -1744,19 +1472,6 @@ static int expand_string(char *stringp) } /***************************************************** - free_sorted: - free all memory allocated to sorted -*****************************************************/ -void free_sorted(vtw_sorted *sortp) -{ - if(sortp->ptrs) - my_free(sortp->ptrs); - if (sortp->parts) - my_free(sortp->parts); -} - - -/***************************************************** free_def: free all memory allocated to def *****************************************************/ @@ -1893,7 +1608,7 @@ int get_value(char **valpp, vtw_path *pathp) /* find value */ *valpp = 0; - push_path(pathp, val_name); + push_path(pathp, VAL_NAME); if (lstat(pathp->path, &statbuf) < 0) { err = "no value file in [%s]\n"; @@ -1935,29 +1650,6 @@ pop: goto pop; } -int get_value_to_at_string(vtw_path *pathp) { - - char* at=NULL; - int status = get_value(&at,pathp); - - if(status==0) { - set_at_string(at); - } else { - set_at_string(NULL); - } - - return status; -} - -/***************************************************** - out_of_memeory - print out of memory message and exit -*****************************************************/ -void out_of_memory() -{ - bye("\n\t!!! OUT OF MEMORY !!!\n"); -} - /************************************************* init_path: init path, exit if not able (out_of_memory) @@ -1989,7 +1681,7 @@ void init_path(vtw_path *path, const char *root) void pop_path(vtw_path *path) { if (--path->path_lev < 1) { - INTERNAL; + bye("INTERNAL: line %d in %s\n", __LINE__, __FILE__); } path->path_len = path->path_ends[path->path_lev - 1]; path->path_buf[path->path_len] = 0; @@ -2231,93 +1923,6 @@ boolean validate_value(vtw_def *def, char *cp) return ret; } -void subtract_values(char **lhs, const char *rhs) -{ - size_t length = 0, lhs_cnt = 0, rhs_cnt = 0, i; - const char *line = NULL; - char *rhs_copy = NULL, *res = NULL; - const char **head = NULL, **ptr = NULL; - const char **new_head = NULL, **new_ptr = NULL; - - if (lhs == NULL || *lhs == NULL || **lhs == '\0' || rhs == NULL || *rhs == '\0') - return; - - /* calculate number of rhs entries */ - rhs_copy = strdup(rhs); - line = strtok(rhs_copy, "\n\r"); - while (line != NULL && *line != '\0') { - rhs_cnt++; - line = strtok(NULL, "\n\r"); - } - - /* strtok destroys the string. dup again. */ - free(rhs_copy); - rhs_copy = strdup(rhs); - - /* allocate enough space for all old entries (to be subtracted) */ - length = rhs_cnt * sizeof(char *); - head = ptr = my_malloc(length, "subtract_values list1"); - memset(head, 0, length); - - /* parse the entries and put them in head[] */ - line = strtok(rhs_copy, "\n\r"); - while (line != NULL && *line != '\0') { - *ptr = line; - ptr++; - line = strtok(NULL, "\n\r"); - } - - /* calculate number of lhs entries */ - { - char *lhs_copy = strdup(*lhs); - line = strtok(lhs_copy, "\n\r"); - while (line != NULL && *line != '\0') { - lhs_cnt++; - line = strtok(NULL, "\n\r"); - } - free(lhs_copy); - } - - /* allocate enough space for all new entries */ - length = lhs_cnt * sizeof(char *); - new_head = new_ptr = my_malloc(length, "subtract_values list2"); - memset(new_head, 0, length); - - /* reset length and lhs_cnt. they are now used for the "new" array (i.e., - * after subtraction). */ - length = 0; - lhs_cnt = 0; - line = strtok(*lhs, "\n\r"); - while (line != NULL && *line != '\0') { - for (i = 0; i < rhs_cnt; i++) { - if (strncmp(line, head[i], strlen(line)) == 0) - break; - } - if (i >= rhs_cnt) { - *new_ptr = line; - length += strlen(line) + 1; - new_ptr++; - lhs_cnt++; - } - line = strtok(NULL, "\n\r"); - } - - res = (char *) my_malloc(length + 1, "subtract_values result"); - *res = '\0'; - for (i = 0; i < lhs_cnt; i++) { - strcat(res, new_head[i]); - strcat(res, "\n"); - } - - my_free(head); - my_free(new_head); - if (rhs_copy != NULL) - my_free(rhs_copy); - my_free(*lhs); - - *lhs = res; -} - int cli_val_read(char *buf, int max_size) { int len; @@ -2333,28 +1938,9 @@ int cli_val_read(char *buf, int max_size) } return len; } -void done(void) -{ - free_reuse_list(); - free_path(&t_path); - free_path(&m_path); - if (exe_string) - my_free(exe_string); -} -void mark_paths(vtw_mark *markp) -{ - markp->m_lev = m_path.path_lev; - markp->t_lev = t_path.path_lev; -} -void restore_paths(vtw_mark *markp) -{ - while(markp->m_lev < m_path.path_lev) - pop_path(&m_path); - while(markp->t_lev < t_path.path_lev) - pop_path(&t_path); -} -void touch_file(const char *filename) +static void +touch_file(const char *filename) { int fd = creat(filename, 0666); if (fd < 0) @@ -2368,7 +1954,8 @@ void touch_file(const char *filename) close(fd); } -void touch(void) +static void +touch(void) { char filename[strlen(get_mdirp()) + 20]; sprintf(filename, "%s/%s", get_mdirp(), MOD_NAME); @@ -2390,20 +1977,6 @@ const char *type_to_name(vtw_type_e type) { } } -#ifdef CLI_DEBUG -void dump_log(int argc, char **argv) -{ - int i; - - printf("Command:"); - for (i = 0; i < argc; ++i) { - putchar(' '); - puts(argv[i]); - } - putchar('\n'); -} -#endif - /********************* New Dir ****************************/ static int set_reference_environment(const char* var_reference, @@ -2682,58 +2255,3 @@ system_out(const char *cmd, const char *prepend_msg, boolean format) } } -/**********************************************************/ - - -boolean -is_deactivated(const clind_path_ref *path) -{ - if (path == NULL) { - return FALSE; - } - - const char* path_string = clind_path_get_path_string(*path); - - char buf[1024]; //ALSO USED AS LIMIT IN UNIONFS path length - strcpy(buf,path_string); - - //first we'll check the current directory - char file[1024]; - sprintf(file,"%s/.disable",buf); - struct stat s; - if (lstat(file,&s) == 0) { - return TRUE; - } - - long min_len = strlen("/opt/vyatta/config/tmp/new_config_"); - - //now walk back up tree looking for disable flag..... - while (TRUE) { - int index = strlen(buf)-1; - if (index < min_len) { - return FALSE; - } - if (buf[index] == '/') { - while (TRUE) { - if (buf[--index] != '/') { - buf[index] = '\0'; - break; - } - } - } - - char *ptr = rindex(buf,'/'); - if (ptr != NULL) { - *ptr = '\0'; - } - - char file[1024]; - sprintf(file,"%s/.disable",buf); - struct stat s; - if (lstat(file,&s) == 0) { - return TRUE; - } - } - - return FALSE; -} diff --git a/src/cli_objects.c b/src/cli_objects.c index 8685c6a..9d389e2 100644 --- a/src/cli_objects.c +++ b/src/cli_objects.c @@ -26,12 +26,9 @@ static boolean in_delete_action=FALSE; static valstruct cli_value; static boolean in_commit=FALSE; /* TRUE if in commit program*/ static boolean in_exec=FALSE; /* TRUE if in exec */ -static boolean _is_echo=FALSE; -static boolean _is_silent_msg=FALSE; static first_seg f_seg_a; static first_seg f_seg_c; static first_seg f_seg_m; -static int in_cond_tik=0; /******************** Accessors: ************************/ @@ -86,22 +83,6 @@ void set_in_exec(boolean b) { in_exec=b; } -boolean is_echo(void) { - return _is_echo; -} - -void set_echo(boolean b) { - _is_echo=b; -} - -boolean is_silent_msg(void) { - return _is_silent_msg; -} - -void set_silent_msg(boolean b) { - _is_silent_msg=b; -} - valstruct* get_cli_value_ptr(void) { return &cli_value; } @@ -118,18 +99,6 @@ first_seg* get_f_seg_m_ptr(void) { return &f_seg_m; } -int is_in_cond_tik(void) { - return in_cond_tik; -} - -void set_in_cond_tik(int ict) { - in_cond_tik=ict; -} - -void dec_in_cond_tik(void) { - --in_cond_tik; -} - const char* get_tdirp(void) { const char* tdirp=getenv(ENV_T_DIR); @@ -178,8 +147,9 @@ const char* get_tmpp(void) { return tmpp; } -char* get_elevp(void) { - +static char * +get_elevp(void) +{ static char elevp_buffer[2049]; static char* elevp=NULL; @@ -196,8 +166,9 @@ char* get_elevp(void) { return elevp; } -char* get_tlevp(void) { - +static char * +get_tlevp(void) +{ static char tlevp_buffer[2049]; static char* tlevp=NULL; @@ -216,67 +187,6 @@ char* get_tlevp(void) { /************************* Init ***************************/ -void init_edit() -{ - int elevlen = 0; - int tlevlen = 0; - - init_paths(TRUE); - if (!get_elevp()) - bye("Not in configuration mode"); - if (!get_tlevp()) - bye("INTERNAL: environment var |%s| is not set",ENV_TEMPLATE_LEVEL); - elevlen = strlen(get_elevp()); - tlevlen = strlen(get_tlevp()); - if (elevlen > 0 && get_elevp()[elevlen - 1]=='/') { - /* cut off terminateing slash */ - --elevlen; - get_elevp()[elevlen] = 0; - } - if (elevlen) { - char *slashp; - char * scanp; - if (*get_elevp()!='/') - INTERNAL; - scanp = get_elevp() + 1; - while (TRUE) { - slashp = strchr(scanp, '/'); - if (slashp) - *slashp = 0; - push_path_no_escape(&m_path, scanp); - if (slashp) { - *slashp = '/'; - scanp = slashp+1; - }else - break; - } - } - switch_path(MPATH); - if (tlevlen > 0 && get_tlevp()[tlevlen - 1]=='/') { - /* cut off terminateing slash */ - --tlevlen; - get_tlevp()[tlevlen] = 0; - } - if (tlevlen) { - char *slashp; - char * scanp; - if (*get_tlevp()!='/') - INTERNAL; - scanp = get_tlevp() + 1; - while (TRUE) { - slashp = strchr(scanp, '/'); - if (slashp) - *slashp = 0; - push_path(&t_path, scanp); - if (slashp) { - *slashp = '/'; - scanp = slashp+1; - }else - break; - } - } -} - void init_paths(boolean for_commit) { struct stat statbuf; diff --git a/src/cli_objects.h b/src/cli_objects.h index 12b6b38..889c772 100644 --- a/src/cli_objects.h +++ b/src/cli_objects.h @@ -3,10 +3,6 @@ #include "cli_val.h" -#define APATH (get_f_seg_a_ptr()) -#define CPATH (get_f_seg_c_ptr()) -#define MPATH (get_f_seg_m_ptr()) - /* names of VYATTA env vars */ #define ENV_EDIT_LEVEL "VYATTA_EDIT_LEVEL" #define ENV_TEMPLATE_LEVEL "VYATTA_TEMPLATE_LEVEL" @@ -17,7 +13,6 @@ #define ENV_TMP_DIR "VYATTA_CONFIG_TMP" #define DEF_A_DIR "/opt/vyatta/config/active" #define DEF_T_DIR "/opt/vyatta/share/ofr/template" -#define ENV_OLD_PS1 "VYATTA_OLD_PS1" /* the string to use as $(@), must be set before call to expand_string */ @@ -34,32 +29,18 @@ void set_in_commit(boolean b); boolean is_in_exec(void); void set_in_exec(boolean b); -boolean is_echo(void); -void set_echo(boolean b); - -boolean is_silent_msg(void); -void set_silent_msg(boolean b); - valstruct* get_cli_value_ptr(void); first_seg* get_f_seg_a_ptr(void); first_seg* get_f_seg_c_ptr(void); first_seg* get_f_seg_m_ptr(void); -int is_in_cond_tik(void); -void set_in_cond_tik(int ict); -void dec_in_cond_tik(void); - const char* get_tdirp(void); const char* get_cdirp(void); const char* get_adirp(void); const char* get_mdirp(void); const char* get_tmpp(void); -char* get_elevp(void); -char* get_tlevp(void); - -void init_edit(void); void init_paths(boolean for_commit); #endif /* CLI_OBJ_H */ diff --git a/src/cli_path_utils.c b/src/cli_path_utils.c index 2874aeb..7d651c2 100644 --- a/src/cli_path_utils.c +++ b/src/cli_path_utils.c @@ -215,14 +215,6 @@ const char* clind_path_get_path_string(clind_path_ref path) { return ""; } -int clind_path_is_absolute(clind_path_ref path) { - if(path) { - clind_path_impl* obj = (clind_path_impl*)path; - return obj->absolute; - } - return 0; -} - void clind_path_push(clind_path_ref path,const char* dir) { if(path && dir && *dir) { @@ -316,38 +308,6 @@ const char* clind_path_last_string(clind_path_ref path) { return ret; } -void clind_path_unshift(clind_path_ref path,const char* dir) { - - if(path && dir && *dir) { - - clind_path_impl* obj = (clind_path_impl*)path; - - int absolute=(*dir=='/'); - - while(*dir && *dir=='/') dir++; - - if(obj->path_len<=0) { - - clind_path_push(path,dir); - - } else { - - obj->path_len++; - - obj->path=(clind_dir_name*)realloc(obj->path, - sizeof(clind_dir_name)*(obj->path_len)); - memmove((char*)(obj->path)+sizeof(clind_dir_name),(char*)(obj->path), - sizeof(clind_dir_name)*(obj->path_len-1)); - obj->path[0]=strdup(dir); - - } - - obj->absolute=absolute; - - clind_reset_path_string(obj); - } -} - const char* clind_path_get_string(clind_path_ref path,int index) { const char* ret=NULL; @@ -362,12 +322,9 @@ const char* clind_path_get_string(clind_path_ref path,int index) { return ret; } -const char* clind_path_first_string(clind_path_ref path) { - return clind_path_get_string(path,0); -} - -char* clind_path_shift_string(clind_path_ref path) { - +static char * +clind_path_shift_string(clind_path_ref path) +{ char* ret=NULL; if(path) { @@ -412,35 +369,6 @@ int clind_path_shift(clind_path_ref path) { return ret; } -void clind_path_debug_print(clind_path_ref path) { - - if(path) { - - int i=0; - clind_path_impl* obj = (clind_path_impl*)path; - - if(obj->path_string) { - printf("obj->path_string=%s, obj->path_len=%d,obj->absolute=%d\n", - obj->path_string,obj->path_len,obj->absolute); - } else { - printf("obj->path_string=NULL, obj->path_len=%d,obj->absolute=%d\n", - obj->path_len,obj->absolute); - } - - if(obj->path) { - for(i=0;i<obj->path_len;i++) { - if(obj->path[i]) { - printf(" obj->path[%d]=%s\n",i,obj->path[i]); - } else { - printf(" obj->path[%d]=NULL\n",i); - } - } - } else { - printf(" obj->path=NULL\n"); - } - } -} - int clind_file_exists(const char* dir,const char* file) { int ret=0; diff --git a/src/cli_path_utils.h b/src/cli_path_utils.h index 6716b22..6fcceb8 100644 --- a/src/cli_path_utils.h +++ b/src/cli_path_utils.h @@ -54,8 +54,6 @@ clind_path_ref clind_path_clone(const clind_path_ref path); int clind_path_get_size(clind_path_ref path); const char* clind_path_get_path_string(clind_path_ref path); -void clind_path_debug_print(clind_path_ref path); -int clind_path_is_absolute(clind_path_ref path); int clind_path_pop(clind_path_ref path); char* clind_path_pop_string(clind_path_ref path); @@ -63,10 +61,7 @@ const char* clind_path_last_string(clind_path_ref path); void clind_path_push(clind_path_ref path,const char* dir); int clind_path_shift(clind_path_ref path); -char* clind_path_shift_string(clind_path_ref path); const char* clind_path_get_string(clind_path_ref path,int index); -const char* clind_path_first_string(clind_path_ref path); -void clind_path_unshift(clind_path_ref path,const char* dir); int clind_file_exists(const char* dir,const char* file); diff --git a/src/cli_val.h b/src/cli_val.h index 022f794..dec1acd 100644 --- a/src/cli_val.h +++ b/src/cli_val.h @@ -4,8 +4,6 @@ #include <cli_cstore.h> -#define BITWISE 0 /* no partial commit */ - #ifndef FALSE #define FALSE 0 #endif @@ -36,11 +34,6 @@ typedef enum { /* IN_COND is like EQ for singular compare, but OR for multivalue right operand */ typedef struct { - int t_lev; - int m_lev; -}vtw_mark; - -typedef struct { const char *f_segp; int f_seglen; int f_segoff; @@ -62,16 +55,8 @@ typedef struct { int print_offset; /* for additional optional output information */ } vtw_path; /* vyatta tree walk */ -typedef struct { - int num; - int partnum; - void **ptrs; - unsigned int *parts; -}vtw_sorted; - extern int char2val(vtw_def *def, char *value, valstruct *valp); extern int get_value(char **valpp, vtw_path *pathp); -extern int get_value_to_at_string(vtw_path *pathp); extern vtw_node * make_node(vtw_oper_e oper, vtw_node *left, vtw_node *right); extern vtw_node *make_str_node(char *str); @@ -80,14 +65,11 @@ extern vtw_node *make_str_node0(char *str, vtw_oper_e op); extern void append(vtw_list *l, vtw_node *n, int aux); extern int yy_cli_val_lex(void); -extern void cli_val_start(char *s); -extern void cli_val_done(void); extern void init_path(vtw_path *path, const char *root); extern void pop_path(vtw_path *path); extern void push_path(vtw_path *path, const char *segm); extern void push_path_no_escape(vtw_path *path, char *segm); extern void free_def(vtw_def *defp); -extern void free_sorted(vtw_sorted *sortp); extern vtw_path m_path, t_path; @@ -98,34 +80,14 @@ extern void add_val(valstruct *first, valstruct *second); extern int cli_val_read(char *buf, int max_size); extern vtw_node *make_val_node(valstruct *val); extern valstruct str2val(char *cp); -extern void dump_tree(vtw_node *node, int lev); -extern void dump_def(vtw_def *defp); -extern boolean val_cmp(const valstruct *left, const valstruct *right, - vtw_cond_e cond); -extern void out_of_memory(void) __attribute__((noreturn)); -extern void subtract_values(char **lhs, const char *rhs); -extern void internal_error(int line, const char *file) - __attribute__((noreturn)); -extern void done(void); -extern void del_value(vtw_def *defp, char *cp); -extern void print_msg(const char *msg, ...) - __attribute__((format(printf, 1, 2))); extern void switch_path(first_seg *seg); -extern void vtw_sort(valstruct *valp, vtw_sorted *sortp); extern void free_val(valstruct *val); -extern void touch(void); extern int mkdir_p(const char *path); extern boolean execute_list(vtw_node *cur, vtw_def *def, const char *outbuf,boolean format); -extern void touch_dir(const char *dp); -extern void touch_file(const char *name); -extern void copy_path(vtw_path *to, vtw_path *from); extern void free_path(vtw_path *path); -void mark_paths(vtw_mark *markp); -void restore_paths(vtw_mark *markp); - extern int get_config_lock(void); extern void release_config_lock(void); @@ -137,8 +99,6 @@ extern void release_config_lock(void); #define MOD_NAME ".modified" #define OPQ_NAME ".wh.__dir_opaque" -#define INTERNAL internal_error(__LINE__, __FILE__) - /*** output ***/ #define LOGFILE_STDOUT "/tmp/cfg-stdout.log" #define LOGFILE_STDERR "/tmp/cfg-stderr.log" @@ -156,9 +116,7 @@ extern FILE *err_stream; #undef CLI_DEBUG #ifdef CLI_DEBUG #define DPRINT(fmt, arg...) printf(fmt, #arg) -extern void dump_log(int argc, char **argv); #else #define DPRINT(fmt, arg...) while (0) { printf(fmt, ##arg); } -#define dump_log(argc, argv) #endif #endif diff --git a/src/cli_val_engine.c b/src/cli_val_engine.c index 4f0690f..6395d92 100644 --- a/src/cli_val_engine.c +++ b/src/cli_val_engine.c @@ -70,13 +70,6 @@ static boolean is_deactivated(const char *path, int in_active); *********************/ /** - * Special file names: - */ -#define VALUE_FILE ("node.val") -#define NODE_TAG ("node.tag") -#define NODE_DEF ("node.def") - -/** * "Command" definition (element of a variable path): */ @@ -172,7 +165,7 @@ static char** clind_get_current_value(clind_path_ref cfg_path, if(cfg_path_string && cfg_end) { - if(strcmp(cfg_end,VALUE_FILE)==0) { + if(strcmp(cfg_end,VAL_NAME)==0) { /* Value reference: */ value_ref = 1; @@ -226,10 +219,10 @@ static char** clind_get_current_value(clind_path_ref cfg_path, } else if(return_value_file_name) { ret=(char**)realloc(ret,sizeof(char*)*1); - ret[0]=(char*)malloc(strlen(cfg_path_string)+1+strlen(VALUE_FILE)+1); + ret[0]=(char*)malloc(strlen(cfg_path_string)+1+strlen(VAL_NAME)+1); strcpy(ret[0],cfg_path_string); strcpy(ret[0]+strlen(ret[0]),"/"); - strcpy(ret[0]+strlen(ret[0]),VALUE_FILE); + strcpy(ret[0]+strlen(ret[0]),VAL_NAME); *ret_size=1; } else { @@ -254,7 +247,7 @@ static char** clind_get_current_value(clind_path_ref cfg_path, } if(ret) { - if(tmpl_end && (strcmp(tmpl_end,NODE_TAG)==0)) { + if(tmpl_end && (strcmp(tmpl_end,TAG_NAME)==0)) { /* since it's a tag, it should be treated as a value */ value_ref = 1; clind_path_pop(tmpl_path_clone); @@ -267,7 +260,7 @@ static char** clind_get_current_value(clind_path_ref cfg_path, vtw_def def; struct stat statbuf; - int fn_node_def_size=strlen(tmpl_path_string)+1+strlen(NODE_DEF)+1; + int fn_node_def_size=strlen(tmpl_path_string)+1+strlen(DEF_NAME)+1; char* fn_node_def=(char*)malloc(fn_node_def_size); fn_node_def[0]=0; @@ -281,7 +274,7 @@ static char** clind_get_current_value(clind_path_ref cfg_path, strcpy(fn_node_def+strlen(fn_node_def),tmpl_path_string); strcpy(fn_node_def+strlen(fn_node_def),"/"); - strcpy(fn_node_def+strlen(fn_node_def),NODE_DEF); + strcpy(fn_node_def+strlen(fn_node_def),DEF_NAME); if ((lstat(fn_node_def, &statbuf) == 0)&& (is_deactivated(fn_node_def, in_active) == FALSE)&& @@ -351,7 +344,7 @@ static int is_multi_node(clind_path_ref tmpl_path) { const char* t_end = clind_path_last_string(tmpl_path); - if(t_end && (strcmp(t_end,NODE_TAG)==0)) { + if(t_end && (strcmp(t_end,TAG_NAME)==0)) { ret=1; } } @@ -370,7 +363,7 @@ static int is_node_def(clind_path_ref tmpl_path) { const char* t_end = clind_path_last_string(tmpl_path); - if(t_end && (strcmp(t_end,NODE_DEF)==0)) { + if(t_end && (strcmp(t_end,DEF_NAME)==0)) { ret=1; } } @@ -501,14 +494,14 @@ static clind_path_ref* clind_config_engine_apply_command(clind_path_ref cfg_path cfg_path = clind_path_clone(cfg_path); ret[0]=cfg_path; - if(t_end && (strcmp(t_end,NODE_TAG)==0)) { + if(t_end && (strcmp(t_end,TAG_NAME)==0)) { /* do nothing, we are there already */ - } else if(t_path_string && clind_file_exists(t_path_string,NODE_TAG)) { - clind_path_push(tmpl_path,NODE_TAG); - } else if(c_end && (strcmp(c_end,VALUE_FILE)==0)) { + } else if(t_path_string && clind_file_exists(t_path_string,TAG_NAME)) { + clind_path_push(tmpl_path,TAG_NAME); + } else if(c_end && (strcmp(c_end,VAL_NAME)==0)) { /* do nothing, we are there already */ } else { - clind_path_push(cfg_path,VALUE_FILE); + clind_path_push(cfg_path,VAL_NAME); } } @@ -553,21 +546,21 @@ static clind_path_ref* clind_config_engine_apply_command(clind_path_ref cfg_path const char* c_end = clind_path_last_string(cfg_path); - if(c_end && (strcmp(c_end,VALUE_FILE)==0)) { + if(c_end && (strcmp(c_end,VAL_NAME)==0)) { *result_len=1; ret=(clind_path_ref*)(malloc(*result_len * sizeof(clind_path_ref))); cfg_path = clind_path_clone(cfg_path); ret[0]=cfg_path; - } else if(clind_file_exists(cfg_path_string,VALUE_FILE)) { + } else if(clind_file_exists(cfg_path_string,VAL_NAME)) { *result_len=1; ret=(clind_path_ref*)(malloc(*result_len * sizeof(clind_path_ref))); cfg_path = clind_path_clone(cfg_path); ret[0]=cfg_path; - clind_path_push(cfg_path,VALUE_FILE); + clind_path_push(cfg_path,VAL_NAME); } else { @@ -594,7 +587,7 @@ static clind_path_ref* clind_config_engine_apply_command(clind_path_ref cfg_path } } while(1); - clind_path_push(tmpl_path,NODE_TAG); + clind_path_push(tmpl_path,TAG_NAME); closedir(dir); } diff --git a/src/common/unionfs.c b/src/common/unionfs.c index f33d3c3..0c95cab 100644 --- a/src/common/unionfs.c +++ b/src/common/unionfs.c @@ -378,13 +378,13 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root, } if (strcmp(dirp->d_name, ".") != 0 && strcmp(dirp->d_name, "..") != 0 && - strcmp(dirp->d_name, MODIFIED_FILE) != 0 && + strcmp(dirp->d_name, MOD_NAME) != 0 && strcmp(dirp->d_name, UNSAVED_FILE) != 0 && strcmp(dirp->d_name, DEF_FILE) != 0 && strcmp(dirp->d_name, DISABLE_FILE) != 0 && strcmp(dirp->d_name, WHITEOUT_FILE) != 0 && strcmp(dirp->d_name, WHITEOUT_DISABLE_FILE) != 0 && - strcmp(dirp->d_name, VALUE_FILE) != 0) { + strcmp(dirp->d_name, VAL_NAME) != 0) { processed = TRUE; NODE_ACTIVATE deactivated = K_NO_DISABLE_OP; @@ -601,7 +601,7 @@ boolean value_exists(char *path) { char buf[MAX_LENGTH_DIR_PATH]; - sprintf(buf, "%s/%s",path,VALUE_FILE); + sprintf(buf, "%s/%s",path,VAL_NAME); struct stat stat_buf; return !stat(buf,&stat_buf); } @@ -781,8 +781,6 @@ common_commit_copy_to_live_config(GNode *node, boolean suppress_piecewise_copy, static const char format1point1[]="mv -f %s/* -t %s"; /*mdirp, tmpp*/ static const char format1point5[]="rm -fr '%s'/*"; /*tmpp*/ - set_echo(TRUE); - char mbuf[MAX_LENGTH_DIR_PATH]; sprintf(mbuf,"%s%s",get_mdirp(),path); char cbuf[MAX_LENGTH_DIR_PATH]; @@ -910,8 +908,6 @@ common_commit_clean_temp_config(GNode *root_node, boolean test_mode) char abuf[MAX_LENGTH_DIR_PATH]; sprintf(abuf,"%s",get_adirp()); - set_echo(TRUE); - if (test_mode == FALSE) { sys_umount_session(); } diff --git a/src/common/unionfs.h b/src/common/unionfs.h index 362972e..0682b69 100644 --- a/src/common/unionfs.h +++ b/src/common/unionfs.h @@ -7,22 +7,6 @@ #include "../cli_val.h" #include "../cli_objects.h" -/* names of VYATTA env vars */ -#define ENV_EDIT_LEVEL "VYATTA_EDIT_LEVEL" -#define ENV_TEMPLATE_LEVEL "VYATTA_TEMPLATE_LEVEL" -#define ENV_A_DIR "VYATTA_ACTIVE_CONFIGURATION_DIR" -#define ENV_C_DIR "VYATTA_CHANGES_ONLY_DIR" -#define ENV_M_DIR "VYATTA_TEMP_CONFIG_DIR" -#define ENV_T_DIR "VYATTA_CONFIG_TEMPLATE" -#define ENV_TMP_DIR "VYATTA_CONFIG_TMP" -#define DEF_A_DIR "/opt/vyatta/config/active" -#define DEF_T_DIR "/opt/vyatta/share/ofr/template" -#define ENV_OLD_PS1 "VYATTA_OLD_PS1" -#define NODE_PRIORITY_FILE "/opt/vyatta/share/vyatta-cfg/priority" - -#define NODE_TAG_FILE "node.tag" -#define VALUE_FILE "node.val" -#define MODIFIED_FILE ".modified" #define UNSAVED_FILE ".unsaved" #define DISABLE_FILE ".disable" #define DEF_FILE "def" |