Почему openssl создает разные хэши для одной и той же строки и как linux принимает разные хэши при переключении пользователей?

Просто небольшой тест с моей стороны, я надеюсь, что комментарии объяснят, что я сделал. Я предполагаю Баш.

По сути, поиск в Google «bash read csv file» помог мне. Остальное на самом деле просто некоторая логика if else и основные команды.

#!/usr/bin/env bash

OLDIFS=$IFS  # store old delimiter for csv files
IFS=" | "    # set delimiter of csv file

# attempt to get the filename of the only csv file in the current folder
# doesn't work if there are multiple csv files -> look into fuzzy finder or demenu for example
# doesn't work if csv file doesn't exist in current directory
# of course you can read the filename from command line with read command
# ls | grep *.csv might be useful to get all names of csv files in current directory
filename=$(ls | grep *.csv)  # store output of command pipe in filename
echo "$filename"  # debug, to see what is stored in $filename

while read f1 f2 f3  # read csv file, each line, 3 fields per line
do
    # debug, echo each field
    echo "field 1 is: $f1"
    echo "field 2 is: $f2"
    echo "field 3 is: $f3"

    echo ""
    echo "does $f2 exist?"
    [ -d $f2 ] && echo "yes" || echo "no"  # really just a short if else, in case you don't know this one

    if [ ! -d $f2 ]; then  # if directory in second column of csv doesn't exist
        echo "creating directory"
        mkdir -p $f2  # -p creates necessary parent directories if they don't exist
    fi

    echo "copying $f3 to $f2/$f3"
    cp $f3 $f2/$f3  # copying doesn' force you to move files for testing, replace with move

done < $filename

# script never reaches this point if anything before fails
# if you want to use this script more often you should think about a way to reliably reset $IFS
IFS=$OLDIFS  # reset delimiter

Мой CSV-файл:

whatever number | /existing_path/nonexisting_path/move_stuff_here | testfile.txt

testfile.txt должен существовать в вашем текущем рабочем каталоге, чтобы это работало.

Несуществующий _путь просто показывает mkdir -p.

1
21.11.2021, 00:42
1 ответ
  • Первые два символа в хеше — это соль. openssl passwdдолжна иметь соль, и она всегда будет длиной 2 символа, ни больше, ни меньше.

  • Таким образом, в случае YY9E0oGqqamCMи csL9dpD2Iy3H2, YYи csявляются соответствующими солями.

    $ openssl passwd -salt YY testing
    YY9E0oGqqamCM
    $ openssl passwd -salt cs testing
    csL9dpD2Iy3H2
    
0
21.11.2021, 03:02

Теги

Похожие вопросы