aboutsummaryrefslogtreecommitdiffstats
path: root/modules/lookup_userhome.c
blob: 5fa25799b96e5adb9d9c096b513d3f1d98fa3b1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ident "$Id$"
/* ----------------------------------------------------------------------- *
 *   
 *  lookup_userhome.c - module for Linux automount to generate
 *			bind mounts to user home directories
 *
 *   Copyright 1999-2004 Transmeta Corporation - All Rights Reserved
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
 *   USA; either version 2 of the License, or (at your option) any later
 *   version; incorporated herein by reference.
 *
 * ----------------------------------------------------------------------- */

#include <stdio.h>
#include <malloc.h>
#include <errno.h>
#include <pwd.h>
#include <unistd.h>
#include <syslog.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>

#define MODULE_LOOKUP
#include "automount.h"

#define MODPREFIX "lookup(userhome): "

int lookup_version = AUTOFS_LOOKUP_VERSION; /* Required by protocol */

static struct mount_mod *mount_bind = NULL;

int lookup_init(const char *mapfmt, int argc, const char * const *argv,
		void **context)
{
  /* Make sure we have the local mount method available */
  if ( !mount_bind )
    mount_bind = open_mount("bind", MODPREFIX);
  
  return !mount_bind;
}

int lookup_mount(const char *root, const char *name,
		 int name_len, void *context)
{
  struct passwd *pw;

  syslog(LOG_DEBUG, MODPREFIX "looking up %s", name);

  /* Get the equivalent username */
  pw = getpwnam(name);
  if ( !pw ) {
    syslog(LOG_DEBUG, MODPREFIX "not found: %s", name);
    return 1;			/* Unknown user or error */
  }

  /* Create the appropriate bind mount */
  return mount_bind->mount_mount(root, name, name_len, pw->pw_dir, "bind",
				 NULL, mount_bind->context);
}

int lookup_done(void *context)
{
  return mount_bind->mount_done(mount_bind->context);
}