Re: mount windows shares at login


Subject: Re: mount windows shares at login
From: Arthur Corliss (arthur@corlissfamily.org)
Date: Thu Mar 06 2003 - 14:09:58 AKST


On Thu, 6 Mar 2003, Tim Jordan, DOL&WD Network Services wrote:

> I've tried putting together a script (my first) to map the windows
> share. I know that I have to use root rights in order to mount the M$
> share. So I tried this:
>
> #! /bin/bash
> su root
> %rootpassword%
> mount -t smbfs -o username=tim,password=******* //%server%/home
> /home/tim/AD1
> cd /home/tim/AD1
> chmod a+rwx
>
> It does not work as the root password prompt appears when I run the script.
> * How do I pass the root password w/the su command?
> *What directory would I put this script in once it works?.....a startup
> directory?

First off: remember that shell scripts execute line by line, and they don't
continue until the command from the previous line exits. So your su line
spawns a shell and the script does nothing else until you exit that shell.

Second: you'd be better off with a setuid wrapper instead of a shell script
-- do you really want your *root* password in a *text* file on that box?! At
least with a setuid wrapper you'd only risk exposing your Windows password,
but if you make it only group readable by a group only *you* belong to, that's
marginally better.

Here's an example of a C program that I use to do exactly this at work (with
the logon/host specifics munged for security). Keep in mind that using the
other options for mounting (uid/gid) you don't have to make it world rw like
you are above. Always do things as securely as possible:

// winmount.c -- Setuid wrapper for mounting my Windows home directory on the
// the server
//
// $Id: winmount.c,v 0.2 2003/03/06 23:34:01 acorliss Exp acorliss $
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>

#define USAGE "Usage: winmount [-m] [-u]\n\t-m\tMount SMB share\n\t-u\tUnmount SMB share \n"
#define F1 "-m"
#define F2 "-u"

int main(int argc, char * argv[]) {

  setreuid (geteuid (), getuid ());

  // Make sure we have an argument and it's a legitimate option
  if (argc != 2 || (strcmp(argv[1], F1) != 0 && strcmp(argv[1], F2) != 0)) {
    printf(USAGE);
    return 1;
  }

  if (strcmp(argv[1], F1) == 0) {
    execl("/bin/mount", "mount", "-t", "smbfs",
      "-o", "username=foo,password=bar,uid=10892,gid=100",
      "//homeserver/foo$", "/mnt", 0);
  } else if (strcmp(argv[1], F2) == 0) {
    execl("/bin/umount", "umount", "/mnt", 0);
  }
}

        --Arthur Corliss
          Bolverk's Lair -- http://arthur.corlissfamily.org/
          Digital Mages -- http://www.digitalmages.com/
          "Live Free or Die, the Only Way to Live" -- NH State Motto

---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.



This archive was generated by hypermail 2a23 : Thu Mar 06 2003 - 14:37:07 AKST