80 #include <sys/types.h>
84 #include <amxc/amxc_macros.h>
85 #include <amxc/amxc_string.h>
98 #define UPGR_STORAGE_DIR_OVERALL "/cfg/system/"
99 #define UPGR_STORAGE_DIR_COMPONENT UPGR_STORAGE_DIR_OVERALL "tr181-xpon/"
118 "Failed to allocate mem for s_upgr_storage_dir");
128 "Failed to allocate mem for s_upgr_storage_dir");
130 SAH_TRACEZ_WARNING(
ME,
"No folder for upgrade persistent settings");
131 SAH_TRACEZ_WARNING(
ME,
"Use folder for reboot persistent settings");
133 if(access(reboot_persistent, R_OK | W_OK | X_OK) != 0) {
134 SAH_TRACEZ_ERROR(
ME,
"No folder for any persistent settings");
139 "Failed to allocate mem for s_upgr_storage_dir");
161 amxc_string_t*
const file_path) {
164 amxc_string_appendf(file_path,
"%s", ani_object);
166 amxc_string_append(file_path,
"_password_hex.txt", 17);
168 amxc_string_append(file_path,
"_password_ascii.txt", 19);
186 const char*
const password,
190 when_null(ani_path, exit);
191 when_null(password, exit);
194 ani_path, password, hex);
196 amxc_string_t file_path_ascii;
197 amxc_string_t file_path_hex;
198 amxc_string_init(&file_path_ascii, 0);
199 amxc_string_init(&file_path_hex, 0);
204 const char*
const ascii_cstr = amxc_string_get(&file_path_ascii, 0);
205 const char*
const hex_cstr = amxc_string_get(&file_path_hex, 0);
207 if(strlen(password) == 0) {
211 write_file(hex ? hex_cstr : ascii_cstr, password);
212 unlink(hex ? ascii_cstr : hex_cstr);
215 amxc_string_clean(&file_path_ascii);
216 amxc_string_clean(&file_path_hex);
222 #define ASCII_PASSWORD_FILE_INDEX 0
223 #define HEX_PASSWORD_FILE_INDEX 1
243 char*
const password,
249 const char* password_file_used = NULL;
251 amxc_string_t file_path_ascii;
252 amxc_string_t file_path_hex;
253 amxc_string_init(&file_path_ascii, 0);
254 amxc_string_init(&file_path_hex, 0);
258 const char* files[2] = { 0 };
262 for(i = 0; i < 2; ++i) {
263 if(access(files[i], F_OK) == 0) {
266 SAH_TRACEZ_ERROR(
ME,
"Failed get password from %s", files[i]);
269 password_file_used = files[i];
276 if(password_file_used == NULL) {
283 if(strlen(password_saved) == 0) {
284 SAH_TRACEZ_ERROR(
ME,
"Password read from %s is empty",
290 password_saved) < 0) {
291 SAH_TRACEZ_ERROR(
ME,
"snprintf() to copy password failed");
299 amxc_string_clean(&file_path_ascii);
300 amxc_string_clean(&file_path_hex);
bool write_file(const char *const path, const char *const value)
bool read_first_line_from_file(const char *const path, char *line, size_t len)
#define MAX_PASSWORD_LEN_PLUS_ONE
const char * persistency_get_folder(void)
bool upgr_persistency_get_password(const char *const ani_path, char *const password, bool *hex)
#define HEX_PASSWORD_FILE_INDEX
static void create_password_file_path(const char *const ani_object, bool hex, amxc_string_t *const file_path)
#define UPGR_STORAGE_DIR_OVERALL
static char * s_upgr_storage_dir
#define UPGR_STORAGE_DIR_COMPONENT
#define ASCII_PASSWORD_FILE_INDEX
void upgr_persistency_cleanup(void)
void upgr_persistency_init(void)
void upgr_persistency_set_password(const char *const ani_path, const char *const password, bool hex)
#define SAH_TRACEZ_DEBUG(zone, format,...)