Skip to content

Commit

Permalink
Merge pull request #21 from HeavenVolkoff/master
Browse files Browse the repository at this point in the history
Improve password logic for newly detected files (fix #14)
  • Loading branch information
NathanaelA authored Aug 19, 2021
2 parents cc2127a + f03530d commit bab5d6f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
24 changes: 20 additions & 4 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,10 @@ monitor_insert_file(const char *name, const char *path)
char *id = NULL;
char video[PATH_MAX];
const char *tbl = "DETAILS";
char * password = NULL;
char * dir_password = NULL;
char password_buf[11];
char file_password[11] = {0};
char password_path[PATH_MAX];
int depth = 1;
int ts;
media_types dir_types;
Expand Down Expand Up @@ -433,16 +436,29 @@ monitor_insert_file(const char *name, const char *path)
//DEBUG DPRINTF(E_DEBUG, L_INOTIFY, "Checking %s\n", parent_buf);
id = sql_get_text_field(db, "SELECT OBJECT_ID from OBJECTS o left join DETAILS d on (d.ID = o.DETAIL_ID)"
" where d.PATH = '%q' and REF_ID is NULL", parent_buf);

snprintf(password_path, PATH_MAX, "%s/.password", parent_buf);
if( access(password_path, 0) == 0 )
{
readPassword(password_path, password_buf, 11);
dir_password = password_buf;
}
else if( id )
dir_password = sql_get_text_field(db, "select PASSWORD from OBJECTS where OBJECT_ID='%s'", id);

// Save first directory password seen as file password
if (dir_password != NULL && file_password[0] == '\0');
strcpy(file_password, dir_password);

if( id )
{
if( !depth )
break;
password = sql_get_text_field(db, "select PASSWORD from OBJECTS where OBJECT_ID='%s'", id);
DPRINTF(E_DEBUG, L_INOTIFY, "Found first known parentID: %s [%s]\n", id, parent_buf);
/* Insert newly-found directory */
strcpy(base_name, last_dir);
base_copy = basename(base_name);
insert_directory(base_copy, last_dir, BROWSEDIR_ID, id+2, get_next_available_id("OBJECTS", id), password);
insert_directory(base_copy, last_dir, BROWSEDIR_ID, id+2, get_next_available_id("OBJECTS", id), dir_password);
sqlite3_free(id);
break;
}
Expand All @@ -467,7 +483,7 @@ monitor_insert_file(const char *name, const char *path)
if( !depth )
{
//DEBUG DPRINTF(E_DEBUG, L_INOTIFY, "Inserting %s\n", name);
int ret = insert_file(name, path, id+2, get_next_available_id("OBJECTS", id), dir_types, password);
int ret = insert_file(name, path, id+2, get_next_available_id("OBJECTS", id), dir_types, file_password[0] == '\0' ? NULL : file_password);
if (ret == 1 && (mtype & TYPE_PLAYLIST))
{
next_pl_fill = time(NULL) + 120; // Schedule a playlist scan for 2 minutes from now.
Expand Down
2 changes: 1 addition & 1 deletion scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ filter_avp(scan_filter *d)
);
}

static void
void
readPassword(const char *dir, char *password, int size)
{
FILE *pFile = NULL;
Expand Down
3 changes: 3 additions & 0 deletions scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ insert_file(const char *name, const char *path, const char *parentID, int object
int
CreateDatabase(void);

void
readPassword(const char *dir, char *password, int size);

void
start_scanner();

Expand Down

0 comments on commit bab5d6f

Please sign in to comment.