diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2012-12-31 20:08:30 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2012-12-31 20:08:30 +0100 |
| commit | 95b85be502f639fb2080ae92d4d33c013b18aa94 (patch) | |
| tree | 7ca15af789198da9021937269eda023946b69221 /src/generators.c | |
| parent | 571790ba31a48c108e42c4ae10f8e63ae734c376 (diff) | |
| download | cataract-95b85be502f639fb2080ae92d4d33c013b18aa94.tar.xz | |
Add support for password protected albums
This adds support for simple password protected areas (albums and
all subalbums) through webserver HTTP authentication. CGG simply
generates .htaccess and password files and it's up to the user to
set up the rest on server side.
No UI changes at this point. Limited to one user per album for
the moment.
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; +} |
