← Back to team overview

ecryptfs-devel team mailing list archive

Re: [PATCH 2/2] pam_ecryptfs: New helper function: file_exists_dotecryptfs()

 

On Sun, Nov 7, 2010 at 4:29 PM, Jakob Unterwurzacher <jakobunt@xxxxxxxxx> wrote:
> Eliminates both ecryptfs_pam_wrapping_independent_set()
> and ecryptfs_pam_automount_set().

Beautiful!  Thanks for the patches.  Applied this one too.

Committed revision 525.  Will be in the -86 release.

:-Dustin

> ---
>  src/pam_ecryptfs/pam_ecryptfs.c |   29 +++++------------------------
>  1 files changed, 5 insertions(+), 24 deletions(-)
>
> diff --git a/src/pam_ecryptfs/pam_ecryptfs.c b/src/pam_ecryptfs/pam_ecryptfs.c
> index 2a821e8..2d64587 100644
> --- a/src/pam_ecryptfs/pam_ecryptfs.c
> +++ b/src/pam_ecryptfs/pam_ecryptfs.c
> @@ -68,32 +68,13 @@ static void error(const char *msg)
>        }
>  }
>
> -/* returns: 0 for pam automounting not set, 1 for set, <0 for error */
> -static int ecryptfs_pam_automount_set(const char *homedir)
> +/* returns: 0 if file does not exist, 1 if it exists, <0 for error */
> +static int file_exists_dotecryptfs(const char *homedir, char *filename)
>  {
>        char *file_path;
>        int rc = 0;
>        struct stat s;
> -       if (asprintf(&file_path, "%s/.ecryptfs/auto-mount", homedir) == -1)
> -               return -ENOMEM;
> -       if (stat(file_path, &s) != 0) {
> -               if (errno != ENOENT)
> -                       rc = -errno;
> -               goto out;
> -       }
> -       rc = 1;
> -out:
> -       free(file_path);
> -       return rc;
> -}
> -
> -/* returns: 0 for independent wrapping passphrase not set, 1 for set, <0 for error */
> -static int ecryptfs_pam_wrapping_independent_set(const char *homedir)
> -{
> -       char *file_path;
> -       int rc = 0;
> -       struct stat s;
> -       if (asprintf(&file_path, "%s/.ecryptfs/wrapping-independent", homedir) == -1)
> +       if (asprintf(&file_path, "%s/.ecryptfs/%s", homedir, filename) == -1)
>                return -ENOMEM;
>        if (stat(file_path, &s) != 0) {
>                if (errno != ENOENT)
> @@ -168,7 +149,7 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
>                       "rc = [%ld]\n", username, rc);
>                goto out;
>        }
> -       if (!ecryptfs_pam_automount_set(homedir))
> +       if (!file_exists_dotecryptfs(homedir, "auto-mount"))
>                goto out;
>        private_mnt = ecryptfs_fetch_private_mnt(homedir);
>        if (ecryptfs_private_is_mounted(NULL, private_mnt, NULL, 1)) {
> @@ -184,7 +165,7 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
>                syslog(LOG_WARNING, "Can't check if kernel supports ecryptfs\n");
>        saved_uid = geteuid();
>        seteuid(uid);
> -       if(ecryptfs_pam_wrapping_independent_set(homedir) == 1)
> +       if(file_exists_dotecryptfs(homedir, "wrapping-independent") == 1)
>                rc = pam_prompt(pamh, PAM_PROMPT_ECHO_OFF, &passphrase, "Encryption passphrase: ");
>        else
>                rc = pam_get_item(pamh, PAM_AUTHTOK, (const void **)&passphrase);
> --
> 1.7.0.4
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~ecryptfs-devel
> Post to     : ecryptfs-devel@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~ecryptfs-devel
> More help   : https://help.launchpad.net/ListHelp
>



-- 
:-Dustin

Dustin Kirkland
Ubuntu Core Developer



References