IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Réseau Discussion :

Permission denied avec l'utilisation du script avec sendmail


Sujet :

Réseau

  1. #1
    Modérateur
    Avatar de ggnore
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    2 472
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 472
    Points : 4 029
    Points
    4 029
    Par défaut Permission denied avec l'utilisation du script avec sendmail
    bonjour.
    Lorsque je lance ce script en étant root, pas de problème ça s'éxécute sans problème.

    Mais dés que je suis un utilisateur lambda, il me dit que permission denied

    j'ai fait un gros chmod 777 dessus, mais rien n'y fait.
    J'utilise postfix.
    Si quelqu'un pouvait le tester chez lui, pour voir si la même erreur arrive, ça serait sympa.
    Sinon si quelqu'un a la patience de le comprendre et trouve la raison du permission denied, c'est encore mieux

    merci d'avance

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    #!/bin/sh
    #exemple de commande
    #./send-mail.sh -f expediteur@ailleurs.com -t destinataire@quelquepart.fr -s "sujet du mail" -n fichierjoint < texte
     
    # -f adresse de l'expediteur ( si non indiqué, sera l'adresse de l'utilisateur connecté)
    # -t adresse du destinataire
    # -c adresse des destinataires en copie (facultatif)
    # -s sujet ou objet (titre)
    # -n liste de fichiers (il existe aussi l'option -u et -b encodage base 64...)
    # < un fichier qui existe (qui contient le corps du message) (facultatif)
    #
     
     
    # script to email files as attachments.
    # ------------------------------------
     
    # Additional documentation for this script, including a brief introdcution
    # to MIME can be found at: http://home.clara.net/dwotton/unix/mail_files.htm
     
    # Written: Dave Wotton, July 1998, (Cambridge UK)
    # This script comes with no warranty or support. You are
    # free to modify it as you wish, but please retain an
    # acknowledgement of my original authorship.
     
    # Usage: mail_files [-t] mailid [ -c mailid ] [ -s subject ] [ -f mailid ]
    # [-n file_list] [-u file_list] [-b file_list] file_list
    #
    # -f : The mailid of the sender ( defaults to your userid )
    # Only userids that have been defined as "trusted" in the sendmail
    # config file can make use of the -f option. For non-trusted users
    # any value specified by this parameter will be ignored by
    # sendmail.
    # -t : The mailid of the recipient. Mandatory, no default
    # multiple mailids can be specified, separated by commas.
    # -c : The mailid of any carbon-copy recipients. Optional.
    # multiple mailids can be specified, separated by commas.
    # -s : The subject string. Optional, default = "Not specified".
    # Enclose in quotes.
    # -n : no-encode: indicates a list of files which are NOT to be base64
    # or uuencode encoded. Multiple files may be enclosed in double
    # quotes. Usual wildcard notation can be used. This option is
    # for completeness and can be omitted because the default action
    # is not to encode the file-list.
    # -b : base64 encoding: indicates a list of files which are to be
    # base64 encoded. Multiple files may be enclosed in double quotes.
    # Usual wildcard notation can be used.
    # -u : uuencode encoding: indicates a list of files which are to be
    # uuencode encoded. Multiple files may be enclosed in double
    # quotes. Usual wildcard notation can be used.
    # file_list : The list of files to send as attachments with no-encoding
    # (same as -n option, but the file list does not need to be
    # enclosed in quotes if more than one file specified).
    # Usual wildcard notation can be used.
     
    # The program will also prompt for text to be supplied on standard input
    # as the main text of the message.
     
    # eg.
    # 1) mail_files Dave.Wotton -b file9.gif t*.htm < /dev/null
    #
    # email file9.gif as a base64 encoded attachment and the t*.htm
    # files unencoded.
    #
    # 2) mail_files Dave.Wotton -s "my test" -b "file1.gif file2.gif" \
    # < /dev/null
    #
    # email file1.gif and file2.gif as base64 encoded attachments.
     
    # The script makes use of perl's MIME package to perform the base-64
    # encoding/decoding.
     
    # Note that files destined for Windows environments should have a name of
    # the form aaaa.bbb where aaaa is up to 8 characters long, and bbb is a
    # 3 character sufix. The suffix determines which program is used to
    # display/process the data at the remote end.
     
    # Simple text files can be emailed unencoded. Binary files, or text files
    # with long lines ( ie > 1000 chars ) should use the base64 or uuencode
    # encoding procedures. Base64 is preferred because it is more universally
    # supported. In particular, most PC mail-clients can automatically decode
    # base64 encoded attachments. Note that simple text files with short lines
    # which are destined for PC environments should not be base64 encoded.
    # This is because PCs use a different line-break character to Unix.
    # If the text is base64 encoded, the line-breaks are not converted
    # automatically and so the data arrives at the remote end without
    # line-breaks.
     
    # set up a 'usage' routine
    # ------------------------
     
    usage()
    {
    [ "$1" ] && ( echo $* ; echo "" )
     
    cat <<!
    Usage: mail_files [-t] mailid [ -c mailid ] [ -s subject ] [ -f mailid ]
    [-n file_list] [-u file_list] [-b file_list] file_list
    !
    exit 4
    }
     
    # Initialise main variables ...
    # -------------------------
     
    FROM=$LOGNAME
    SUBJ=${SUBJ:-"Not specified"}
     
    TO="" ; CC="" ; SUBJ="" ; NOENC="" ; BASE64="" ; UUE=""
     
    # First parse the command line options. Using getopts means the parameters
    # can be supplied in any order. But first we handle the first parameter,
    # which may be a recipient, without a -t flag...
     
    case "$1" in
    -* ) : ;; # ignore it, let getopts handle flags
    * ) TO=$1 ; shift ;;
    esac
     
    while getopts f:s:t:c:n:b:u: OPT
    do
    case $OPT in
    "f" ) FROM=$OPTARG ;;
    "t" ) TO="$TO,$OPTARG" ;;
    "c" ) CC="$CC,$OPTARG" ;;
    "s" ) SUBJ=$OPTARG ;;
    "n" ) NOENC="$NOENC $OPTARG" ;;
    "b" ) BASE64="$BASE64 $OPTARG" ;;
    "u" ) UUE="$UUE $OPTARG" ;;
    * ) usage ;;
    esac
    done
     
    shift `expr $OPTIND - 1`
     
    if [ "$TO" = "" ]
    then
    usage "An addressee must be specified"
    fi
     
    # All remaining parameters are files not requiring encoding ...
    # ---------------------------------------------------------
     
    # Build up $FILES as the list of non-encoded files. Use sed to remove
    # any leading space from the variable.
     
    FILES=`echo $NOENC $*|sed 's/^ //'`
     
    if [ "$BASE64" = "" -a "$FILES" = "" -a "$UUE" = "" ]
    then
    usage "At least one file must be specified"
    fi
     
    # Remove leading commas from TO, CC ...
    # ---------------------------------
     
    TO=`echo $TO | sed 's/^,//'`
    CC=`echo $CC | sed 's/^,//'`
     
    # Validate that the files exist ...
    # -----------------------------
     
    for F in $FILES $BASE64 $UUE
    do
    if [ ! -r $F ]
    then
    echo "Error: File $F does not exist / is not readable."
    echo "Exiting. ( Mail not sent )."
    exit
    fi
    done
     
    tty -s && echo "Enter text of main message ( finish with CTRL-D ) ..."
     
    # Now do the work ...
    # ---------------
     
    # The generated mail message is output onto standard out, which is then
    # piped in to sendmail.
     
    (
    cat <<!
    From: $FROM
    Subject: $SUBJ
    To: $TO
    !
     
    [ "$CC" ] && echo "Cc: $CC"
     
    cat <<!
    Mime-Version: 1.0
    Content-Type: multipart/mixed; boundary="DMW.Boundary.605592468"
     
    This is a Mime message, which your mail program may not understand. Parts
    of the message will appear as text. If the remainder appears as random
    characters in the message body, instead of as attachments, then you'll
    have to extract these parts and decode them manually.
     
    --DMW.Boundary.605592468
    Content-Type: text/plain; name="message.txt"; charset=US-ASCII
    Content-Disposition: inline; filename="message.txt"
    Content-Transfer-Encoding: 7bit
     
    !
     
    # Read the standard input as the main text of the message ...
    # -------------------------------------------------------
     
    cat -
     
    # Now process the non-encrypted attachments ...
    # -----------------------------------------
     
    if [ "$FILES" ]
    then
    for F in $FILES
    do
     
    BASE=`basename $F`
     
    echo --DMW.Boundary.605592468
    echo Content-Type: application/octet-stream\; name=\"$BASE\"
    echo Content-Disposition: attachment\; filename=\"$BASE\"
    echo Content-Transfer-Encoding: 7bit
    echo
     
    cat $F
     
    done
    fi
     
    # Now process the base64 encrypted attachments ...
    # --------------------------------------------
     
    if [ "$BASE64" ]
    then
    for F in $BASE64
    do
     
    BASE=`basename $F`
     
    echo --DMW.Boundary.605592468
    echo Content-Type: application/octet-stream\; name=\"$BASE\"
    echo Content-Disposition: attachment\; filename=\"$BASE\"
    echo Content-Transfer-Encoding: base64
    echo
     
    perl -e '
    use MIME::Base64 qw(encode_base64);
    local($/) = undef;
    print encode_base64(<STDIN>);' < $F
     
    done
    fi
     
    # Now process the uuencode encrypted attachments ...
    # ----------------------------------------------
     
    # Sorry, this bit is untested - I haven't got a mail-client which can
    # handle uuencoded MIME messages automatically, so can't test if the
    # 'Content-Transfer-Encoding: uuencode' line is correct and whether I
    # need the uuencode "begin" and "end" lines.
     
    if [ "$UUE" ]
    then
    for F in $UUE
    do
     
    BASE=`basename $F`
     
    echo --DMW.Boundary.605592468
    echo Content-Type: application/octet-stream\; name=\"$BASE\"
    echo Content-Disposition: attachment\; filename=\"$BASE\"
    echo Content-Transfer-Encoding: uuencode
    echo
     
    uuencode < $F xxx
     
    done
    fi
     
    # append the final boundary line ...
     
    echo --DMW.Boundary.605592468--
     
    ) | /usr/sbin/sendmail -t
    Toutes les vertus des hommes se perdent dans l’intérêt comme les fleuves se perdent dans la mer.
    N'oubliez pas de consulter les FAQ Linux et les cours et tutoriels Linux

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Août 2004
    Messages
    48
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2004
    Messages : 48
    Points : 59
    Points
    59
    Par défaut
    Salut,

    Si je ne me trompe, /usr/sbin contient des programme destinés à root. Donc, lambda n'a pas les droits d'exécution dessus. Comme la dernière ligne du script y fait référence, je suppose que c'est elle qui provoque ton problème.

    Soit tu donne le setUid root au script (pas bien) soit tu configure sudo pour permettre à lambda d'utiliser sendmail.

    Pet-être que je me trompe, essaies et on verra plus claire.

    PS: enlever qqs lignes de commentaire au script n'aurait pas été superflu.

  3. #3
    Modérateur
    Avatar de ggnore
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    2 472
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 472
    Points : 4 029
    Points
    4 029
    Par défaut
    pourtant en étant une utilisateur lambda, j'arrive à lancer sendmail
    la redirection implique t elle qu'on doive avoir les droits d'écriture su sendmail ? m'étonnerait quand même.
    Toutes les vertus des hommes se perdent dans l’intérêt comme les fleuves se perdent dans la mer.
    N'oubliez pas de consulter les FAQ Linux et les cours et tutoriels Linux

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2004
    Messages : 23
    Points : 26
    Points
    26
    Par défaut
    Le fait est que /usr/sbin est inaccessible pour l'utilisateur non root... maintenant il se peut que sendmail soit aussi présent dans /usr/bin, ce qui expliquerait que tu puisses l'utiliser. mais dans tous les cas, le fichier auquel tu fais référence est interdit aux utilisateurs... cherche un autre emplacement de sendmail, il doit forcément exister si un utilisateur peut l'utiliser...

  5. #5
    Modérateur
    Avatar de ggnore
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    2 472
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 472
    Points : 4 029
    Points
    4 029
    Par défaut
    bizarre...
    En étant un utilisateur, je peux lancer ce qui est dans /usr/sbin ...

    bref le problème venait du fait que le script était éxecutable par n'importe qui, mais n'était pas readable.
    Or un script, ça a besoin d'être interprété à la différence d'un programme compilé en C.

    Merci pour votre aide.
    Toutes les vertus des hommes se perdent dans l’intérêt comme les fleuves se perdent dans la mer.
    N'oubliez pas de consulter les FAQ Linux et les cours et tutoriels Linux

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Utiliser le script "Sitemap Generator" avec Rails
    Par Flackou dans le forum Ruby on Rails
    Réponses: 0
    Dernier message: 03/10/2008, 15h06
  2. [Lua] utiliser 1 script avec 2 application
    Par Clercq dans le forum Développement 2D, 3D et Jeux
    Réponses: 2
    Dernier message: 26/03/2008, 14h33
  3. Réponses: 0
    Dernier message: 30/11/2007, 15h29
  4. Réponses: 7
    Dernier message: 22/12/2006, 11h24
  5. Problème avec Rename : Permission denied
    Par panaone dans le forum Langage
    Réponses: 12
    Dernier message: 21/08/2005, 17h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo