Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve password logic for newly detected files (fix #14) #21

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,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 @@ -432,16 +435,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');
HeavenVolkoff marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -466,7 +482,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
HeavenVolkoff marked this conversation as resolved.
Show resolved Hide resolved
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