/** * Add user * * @param uname Name of the new user * @param passwd Password for the new user * @return NULL on success or an error string on failure */ char * admin_add_user(char *uname, char *passwd) { FILE *fp; char fname[1024], *home, *cpasswd; initialise(); if (access(get_datadir(), F_OK) != 0) { if (mkdir(get_datadir(), S_IRWXU) != 0 && errno != EEXIST) { return ADMIN_ERR_PWDFILEOPEN; } } snprintf(fname,1023, "%s/passwd", get_datadir()); fname[1023] = '\0'; if (users == NULL) { MXS_NOTICE("Create initial password file."); if ((users = users_alloc()) == NULL) { return ADMIN_ERR_NOMEM; } if ((fp = fopen(fname, "w")) == NULL) { MXS_ERROR("Unable to create password file %s.", fname); return ADMIN_ERR_PWDFILEOPEN; } fclose(fp); } if (users_fetch(users, uname) != NULL) { return ADMIN_ERR_DUPLICATE; } struct crypt_data cdata; cdata.initialized = 0; cpasswd = crypt_r(passwd, ADMIN_SALT, &cdata); users_add(users, uname, cpasswd); if ((fp = fopen(fname, "a")) == NULL) { MXS_ERROR("Unable to append to password file %s.", fname); return ADMIN_ERR_FILEAPPEND; } fprintf(fp, "%s:%s\n", uname, cpasswd); fclose(fp); return ADMIN_SUCCESS; }
/** * Load the admin users * * @return Table of users */ static USERS * loadUsers() { USERS *rval; FILE *fp; char fname[1024], *home; char uname[80], passwd[80]; initialise(); snprintf(fname,1023, "%s/passwd", get_datadir()); fname[1023] = '\0'; if ((fp = fopen(fname, "r")) == NULL) { return NULL; } if ((rval = users_alloc()) == NULL) { fclose(fp); return NULL; } while (fscanf(fp, "%[^:]:%s\n", uname, passwd) == 2) { users_add(rval, uname, passwd); } fclose(fp); return rval; }
void mkoas_init(char *prsfile, SGMNT_PRS *sgmnt_prs, ENHNC_PRS *enhnc_prs, int *rors_slit_range_thresh, float *r92a_discard_thresh, RGAR_PRS *rgar_prs, int *ascii_oas, int *update_freq, int *clobber_oas_file, FILE **fp_proc_images_list, int *n_oas, char *oas_file) { char *datadir, proc_images_list[200], str[400]; /* Reads first the oas (orientation arrays) parms file, then the mkoas additional-parms default file, then the required user parms file. Checks that every parm was set. */ memset(&mkoas_setflags, 0, sizeof(mkoas_setflags)); datadir = get_datadir(); sprintf(str, "%s/parms/oas.prs", datadir); mkoas_readparms(str, sgmnt_prs, enhnc_prs, rors_slit_range_thresh, r92a_discard_thresh, rgar_prs, ascii_oas, update_freq, clobber_oas_file, proc_images_list, oas_file); sprintf(str, "%s/parms/mkoas.prs", datadir); mkoas_readparms(str, sgmnt_prs, enhnc_prs, rors_slit_range_thresh, r92a_discard_thresh, rgar_prs, ascii_oas, update_freq, clobber_oas_file, proc_images_list, oas_file); mkoas_readparms(prsfile, sgmnt_prs, enhnc_prs, rors_slit_range_thresh, r92a_discard_thresh, rgar_prs, ascii_oas, update_freq, clobber_oas_file, proc_images_list, oas_file); mkoas_check_parms_allset(); strcpy(str, tilde_filename(proc_images_list, 0)); *n_oas = linecount(str); *fp_proc_images_list = fopen_ch(str, "rb"); }
int main(int argc, char **argv) { int result = 0; char *home, buf[1024]; /* Unlink any existing password file before running this test */ sprintf(buf, "%s/passwd", get_datadir()); if(!is_valid_posix_path(buf)) exit(1); if (strcmp(buf, "/etc/passwd") != 0) unlink(buf); result += test1(); result += test2(); result += test3(); result += test4(); result += test5(); /* Add the default user back so other tests can use it */ admin_add_user("admin", "mariadb"); exit(result); }
/** * Add user * * @param uname Name of the new user * @param passwd Password for the new user * @return NULL on success or an error string on failure */ char * admin_add_user(char *uname, char *passwd) { FILE *fp; char fname[1024], *home, *cpasswd; initialise(); sprintf(fname, "%s/passwd", get_datadir()); if (users == NULL) { LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE, "Create initial password file."))); if ((users = users_alloc()) == NULL) return ADMIN_ERR_NOMEM; if ((fp = fopen(fname, "w")) == NULL) { LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, "Error : Unable to create password file %s.", fname))); return ADMIN_ERR_PWDFILEOPEN; } fclose(fp); } if (users_fetch(users, uname) != NULL) { return ADMIN_ERR_DUPLICATE; } cpasswd = crypt(passwd, ADMIN_SALT); users_add(users, uname, cpasswd); if ((fp = fopen(fname, "a")) == NULL) { LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR, "Error : Unable to append to password file %s.", fname))); return ADMIN_ERR_FILEAPPEND; } fprintf(fp, "%s:%s\n", uname, cpasswd); fclose(fp); return ADMIN_SUCCESS; }
const char * get_install_datadir() { const char *datadir=0; if(install == FINDDIR_CUSTOM) { datadir=customdir(); if(datadir[0] == '\0') { printf("When you specify --install=custom, you need to specify --datadir, too.\n"); return 0; } return datadir; } else if(install < NUM_DATADIR && install >= 0) return get_datadir(install); return 0; }
void conkyrc_default () { FILE *fp; int i; fp = fopenf("%s/conkyrc", "w", tempdir()); if(fp == 0) { printf("failed to open %s with write permission.\n", tempdir()); return; } char ubuntufix; printf("Ubuntu/Debian distro? [y/N]: "); scanf("%c",&ubuntufix); const char *clockdir=finddir("bin/conkyClock"); const char *playerdir=finddir("bin/conky%s", player); const char *pltempldir=finddir("templates/conkyPlayer.template"); const char *coverdir=finddir("bin/conkyCover"); const char *yahooweatherdir=finddir("bin/conkyYahooWeather"); const char *bbcweatherdir=finddir("bin/conkyBBCWeather"); const char *conkyipdir=finddir("bin/conkyIp"); //Global Setup fprintf(fp,"######################\n"); fprintf(fp,"# - Conky settings - #\n"); fprintf(fp,"######################\n"); fprintf(fp,"update_interval 1\n"); fprintf(fp,"total_run_times 0\n"); fprintf(fp,"net_avg_samples 1\n"); fprintf(fp,"cpu_avg_samples 1\n"); fprintf(fp,"if_up_strictness link\n"); fprintf(fp,"\n"); fprintf(fp,"imlib_cache_size 0\n"); fprintf(fp,"double_buffer yes\n"); fprintf(fp,"no_buffers yes\n"); fprintf(fp,"\n"); fprintf(fp,"format_human_readable\n"); fprintf(fp,"\n"); fprintf(fp,"#####################\n"); fprintf(fp,"# - Text settings - #\n"); fprintf(fp,"#####################\n"); fprintf(fp,"use_xft yes\n"); fprintf(fp,"xftfont Ubuntu:size=8\n"); fprintf(fp,"override_utf8_locale yes\n"); fprintf(fp,"text_buffer_size 2048\n"); fprintf(fp,"\n"); fprintf(fp,"#############################\n"); fprintf(fp,"# - Window specifications - #\n"); fprintf(fp,"#############################\n"); fprintf(fp,"own_window_class Conky\n"); fprintf(fp,"own_window yes\n"); if (ubuntufix == 'y') fprintf(fp,"own_window_type override\n"); else fprintf(fp,"own_window_type normal\n"); if ((set_photo == 0 && cover < 2) && ubuntufix != 'y') { fprintf(fp, "own_window_argb_visual yes\n"); fprintf(fp, "own_window_argb_value %d\n", argb_value); } fprintf(fp,"own_window_transparent yes\n"); fprintf(fp,"own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager\n"); fprintf(fp,"\n"); if(strcmp("left",side) == 0) fprintf(fp,"alignment top_left\n"); else fprintf(fp,"alignment top_right\n"); if (cairo_set == 1) fprintf(fp,"gap_x 0\n"); else fprintf(fp,"gap_x 25\n"); fprintf(fp,"gap_y 40\n"); fprintf(fp,"minimum_size 182 600\n"); fprintf(fp,"maximum_width 182\n"); fprintf(fp,"\n"); fprintf(fp,"default_bar_size 60 8\n"); fprintf(fp,"\n"); fprintf(fp,"#########################\n"); fprintf(fp,"# - Graphics settings - #\n"); fprintf(fp,"#########################\n"); fprintf(fp,"draw_shades no\n"); if(elementary == True && dark == True) fprintf(fp,"\ndefault_color 2B2B2B\n"); else if(dark == True || black == True) fprintf(fp,"\ndefault_color 212526\n"); else if(ambiance == True) fprintf(fp,"\ndefault_color E2DACB\n"); else if(radiance == True) fprintf(fp,"\ndefault_color 3C3B37\n"); else if(elementary == True) fprintf(fp,"\ndefault_color D6D6D6\n"); else fprintf(fp,"\ndefault_color cccccc\n"); fprintf(fp,"\n"); //COLOR0 if (dark == True || black == True) fprintf(fp,"color0 1E1C1A\n"); else if (custom == True || radiance == True || ambiance == True || elementary == True) fprintf(fp,"color0 %s\n", color0); else fprintf(fp,"color0 white\n"); //COLOR1 fprintf(fp,"color1 %s\n", color1); //COLOR2 if (dark == True || black == True) fprintf(fp,"color2 1E1C1A\n"); else if (custom == True || radiance == True || ambiance == True || (elementary == True && dark != True)) fprintf(fp,"color2 %s\n", color2); else fprintf(fp,"color2 white\n"); //COLOR3 fprintf(fp,"color3 %s\n", color3); fprintf(fp,"\n"); fprintf(fp,"TEXT\n"); //System Widget fprintf(fp,"${font Ubuntu:style=Bold:size=8}%s $stippled_hr${font}\n", sys); fprintf(fp,"##############\n"); fprintf(fp,"# - SYSTEM - #\n"); fprintf(fp,"##############\n"); //Logo if (logo == True) { fprintf(fp,"${color0}${voffset 6}${font OpenLogos:size=19}%s${font}${color}", logo_letter); fprintf(fp,"${goto %d}${voffset -14}Kernel: ${alignr}${color2}${kernel}${color}\n", go2); } else { fprintf(fp,"${color0}${font Poky:size=14}S${font}${color}"); fprintf(fp,"${goto %d}${voffset -8}Kernel: ${alignr}${color2}${kernel}${color}\n", go2); } fprintf(fp,"${goto %d}%s: ${alignr}${color2}${uptime}${color}\n", go2, uptime); //Updates if (aptget == True) { fprintf(fp,"# |--UPDATES\n"); fprintf(fp,"${goto %d}%s: ${alignr}${font Ubuntu:style=Bold:size=8}${color1}${execi 360 aptitude search \"~U\" | wc -l | tail}${color}${font} ${color2}%s${color}\n", go2, updates, packages); } //Gmail widget if (gmail == True) { fprintf(fp,"# |--GMAIL\n"); fprintf(fp,"${goto %d}Gmail: ${alignr}${font Ubuntu:style=Bold:size=8}${color0}${execpi 3600 %s/bin/conkyEmail -m IMAP -s imap.googlemail.com -u %s -p %s --ssl}${color}${font} %s email(s)\n", go2, finddir("bin/conkyEmail"), user, password, nouve); } //CPU fprintf(fp,"# |--CPU\n"); if (cpu == 1) { fprintf(fp,"${voffset 2}${offset 2}${color0}${font Poky:size=14}P${color}${font}${voffset -4}"); if (cputemp == True) { if (unit == True) fprintf(fp,"${goto %d}CPU: ${font Ubuntu:style=Bold:size=8}${color1}${cpu cpu1}%%${font} ${alignr}${font Ubuntu:style=Bold:size=8}${color1}${execi 30 sensors -f | grep 'Core 0' | awk '{print $3}' | sed 's/+//' | sed 's/\\.0//g'}${color}${font} ${color2}${cpugraph cpu1 8,50 %s}${color}\n", go2, color4); else fprintf(fp,"${goto %d}CPU: ${font Ubuntu:style=Bold:size=8}${color1}${cpu cpu1}%%${font} ${alignr}${font Ubuntu:style=Bold:size=8}${color1}${execi 30 sensors | grep 'Core 0' | awk '{print $3}' | sed 's/+//' | sed 's/\\.0//g'}${color}${font} ${color2}${cpugraph cpu1 8,50 %s}${color}\n", go2, color4); } else fprintf(fp,"${goto %d}CPU: ${font Ubuntu:style=Bold:size=8}${color1}${cpu cpu1}%%${color}${font} ${alignr}${color2}${cpugraph cpu1 8,60 %s}${color}\n", go2, color4); } else { fprintf(fp,"${voffset 2}${offset 2}${color0}${font Poky:size=14}P${font}${offset -19}${voffset 9}${offset 1}${cpubar cpu0 4,18}${color}${voffset -16}"); for (i = 1; i <= cpu; i++) { if (cputemp == True) { if (unit == True) fprintf(fp,"${goto %d}CPU%d: ${font Ubuntu:style=Bold:size=8}${color1}${cpu cpu%d}%%${font} ${alignr}${font Ubuntu:style=Bold:size=8}${color1}${execi 30 sensors -f | grep 'Core %d' | awk '{print $3}' | sed 's/+//' | sed 's/\\.0//g'}${color}${font} ${color2}${cpugraph cpu%d 8,50 %s}${color}\n", go2, i, i, i-1, i, color4); else fprintf(fp,"${goto %d}CPU%d: ${font Ubuntu:style=Bold:size=8}${color1}${cpu cpu%d}%%${font} ${alignr}${font Ubuntu:style=Bold:size=8}${color1}${execi 30 sensors | grep 'Core %d' | awk '{print $3}' | sed 's/+//' | sed 's/\\.0//g'}${color}${font} ${color2}${cpugraph cpu%d 8,50 %s}${color}\n", go2, i, i, i-1, i, color4); } else fprintf(fp,"${goto %d}CPU%d: ${font Ubuntu:style=Bold:size=8}${color1}${cpu cpu%d}%%${color}${font} ${alignr}${color2}${cpugraph cpu%d 8,60 %s}${color}\n", go2, i, i, i, color4); } } //Memory fprintf(fp,"# |--MEM\n"); fprintf(fp,"${voffset 2}${offset 1}${color0}${font Poky:size=14}M${font}${color}${goto %d}${voffset -7}RAM: ${font Ubuntu:style=Bold:size=8}${color1}$memperc%%${color}${font}\n", go2); fprintf(fp,"${voffset 1}${offset 1}${voffset 2}${color0}${membar 4,18}${color}${goto %d}${voffset -2}F: ${font Ubuntu:style=Bold:size=8}${color2}${memeasyfree}${color}${font} U: ${font Ubuntu:style=Bold:size=8}${color2}${mem}${color}${font}\n", go2); //Swap if (swap == True) { fprintf(fp,"# |--SWAP\n"); fprintf(fp,"${voffset 4}${offset 1}${color0}${font Poky:size=12}s${font}${color}${voffset -4}${goto %d}SWAP: ${font Ubuntu:style=Bold:size=8}${color1}${swapperc}%%${color}${font}\n", go2); fprintf(fp,"${voffset 2}${offset 1}${color0}${swapbar 4,18}${color}${voffset -2}${goto %d}F: ${font Ubuntu:style=Bold:size=8}${color2}$swapmax${color}${font} U: ${font Ubuntu:style=Bold:size=8}${color2}$swap${color}${font}\n", go2); } //Battery if (set_battery == True) { fprintf(fp,"# |--BATTERY\n"); fprintf(fp,"${if_existing /sys/class/power_supply/BAT%d}${color0}${font Poky:size=13}E${font}${color}${goto %d}${voffset -5}%s: ${font Ubuntu:style=Bold:size=8}${color1}${battery_percent BAT%d}%%${color}${font} ${alignr}${color2}${battery_bar BAT%d 8,60}${color}${else}${color0}${font Poky:size=13}E${font}${color}${goto %d}${voffset -5}%s: ${font Ubuntu:style=Bold:size=8}${color2}%s${color}${font}${endif}\n", battery_value, go2, battery, battery_value, battery_value, go2, battery, unknownstatus); } //Processes if (set_process == True) { fprintf(fp,"# |--PROC\n"); fprintf(fp,"${voffset 2}${voffset 1}${color0}${font Poky:size=14}a${font}${color}${goto %d}${voffset -10}%s: ${color2}${alignr 13}CPU${alignr}RAM${color}\n", go2, processes); for (i = True; i <= proc; i++) fprintf(fp,"${voffset -1}${goto 42}${color2}${top name %d}${color}${font Ubuntu:style=Bold:size=8}${color1} ${goto 126}${top cpu %d}${alignr }${top mem %d}${color}${font}\n", i, i, i); } //Clock and Calendar Widget if (nodata == False) { fprintf(fp,"#############\n"); fprintf(fp,"# - CLOCK - #\n"); fprintf(fp,"#############\n"); fprintf(fp,"${voffset 4}${font Ubuntu:style=Bold:size=8}%s $stippled_hr${font}\n", date); //Classic Theme if (clocktype == 1) { fprintf(fp,"${voffset 10}${alignc 55}${font aClock:style=_Hour:size=90}${color2}${execpi 120 %s/bin/conkyClock_h}${color}${font}\n", finddir("bin/conkyClock_h") ); fprintf(fp,"${voffset -98}${alignc 55}${font aClock:style=_Min:size=90}${color2}${execpi 60 %s/bin/conkyClock_m}${color}${font}\n", finddir("bin/conkyClock_m") ); fprintf(fp,"${voffset 12}${alignc}${font Ubuntu:style=Bold:size=10}${color1}${time %%H:%%M}${color}${font}${voffset -8}\n"); } //Slim Theme else if (clocktype == 2) { fprintf(fp,"${voffset 20}${alignc 44}${font zoraclockH:size=70}${color2}${execpi 120 %s/bin/conkyClock hour}${color}${font}\n", clockdir ); fprintf(fp,"${voffset -90}${alignc 64}${font zoraclockM:size=100}${color2}${execpi 60 %s/bin/conkyClock minute}${color}${font}\n", clockdir ); fprintf(fp,"${voffset 26}${alignc}${font Ubuntu:style=Bold:size=10}${color1}${time %%H:%%M}${color}${font}${voffset -8}\n"); } //Modern Theme else if (clocktype == 3) { fprintf(fp,"${voffset -12}${goto 28}${font Arial Black:size=38}${color2}${time %%H}${color}${font}${voffset -28}${font Ubuntu:style=Bold:size=11}${color2}${time :%%M}${time :%%S}${color}${font}\n"); fprintf(fp,"${voffset -2}${goto 100}${font Ubuntu:style=Bold:size=8}${color2}${time %%A}${color}${font}\n"); fprintf(fp,"${goto 100}${time %%d %%b %%Y}\n"); } //Lucky Theme else if (clocktype == 4) { fprintf(fp,"${voffset 4}${goto 32}${font clockfaces:size=40}O${font}\n"); fprintf(fp,"${voffset -34}${goto 41}${font zoraclockH:size=30}${color2}${execpi 120 %s/bin/conkyClock hour}${color}${font}\n", clockdir); fprintf(fp,"${voffset -39}${goto 35}${font zoraclockM:size=40}${color2}${execpi 60 %s/bin/conkyClock minute}${color}${font}\n", clockdir); fprintf(fp,"${goto 100}${voffset -40}${font Ubuntu:style=Bold:size=11}${color2}${time %%H}${time :%%M}${time :%%S}${color}${font}\n"); fprintf(fp,"${goto 100}${voffset -2}${goto 100}${font Ubuntu:style=Bold:size=8}${color2}${time %%A}${color}${font}\n"); fprintf(fp,"${goto 100}${time %%d %%b %%Y}${voffset 8}\n"); } //Digital Theme else if (clocktype == 5) { fprintf(fp,"${font Digital Readout Thick Upright:size=40}${goto 22}${color2}${time %%k}${voffset -9}:${voffset 9}${time %%M}${goto 130}${color2}${voffset -14}${font Digital Readout Thick Upright:size=24}${goto 130}${color2}${time %%d}${font Digital Readout Thick Upright:size=12}${voffset 14}${goto 130}${color2}${time %%m}${goto 144}${color2}${time %%y}${font}\n"); } //Clock off else if (clocktype == 6); //Clock Default Theme else fprintf(fp,"${voffset -10}${alignc 46}${color2}${font Arial Black:size=30}${time %%H:%%M}${font}${color}\n"); if (clocktype != 3 && clocktype != 4 && clocktype != 5) { if (clocktype == 1 || clocktype == 2) fprintf(fp,"${voffset 8}${alignc}${time %%d %%B %%Y}\n"); else if (clocktype == 5) fprintf(fp,"${voffset 4}${alignc}${time %%d %%B %%Y}\n"); else if (set_calendar > 0) fprintf(fp,"${voffset 6}${alignc}${time %%d %%B %%Y}${voffset -6}\n"); else fprintf(fp,"${alignc}${time %%d %%B %%Y}\n"); } //Calendar if (set_calendar > 0) { fprintf(fp,"################\n"); fprintf(fp,"# - CALENDAR - #\n"); fprintf(fp,"################\n"); if (set_calendar == 1) { fprintf(fp,"${voffset -2}${color0}${font Poky:size=16}D${font}${voffset -8}${font Ubuntu:style=Bold:size=7}${offset -17}${voffset 4}${time %%d}${font}${color}${voffset -1}${font Monospace:size=7}${execpi 300 DJS=`date +%%_d`; cal "); if (ubuntufix == 'y') fprintf(fp,"-h "); fprintf(fp,"|sed \'2,8!d\'| sed \'/./!d\' | sed \'s/^/${goto 42} /\'| sed \'s/$/ /\' | sed \'s/^/ /\' | sed /\" $DJS \"/s/\" $DJS \"/\" \"\'${font Arial:style=Bold:size=8}${voffset -2}${offset -4}${color1} \'\"$DJS\"\'${color}${font Monospace:size=7}\'\" \"/}${voffset -1}\n"); if (ubuntufix == 'y') fprintf(fp,"${voffset -22}\n"); } else if (set_calendar == 2) fprintf(fp,"${voffset -2}${color0}${font Poky:size=16}D${font}${voffset -8}${font Ubuntu:style=Bold:size=7}${offset -17}${voffset 4}${time %%d}${font}${color}${font Monospace:size=7}${execpi 10800 %s/bin/conkyZimCalendar}${font}${voffset -14}\n", finddir("bin/conkyZimCalendar")); else { fprintf(fp,"${voffset -2}${color0}${font Poky:size=16}D${font}${voffset -8}${font Ubuntu:style=Bold:size=7}${offset -17}${voffset 4}${time %%d}${font}${color}${voffset -1}${font Monospace:size=7}${execpi 300 DJS=`date +%%_d`; cal "); if (ubuntufix == 'y') fprintf(fp,"-h "); fprintf(fp," -m|sed \'2,8!d\'| sed \'/./!d\' | sed \'s/^/${goto 42} /\'| sed \'s/$/ /\' | sed \'s/^/ /\' | sed /\" $DJS \"/s/\" $DJS \"/\" \"\'${font Ubuntu:style=Bold:size=8}${voffset -2}${offset -4}${color1} \'\"$DJS\"\'${color}${font Monospace:size=7}\'\" \"/}${voffset -1}\n"); if (ubuntufix == 'y') fprintf(fp,"${voffset -22}\n"); } } } //Photo Widget if (set_photo > 0) { int num=num_datadir(); fprintf(fp,"#############\n"); fprintf(fp,"# - PHOTO - #\n"); fprintf(fp,"#############\n"); fprintf(fp,"# For a working photo widget you need to specify a file or directory in conkyPhoto or conkyPhotoRandom script in "); for(i=0; i<num; ++i) { const char *dir=get_datadir(i); if(dir[0] != '\0') fprintf(fp, " %s/bin", dir); } fprintf(fp," folders\n"); fprintf(fp,"${voffset 4}${font Ubuntu:style=Bold:size=8}%s $stippled_hr${font}\n", photo); if (set_photo == 1) fprintf(fp,"${execi 10800 %s/bin/conkyPhoto}${image /tmp/conkyPhoto.png -s 174x110 -p 4,%d}${voffset 104}\n", finddir("bin/conkyPhoto"), yp); else fprintf(fp,"${execi 60 %s/bin/conkyPhotoRandom}${image /tmp/conkyPhoto.png -s 174x110 -p 4,%d}${voffset 104}\n", finddir("bin/conkyPhotoRandom"), yp); } //Rhythmbox/Banshee/Clementine Widget if (rhythmbox == True || banshee == True || clementine == True) { fprintf(fp,"####################\n"); fprintf(fp,"# - MEDIA PLAYER - #\n"); fprintf(fp,"####################\n"); fprintf(fp,"${voffset 4}${font Ubuntu:style=Bold:size=8}MEDIA PLAYER $stippled_hr${font}\n"); if (cover > 2) fprintf(fp,"${execi 6 %s/bin/conkyCover}", coverdir); fprintf(fp,"${execpi 2 %s/bin/conky%s -t %s/templates/conkyPlayer.template}\n", playerdir, player, pltempldir ); } //MPD Widget if (mpd == True) { fprintf(fp,"###########\n"); fprintf(fp,"# - MPD - #\n"); fprintf(fp,"###########\n"); fprintf(fp,"${voffset 4}${font Ubuntu:style=Bold:size=8}MPD $stippled_hr${font}\n"); fprintf(fp,"${execpi 2 %s/bin/conkyMPD}\n", finddir("bin/conkyMPD") ); } //CoverGloobus Widget if (covergloobus == True) { fprintf(fp,"####################\n"); fprintf(fp,"# - CoverGloobus - #\n"); fprintf(fp,"####################\n"); fprintf(fp,"${voffset 4}${font Ubuntu:style=Bold:size=8}MEDIA PLAYER $stippled_hr${font}\n"); fprintf(fp,"${voffset 80}\n"); } //TASK if (todo == True) { fprintf(fp,"############\n"); fprintf(fp,"# - TASK - #\n"); fprintf(fp,"############\n"); fprintf(fp,"# type \"ct help\" in terminal for info\n"); fprintf(fp,"${voffset 4}${font Ubuntu:style=Bold:size=8}TASK $stippled_hr${font}\n"); fprintf(fp,"${voffset 4}${execpi 5 cat ~/.conkycolors/tasks | fold -w 38 | sed 's/\\[ \\]/\\[ \\]/' | sed 's/\\[X\\]/\\[ X \\]/' | sed 's/\\] /\\] ${color2}/' | sed 's/$/${color}/' | sed 's/ X /${color0}${font Poky:size=7}A${font}${color}${voffset -1}/'}\n"); } //NVIDIA Widget if (nvidia == True) { fprintf(fp,"##############\n"); fprintf(fp,"# - NVIDIA - #\n"); fprintf(fp,"##############\n"); fprintf(fp,"${voffset 4}${font Ubuntu:style=Bold:size=8}NVIDIA $stippled_hr${font}\n"); fprintf(fp,"${color0}${voffset -4}${font Poky:size=17}N${font}${color}"); fprintf(fp,"${goto %d}${voffset -8}GPU Temp:${alignr}${font Ubuntu:style=Bold:size=8}${color1} ${exec nvidia-settings -q GPUCoreTemp | grep Attribute | cut -d ' ' -f 6 | cut -c 1-2}${font}${color}°C\n", go2); fprintf(fp,"${goto %d}GPU Clock:${alignr}${font Ubuntu:style=Bold:size=8}${color1} ${exec nvidia-settings -q GPU2DClockFreqs -t}${font}${color}MHz\n", go2); fprintf(fp,"${goto %d}Video RAM:${alignr}${font Ubuntu:style=Bold:size=8}${color1} ${exec nvidia-settings -q VideoRam -t}${font}${color}KiB\n", go2); fprintf(fp,"${goto %d}Driver Version:${alignr}${font Ubuntu:style=Bold:size=8}${color1} ${exec nvidia-settings -q NvidiaDriverVersion -t}${font}${color}\n", go2); } //HD Widget if (set_hd == True) { fprintf(fp,"##########\n"); fprintf(fp,"# - HD - #\n"); fprintf(fp,"##########\n"); fprintf(fp,"${voffset 4}${font Ubuntu:style=Bold:size=8}%s $stippled_hr${font}\n", hd); if (hdtemp1 == True) { fprintf(fp,"# |--HDTEMP1\n"); if (hdtemp2 == True || hdtemp3 == True || hdtemp4 == True) if (unit == True) fprintf(fp," ${voffset 4}${color0}${font Weather:size=15}y${font}${color}${voffset -8}${goto %d}/dev/%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 120 hddtemp /dev/%s -n --unit=F}°F${color}${font}\n", go2, dev1, dev1); else fprintf(fp," ${voffset 4}${color0}${font Weather:size=15}y${font}${color}${voffset -8}${goto %d}/dev/%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 120 hddtemp /dev/%s -n --unit=C}°C${color}${font}\n", go2, dev1, dev1); else if (unit == True) fprintf(fp," ${voffset 4}${color0}${font Weather:size=15}y${font}${color}${voffset -3}${goto %d}%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 120 hddtemp /dev/%s -n --unit=F}°F${color}${font}${alignr}${color2}/dev/%s${color}\n", go2, temperature, dev1, dev1); else fprintf(fp," ${voffset 4}${color0}${font Weather:size=15}y${font}${color}${voffset -3}${goto %d}%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 120 hddtemp /dev/%s -n --unit=C}°C${color}${font}${alignr}${color2}/dev/%s${color}\n", go2, temperature, dev1, dev1); } if (hdtemp2 == True) { fprintf(fp,"# |--HDTEMP2\n"); if (unit == True) fprintf(fp,"${goto %d}/dev/%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 120 hddtemp /dev/%s -n --unit=F}°F${color}${font}\n", go2, dev2, dev2); else fprintf(fp,"${goto %d}/dev/%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 120 hddtemp /dev/%s -n --unit=C}°C${color}${font}\n", go2, dev2, dev2); } if (hdtemp3 == True) { fprintf(fp,"# |--HDTEMP3\n"); if (unit == True) fprintf(fp,"${goto %d}/dev/%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 120 hddtemp /dev/%s -n --unit=F}°F${color}${font}\n", go2, dev3, dev3); else fprintf(fp,"${goto %d}/dev/%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 120 hddtemp /dev/%s -n --unit=C}°C${color}${font}\n", go2, dev3, dev3); } if (hdtemp4 == True) { fprintf(fp,"# |--HDTEMP4\n"); if (unit == True) fprintf(fp,"${goto %d}/dev/%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 120 hddtemp /dev/%s -n --unit=F}°F${color}${font}\n", go2, dev4, dev4); else fprintf(fp,"${goto %d}/dev/%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 120 hddtemp /dev/%s -n --unit=C}°C${color}${font}\n", go2, dev4, dev4); } //Default Theme if (hdtype == 1) fprintf(fp,"${execpi 30 %s/bin/conkyHD1}\n", finddir("bin/conkyHD1") ); else //Meerkat Theme if (hdtype == 2) fprintf(fp,"${execpi 30 %s/bin/conkyHD2}\n", finddir("bin/conkyHD2") ); else //Mix Theme if (hdtype == 3) fprintf(fp,"${execpi 30 %s/bin/conkyHD3}\n", finddir("bin/conkyHD3") ); else //Simple Theme fprintf(fp,"${execpi 30 %s/bin/conkyHD4}\n", finddir("bin/conkyHD4") ); } //Network Widget if (set_network == True) { fprintf(fp,"###############\n"); fprintf(fp,"# - NETWORK - #\n"); fprintf(fp,"###############\n"); if ((rhythmbox == True || banshee == True || clementine == True) && set_hd == 0) fprintf(fp,"${voffset 4}${font Ubuntu:style=Bold:size=8}%s $stippled_hr${font}\n", network); else fprintf(fp,"${voffset -4}${font Ubuntu:style=Bold:size=8}%s $stippled_hr${font}\n", network); fprintf(fp,"# |--WLAN%d\n", wlan); fprintf(fp,"${if_up wlan%d}\n", wlan); fprintf(fp,"${voffset -5}${color0}${font Webdings:size=17}”${font}${color}${goto %d}${voffset -5}%s: ${font Ubuntu:style=Bold:size=8}${color1}${upspeed wlan%d}${color}${font} ${alignr}${color2}${upspeedgraph wlan%d 8,60 %s}${color}\n", go2, up, wlan, wlan, color4); fprintf(fp,"${goto %d}%s: ${font Ubuntu:style=Bold:size=8}${color2}${totalup wlan%d}${color}${font}\n", go2, total, wlan); fprintf(fp,"${voffset 2}${color0}${font Webdings:size=17}“${font}${color}${goto %d}${voffset -5}%s: ${font Ubuntu:style=Bold:size=8}${color1}${downspeed wlan%d}${color}${font} ${alignr}${color2}${downspeedgraph wlan%d 8,60 %s}${color}\n", go2, down, wlan, wlan, color4); fprintf(fp,"${goto %d}%s: ${font Ubuntu:style=Bold:size=8}${color2}${totaldown wlan%d}${color}${font}\n", go2, total, wlan); fprintf(fp,"${voffset 2}${color0}${font Poky:size=14}Y${font}${color}${goto %d}${voffset -2}%s: ${font Ubuntu:style=Bold:size=8}${color1}${wireless_link_qual_perc wlan%d}%%${color}${font} ${alignr}${color2}${wireless_link_bar 8,60 wlan%d}${color}\n", go2, sinal, wlan, wlan); fprintf(fp,"${voffset 2}${color0}${font Webdings:size=16}¬${font}${color}${goto %d}${voffset -8}%s: ${alignr}${color2}${addr wlan%d}${color}\n", go2, localip, wlan); fprintf(fp,"${goto %d}%s: ${alignr}${color2}${execi 10800 %s/bin/conkyIp}${color}\n", go2, publicip, conkyipdir ); fprintf(fp,"# |--ETH%d\n", eth); fprintf(fp,"${else}${if_up eth%d}\n", eth); fprintf(fp,"${voffset -5}${color0}${font Webdings:size=17}”${font}${color}${goto %d}${voffset -5}%s: ${font Ubuntu:style=Bold:size=8}${color1}${upspeed eth%d}${color}${font} ${alignr}${color2}${upspeedgraph eth%d 8,60 %s}${color}\n", go2, up, eth, eth, color4); fprintf(fp,"${goto %d}%s: ${font Ubuntu:style=Bold:size=8}${color2}${totalup eth%d}${color}${font}\n", go2, total, eth); fprintf(fp,"${voffset 2}${color0}${font Webdings:size=17}“${font}${color}${goto %d}${voffset -5}%s: ${font Ubuntu:style=Bold:size=8}${color1}${downspeed eth%d}${color}${font} ${alignr}${color2}${downspeedgraph eth%d 8,60 %s}${color}\n", go2, down, eth, eth, color4); fprintf(fp,"${goto %d}%s: ${font Ubuntu:style=Bold:size=8}${color2}${totaldown eth%d}${color}${font}\n", go2, total, eth); fprintf(fp,"${voffset 2}${color0}${font Webdings:size=16}¬${font}${color}${goto %d}${voffset -4}%s: ${alignr}${color2}${addr eth%d}${color}\n", go2, localip, eth); fprintf(fp,"${goto %d}%s: ${alignr}${color2}${execi 10800 %s/bin/conkyIp}${color}\n", go2, publicip, conkyipdir); fprintf(fp,"# |--PPP%d\n", ppp); fprintf(fp,"${else}${if_up ppp%d}\n", ppp); fprintf(fp,"${voffset -5}${color0}${font Webdings:size=17}”${font}${color}${goto %d}${voffset -5}%s: ${font Ubuntu:style=Bold:size=8}${color1}${upspeed ppp%d}${color}${font} ${alignr}${color2}${upspeedgraph ppp%d 8,60 %s}${color}\n", go2, up, ppp, ppp, color4); fprintf(fp,"${goto %d}%s: ${font Ubuntu:style=Bold:size=8}${color2}${totalup ppp%d}${color}${font}\n", go2, total, ppp); fprintf(fp,"${voffset 2}${color0}${font Webdings:size=17}“${font}${color}${goto %d}${voffset -5}%s: ${font Ubuntu:style=Bold:size=8}${color1}${downspeed ppp%d}${color}${font} ${alignr}${color2}${downspeedgraph ppp%d 8,60 %s}${color}\n", go2, down, ppp, ppp, color4); fprintf(fp,"${goto %d}%s: ${font Ubuntu:style=Bold:size=8}${color2}${totaldown ppp%d}${color}${font}\n", go2, total, ppp); fprintf(fp,"${voffset 2}${color0}${font Webdings:size=16}¬${font}${color}${goto %d}${voffset -4}%s: ${alignr}${color2}${addr ppp%d}${color}\n", go2, localip, ppp); fprintf(fp,"${else}${voffset 4}${offset 4}${color0}${font Wingdings:size=20}N${font}${color}${voffset -6}${goto %d}%s${voffset 14}${endif}${endif}${endif}\n", go2, nonet); } //Weather Widget if (set_weather == 1) { fprintf(fp,"####################\n"); fprintf(fp,"# - WEATHER - #\n"); fprintf(fp,"####################\n"); fprintf(fp,"# http://weather.yahoo.com/\n"); if (set_network == True) fprintf(fp,"${voffset -8}${font Ubuntu:style=Bold:size=8}%s $stippled_hr${font}\n", Weather); else fprintf(fp,"${voffset -4}${font Ubuntu:style=Bold:size=8}%s $stippled_hr${font}\n", Weather); if (unit == True) { fprintf(fp,"${if_gw}${voffset 4}${offset -4}${color0}${font Webdings:size=24}·${font}${color}\n"); fprintf(fp,"${voffset -24}${goto %d}%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 600 %s/bin/conkyYahooWeather cur %s f}°F${color}${font}\n", go2, temperature, yahooweatherdir, weather_code); fprintf(fp,"${goto %d}${voffset -2}${color0}${font Webdings}6${font}${color}${font Ubuntu:style=Bold:size=8}${color1}${execi 600 %s/bin/conkyYahooWeather min %s c}°F${color}${font} ${voffset -2}${color0}${font Webdings}5${font}${color}${voffset -1}${font Ubuntu:style=Bold:size=8}${color1}${execi 600 %s/bin/conkyYahooWeather max %s c}°F${color}${font}\n", go2, yahooweatherdir, weather_code, yahooweatherdir, weather_code); fprintf(fp,"${else}${voffset 4}${offset 4}${color0}${font Wingdings:size=20}N${font}${color}${voffset -6}${goto %d}%s${voffset 14}${endif}\n", go2, noweather); } else { fprintf(fp,"${if_gw}${voffset 4}${offset -4}${color0}${font Webdings:size=24}·${font}${color}\n"); fprintf(fp,"${voffset -24}${goto %d}%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 600 %s/bin/conkyYahooWeather cur %s c}°C${color}${font}\n", go2, temperature, yahooweatherdir, weather_code); fprintf(fp,"${goto %d}${voffset -2}${color0}${font Webdings}6${font}${color}${font Ubuntu:style=Bold:size=8}${color1}${execi 600 %s/bin/conkyYahooWeather min %s c}°C${color}${font} ${voffset -2}${color0}${font Webdings}5${font}${color}${voffset -1}${font Ubuntu:style=Bold:size=8}${color1}${execi 600 %s/bin/conkyYahooWeather max %s c}°C${color}${font}\n", go2, yahooweatherdir, weather_code, yahooweatherdir, weather_code); fprintf(fp,"${else}${voffset 4}${offset 4}${color0}${font Wingdings:size=20}N${font}${color}${voffset -6}${goto %d}%s${voffset 14}${endif}\n", go2, noweather); } } else if (set_weather == 2) { fprintf(fp,"##################\n"); fprintf(fp,"# - BBCWEATHER - #\n"); fprintf(fp,"##################\n"); fprintf(fp,"# http://news.bbc.co.uk/weather/\n"); if (set_network == True) fprintf(fp,"${voffset -8}${font Ubuntu:style=Bold:size=8}%s $stippled_hr${font}\n", Weather); else fprintf(fp,"${voffset -4}${font Ubuntu:style=Bold:size=8}%s $stippled_hr${font}\n", Weather); if (unit == True) { fprintf(fp,"${if_gw}${voffset 4}${offset -4}${color0}${font Webdings:size=24}·${font}${color}\n"); fprintf(fp,"${voffset -24}${goto %d}%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 600 %s/bin/conkyBBCWeather cur %d f}°F${color}${font}\n", go2, temperature, bbcweatherdir, bbccode); fprintf(fp,"${goto %d}${voffset -2}${color0}${font Webdings}6${font}${color}${font Ubuntu:style=Bold:size=8}${color1}${execi 600 %s/bin/conkyBBCWeather min %d f}°F${color}${font} ${voffset -2}${color0}${font Webdings}5${font}${color}${voffset -1}${font Ubuntu:style=Bold:size=8}${color1}${execi 600 %s/bin/conkyBBCWeather max %d f}°F${color}${font}\n", go2, bbcweatherdir, bbccode, bbcweatherdir, bbccode); fprintf(fp,"${goto %d}%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 600 %s/bin/conkyBBCWeather hum %d f}%%${color}${font}${alignr}${color2}${execbar %s/bin/conkyBBCWeather hum %d f}%%${color}${font}\n", go2, humidity, bbcweatherdir, bbccode, bbcweatherdir, bbccode); fprintf(fp,"${else}${voffset 4}${offset 4}${color0}${font Wingdings:size=20}N${font}${color}${voffset -6}${goto %d}%s${voffset 14}${endif}\n", go2, noweather); } else { fprintf(fp,"${if_gw}${voffset 4}${offset -4}${color0}${font Webdings:size=24}·${font}${color}\n"); fprintf(fp,"${voffset -24}${goto %d}%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 600 %s/bin/conkyBBCWeather cur %d c}°C${color}${font}\n", go2, temperature, bbcweatherdir, bbccode); fprintf(fp,"${goto %d}${voffset -2}${color0}${font Webdings}6${font}${color}${font Ubuntu:style=Bold:size=8}${color1}${execi 600 %s/bin/conkyBBCWeather min %d c}°C${color}${font} ${voffset -2}${color0}${font Webdings}5${font}${color}${voffset -1}${font Ubuntu:style=Bold:size=8}${color1}${execi 600 %s/bin/conkyBBCWeather max %d c}°C${color}${font}\n", go2, bbcweatherdir, bbccode, bbcweatherdir, bbccode); fprintf(fp,"${goto %d}%s: ${font Ubuntu:style=Bold:size=8}${color1}${execi 600 %s/bin/conkyBBCWeather hum %d c}%%${color}${font}${alignr}${color2}${execbar %s/bin/conkyBBCWeather hum %d c}%%${color}${font}\n", go2, humidity, bbcweatherdir, bbccode, bbcweatherdir, bbccode); fprintf(fp,"${else}${voffset 4}${offset 4}${color0}${font Wingdings:size=20}N${font}${color}${voffset -6}${goto %d}%s${voffset 14}${endif}\n", go2, noweather); } } fclose(fp); }
/** * Remove maxscale user from in-memory structure and from password file * * @param uname Name of the new user * @param passwd Password for the new user * @return NULL on success or an error string on failure */ char* admin_remove_user( char* uname, char* passwd) { FILE* fp; FILE* fp_tmp; char fname[1024]; char fname_tmp[1024]; char* home; char fusr[LINELEN]; char fpwd[LINELEN]; char line[LINELEN]; fpos_t rpos; int n_deleted; if (!admin_search_user(uname)) { MXS_ERROR("Couldn't find user %s. Removing user failed.", uname); return ADMIN_ERR_USERNOTFOUND; } if (admin_verify(uname, passwd) == 0) { MXS_ERROR("Authentication failed, wrong user/password " "combination. Removing user failed."); return ADMIN_ERR_AUTHENTICATION; } /** Remove user from in-memory structure */ n_deleted = users_delete(users, uname); if (n_deleted == 0) { MXS_ERROR("Deleting the only user is forbidden. Add new " "user before deleting the one."); return ADMIN_ERR_DELLASTUSER; } /** * Open passwd file and remove user from the file. */ snprintf(fname, 1023, "%s/passwd", get_datadir()); snprintf(fname_tmp, 1023, "%s/passwd_tmp", get_datadir()); fname[1023] = '\0'; fname_tmp[1023] = '\0'; /** * Rewrite passwd file from memory. */ if ((fp = fopen(fname, "r")) == NULL) { int err = errno; MXS_ERROR("Unable to open password file %s : errno %d.\n" "Removing user from file failed; it must be done " "manually.", fname, err); return ADMIN_ERR_PWDFILEOPEN; } /** * Open temporary passwd file. */ if ((fp_tmp = fopen(fname_tmp, "w")) == NULL) { int err = errno; MXS_ERROR("Unable to open tmp file %s : errno %d.\n" "Removing user from passwd file failed; it must be done " "manually.", fname_tmp, err); fclose(fp); return ADMIN_ERR_TMPFILEOPEN; } /** * Scan passwd and copy all but matching lines to temp file. */ if (fgetpos(fp, &rpos) != 0) { int err = errno; MXS_ERROR("Unable to process passwd file %s : errno %d.\n" "Removing user from file failed, and must be done " "manually.", fname, err); fclose(fp); fclose(fp_tmp); unlink(fname_tmp); return ADMIN_ERR_PWDFILEACCESS; } while (fscanf(fp, "%[^:]:%s\n", fusr, fpwd) == 2) { /** * Compare username what was found from passwd file. * Unmatching lines are copied to tmp file. */ if (strncmp(uname, fusr, strlen(uname)+1) != 0) { if(fsetpos(fp, &rpos) != 0) { /** one step back */ MXS_ERROR("Unable to set stream position. "); } fgets(line, LINELEN, fp); fputs(line, fp_tmp); } if (fgetpos(fp, &rpos) != 0) { int err = errno; MXS_ERROR("Unable to process passwd file %s : " "errno %d.\n" "Removing user from file failed, and must be " "done manually.", fname, err); fclose(fp); fclose(fp_tmp); unlink(fname_tmp); return ADMIN_ERR_PWDFILEACCESS; } } fclose(fp); /** * Replace original passwd file with new. */ if (rename(fname_tmp, fname)) { int err = errno; MXS_ERROR("Unable to rename new passwd file %s : errno " "%d.\n" "Rename it to %s manually.", fname_tmp, err, fname); unlink(fname_tmp); fclose(fp_tmp); return ADMIN_ERR_PWDFILEACCESS; } fclose(fp_tmp); return ADMIN_SUCCESS; }
/** * This routine reads data from a binary file named ".secrets" and extracts the AES encryption key * and the AES Init Vector. * If the path parameter is not null the custom path is interpreted as a folder * containing the .secrets file. Otherwise the default location is used. * @return The keys structure or NULL on error */ static MAXKEYS * secrets_readKeys(char* path) { char secret_file[PATH_MAX+1]; char *home; MAXKEYS *keys; struct stat secret_stats; int fd; int len; static int reported = 0; if(path != NULL) snprintf(secret_file, PATH_MAX, "%s/.secrets", path); else snprintf(secret_file, PATH_MAX, "%s/.secrets", get_datadir()); /* Try to access secrets file */ if (access(secret_file, R_OK) == -1) { int eno = errno; errno = 0; if (eno == ENOENT) { if (!reported) { LOGIF(LM, (skygw_log_write( LOGFILE_MESSAGE, "Encrypted password file %s can't be accessed " "(%s). Password encryption is not used.", secret_file, strerror(eno)))); reported = 1; } } else { LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, "Error : access for secrets file " "[%s] failed. Error %d, %s.", secret_file, eno, strerror(eno)))); } return NULL; } /* open secret file */ if ((fd = open(secret_file, O_RDONLY)) < 0) { int eno = errno; errno = 0; LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, "Error : Failed opening secret " "file [%s]. Error %d, %s.", secret_file, eno, strerror(eno)))); return NULL; } /* accessing file details */ if (fstat(fd, &secret_stats) < 0) { int eno = errno; errno = 0; close(fd); LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, "Error : fstat for secret file %s " "failed. Error %d, %s.", secret_file, eno, strerror(eno)))); return NULL; } if (secret_stats.st_size != sizeof(MAXKEYS)) { int eno = errno; errno = 0; close(fd); LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, "Error : Secrets file %s has " "incorrect size. Error %d, %s.", secret_file, eno, strerror(eno)))); return NULL; } if (secret_stats.st_mode != (S_IRUSR|S_IFREG)) { close(fd); LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, "Error : Ignoring secrets file " "%s, invalid permissions.", secret_file))); return NULL; } if ((keys = (MAXKEYS *)malloc(sizeof(MAXKEYS))) == NULL) { close(fd); LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, "Error : Memory allocation failed " "for key structure."))); return NULL; } /** * Read all data from file. * MAXKEYS (secrets.h) is struct for key, _not_ length-related macro. */ len = read(fd, keys, sizeof(MAXKEYS)); if (len != sizeof(MAXKEYS)) { int eno = errno; errno = 0; close(fd); free(keys); LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, "Error : Read from secrets file " "%s failed. Read %d, expected %d bytes. Error %d, %s.", secret_file, len, sizeof(MAXKEYS), eno, strerror(eno)))); return NULL; } /* Close the file */ if (close(fd) < 0) { int eno = errno; errno = 0; free(keys); LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, "Error : Failed closing the " "secrets file %s. Error %d, %s.", secret_file, eno, strerror(eno)))); return NULL; } ss_dassert(keys != NULL); return keys; }
/** * dictopen() - open a dictionary * * This function is used to open a dictionary file or a word file, * or any associated data file (like a post process knowledge file). * * It works as follows. If the file name begins with a "/", then * it's assumed to be an absolute file name and it tries to open * that exact file. * * If the filename does not begin with a "/", then it uses the * dictpath mechanism to find the right file to open. This looks * for the file in a sequence of directories until it finds it. The * sequence of directories is specified in a dictpath string, in * which each directory is followed by a ":". */ FILE *dictopen(const char *filename, const char *how) { char completename[MAX_PATH_NAME+1]; char fulldictpath[MAX_PATH_NAME+1]; static char prevpath[MAX_PATH_NAME+1] = ""; static int first_time_ever = 1; char *pos, *oldpos; int filenamelen, len; FILE *fp; /* Record the first path ever used, so that we can recycle it */ if (first_time_ever) { strncpy (prevpath, filename, MAX_PATH_NAME); prevpath[MAX_PATH_NAME] = 0; pos = strrchr(prevpath, DIR_SEPARATOR); if (pos) *pos = 0; pos = strrchr(prevpath, DIR_SEPARATOR); if (pos) *(pos+1) = 0; first_time_ever = 0; } /* Look for absolute filename. * Unix: starts with leading slash. * Windows: starts with C:\ except that the drive letter may differ. */ if ((filename[0] == '/') || ((filename[1] == ':') && (filename[2] == '\\'))) { /* fopen returns NULL if the file does not exist. */ fp = fopen(filename, how); if (fp) return fp; } { char * data_dir = get_datadir(); if (data_dir) { snprintf(fulldictpath, MAX_PATH_NAME, "%s%c%s%c", data_dir, PATH_SEPARATOR, DEFAULTPATH, PATH_SEPARATOR); free(data_dir); } else { /* Always make sure that it ends with a path * separator char for the below while() loop. * For unix, this should look like: * /usr/share/link-grammar:.:data:..:../data: * For windows: * C:\SOMWHERE;.;data;..;..\data; */ snprintf(fulldictpath, MAX_PATH_NAME, "%s%c%s%c%s%c%s%c%s%c%s%c%s%c", prevpath, PATH_SEPARATOR, DEFAULTPATH, PATH_SEPARATOR, ".", PATH_SEPARATOR, "data", PATH_SEPARATOR, "..", PATH_SEPARATOR, "..", DIR_SEPARATOR, "data", PATH_SEPARATOR); } } /* Now fulldictpath is our dictpath, where each entry is * followed by a ":" including the last one */ filenamelen = strlen(filename); len = strlen(fulldictpath)+ filenamelen + 1 + 1; oldpos = fulldictpath; while ((pos = strchr(oldpos, PATH_SEPARATOR)) != NULL) { strncpy(completename, oldpos, (pos-oldpos)); *(completename+(pos-oldpos)) = DIR_SEPARATOR; strcpy(completename+(pos-oldpos)+1,filename); if ((fp = fopen(completename, how)) != NULL) { return fp; } oldpos = pos+1; } return NULL; }