diff options
Diffstat (limited to 'src/generators.c')
| -rw-r--r-- | src/generators.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/generators.c b/src/generators.c index d5f1837..ac641d4 100644 --- a/src/generators.c +++ b/src/generators.c @@ -33,6 +33,7 @@ #include "replace-table.h" #include "block-parser.h" #include "stats.h" +#include "generators.h" #define IS_NOFULLSIZE(item,parent_items,setup) \ @@ -959,3 +960,78 @@ write_html_image (TGallerySetup *setup, return res; } + +/* + * write_auth_passwd_file, write_auth_htaccess_file: setup authentication files for the current album + * + */ +gboolean +write_auth_passwd_file (TGallerySetup *setup, + const gchar *dst, + TAlbum *items) +{ + GError *error = NULL; + const gchar *argv[8]; + + argv[0] = "htpasswd"; + argv[1] = "-b"; + argv[2] = "-c"; + argv[3] = "-m"; + argv[4] = dst; + argv[5] = items->auth_username; + argv[6] = items->auth_passwd; + argv[7] = NULL; + + if (! g_spawn_sync (NULL, + (gchar **) argv, + NULL, + G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, + NULL, NULL, + NULL, NULL, + NULL, + &error)) + { + log_error ("Error writing password file: %s\n", error->message); + g_error_free (error); + return FALSE; + } + + return TRUE; +} + +gboolean +write_auth_htaccess_file (TGallerySetup *setup, + const gchar *dst, + const gchar *passwd_file_name, + TAlbum *items) +{ + FILE* f; + + f = fopen (dst, "a"); + if (f == NULL) { + log_error ("Error writing htaccess file: %s\n", strerror (errno)); + return FALSE; + } + + fprintf (f, "\n"); + fprintf (f, "# CGG auth data\n"); + switch (items->auth_type) { + case AUTH_TYPE_NONE: + g_assert_not_reached(); + break; + case AUTH_TYPE_BASIC: + fprintf (f, "AuthType Basic\n"); + fprintf (f, "AuthName \"%s\"\n", items->auth_realm); + fprintf (f, "AuthBasicProvider file\n"); + fprintf (f, "AuthUserFile %s\n", passwd_file_name); + fprintf (f, "Require user %s\n", items->auth_username); + break; + } + + if (fclose (f) != 0) { + log_error ("Error writing htaccess file: %s\n", strerror (errno)); + return FALSE; + } + + return TRUE; +} |
