-1

I'm having a problem when trying to import a user list into Zentyal 3.4.

The script I'm using is this:

#!/usr/bin/perl

use strict;
use warnings;

use EBox;
use EBox::Users::User;

EBox::init();

my $usersMod = EBox::Global->getInstance()->modInstance('users');
my $parent = $usersMod->objectFromDN('ou=Promo 2022,ou=Alumnos,'.$usersMod->ldap->dn());

my $file = 'users.csv';
open (my $USERS, $file) or die "Can't open '$file': $!";

while (my $line = <$USERS>) {
    chomp ($line);
    my ($username, $givenname, $surname, $password) = split(';', $line);
    EBox::Users::User->create(
    uid => $username,
    parent => $parent,
    givenname => $givenname,
    surname => $surname,
    password => $password,
    );
}

close ($USERS);

1;

It worked perfectly the first time I used it but now it gives a "Permission denied" error when it tries to open the file.

Both the file intended to open and the script have 0777 permissions so any user should be able to do whatever the please with them.

The script needs to be run as sudo (which I did).

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
angardi
  • 367
  • 3
  • 14
  • What happens if you do a `head users.csv`? Maybe you need to set the full path? Also, `0777` are horrible & should never be used for a file that is only going to be read. It should be `0644` and should work. Esepcially if you are using `sudo`. 100% no reason to ever set `0777` for any reason. Perhaps the `permission denied` is connected to the script itself or perhaps `/usr/bin/perl`? – Giacomo1968 Jun 13 '14 at 02:46
  • Is it saying `Can't open 'users.csv': Permission denied"`? – Barmar Jun 13 '14 at 02:47
  • If the script is run with `sudo`, permissions should be ignored. – Barmar Jun 13 '14 at 02:48
  • @Barmar I know permissions are ignored when running as sudo, just mentioned it to avoid people saying "You should run the script as sudo". And yes, that is exactly the output I'm getting. – angardi Jun 13 '14 at 02:59
  • @JakeGould I know 0777 is horrible but I've tried everything with no success. If I don't have permissions to run perl, I shouldn't even be able to run the script, right? Besides, the script worked just fine the first time I used it, which was only yesterday. – angardi Jun 13 '14 at 03:05
  • Is the `users.csv` readable? Perhaps you should set the full path to `users.csv` like `/home/angardi/users.csv`. – Giacomo1968 Jun 13 '14 at 03:07
  • @JakeGould 'users.csv' is readable. `head users.csv` gives me a few lines of the csv file. I've tried with the full path but got the same result. – angardi Jun 13 '14 at 03:14
  • Just to be clear, are you still getting this error if the script is run with `sudo`? – Borodin Jun 13 '14 at 10:04
  • @Borodin yes, I still get the error when using `sudo`. Also, the script cannot be run without `sudo` because it won't be able to use EBox – angardi Jun 13 '14 at 12:11
  • Solved it. The problem was that although I could read the files, the folder `/home/angardi` was set to `0700`, so perl couldn't read the file. Thanks to everyone for your help – angardi Jun 13 '14 at 13:14
  • @angardi: Please submit your solution as an answer and accept it so that others can see that your question has been resolved – Borodin Jun 13 '14 at 16:40

1 Answers1

1

Solved it by the OP in the comments.

The relevant files had permissions 0777. However, the containing folder /home/angardi was set to 0700.

Therefore, although I could read the files, perl didn't have permissions to read.

Miller
  • 34,962
  • 4
  • 39
  • 60