【发布时间】:2016-05-19 03:39:34
【问题描述】:
我正在使用 Perl 将字符串 ($password) 传递给系统行以进行解释。不过,它似乎没有被正确解释,因为当我附加 Sparse Bundle 时,它说身份验证失败。请注意,管道之后的一切都可以正常工作。
$password = chomp($password);
### Create the bash system call to create the sparse bundle with the password
my $cmd = `echo $password | hdiutil create -size 200g -type SPARSEBUNDLE -encryption -stdinpass -volname \"Encrypted Storage for Matt\" -fs \"Case-sensitive Journaled HFS+\" -verbose ~/Desktop/SparseBundle`;
一些示例输出:
SLC1087-Matt:backups matt$ ./create_sparsebundle.pl
DIDiskImageCreatorProbe: interface 1, score 1000, CSparseBundleDiskImage
DIDiskImageCreatorProbe: interface 2, score -1000, CSparseDiskImage
DIDiskImageCreatorProbe: interface 3, score -1000, CRawDiskImage
DIDiskImageCreatorProbe: interface 7, score -1000, CWOUDIFDiskImage
DIDiskImageCreatorProbe: interface 9, score -1000, CCFPlugInDiskImage
DIDiskImageCreateWithCFURL: CSparseBundleDiskImage
CBSDBackingStore::createProbe directory, not a valid image file.
DIBackingStoreCreatorProbe: interface 0, score -1000, CBSDBackingStore
DIBackingStoreCreatorProbe: interface 1, score 1000, CBundleBackingStore
DIBackingStoreCreatorProbe: interface 2, score 0, CRAMBackingStore
DIBackingStoreCreatorProbe: interface 3, score 100, CCarbonBackingStore
DIBackingStoreCreatorProbe: interface 5, score -100, CCURLBackingStore
DIBackingStoreCreateWithCFURL: CBundleBackingStore
DIFileEncodingCreatorProbe: interface 2, score 1000, CEncryptedEncoding
DIFileEncodingCreateWithCFURL: CEncryptedEncoding
DIFileEncodingCreatorProbe: interface 2, score -1000, CEncryptedEncoding
DIBackingStoreCreatorProbe: interface 0, score 100, CBSDBackingStore
DIBackingStoreCreatorProbe: interface 1, score -1000, CBundleBackingStore
DIBackingStoreCreatorProbe: interface 2, score 0, CRAMBackingStore
DIBackingStoreCreatorProbe: interface 3, score 100, CCarbonBackingStore
DIBackingStoreCreatorProbe: interface 5, score -100, CCURLBackingStore
DIBackingStoreCreateWithCFURL: CBSDBackingStore
DIBackingStoreCreateWithCFURL: creator returned 0
DIFileEncodingCreateWithCFURL: creator returned 0
DIBackingStoreCreateWithCFURL: creator returned 0
DIDiskImageCreateWithCFURL: creator returned 0
DI_kextWaitQuiet: about to call IOServiceWaitQuiet...
DI_kextWaitQuiet: IOServiceWaitQuiet took 0.000003 seconds
2016-05-18 20:59:09.627 diskimages-helper[68122:1796245] *** -[NSMachPort handlePortMessage:]: dropping incoming DO message because the connection is invalid
hdiutil: create: returning 0
SLC1087-Matt:backups matt$ hdiutil attach ~/Desktop/SparseBundle.sparsebundle
Enter password to access "SparseBundle.sparsebundle":
hdiutil: attach failed - Authentication error
似乎一切正常,但密码显然错误。
【问题讨论】:
-
只打印密码会发生什么?
system("echo $password")? -
您是否验证过这在 bash 中确实有效? - 即没有 perl。我遇到的一些应用程序使用密码做一些时髦的事情,并且不会使用那种格式来获取东西。所以打开 bash 并运行
echo TheRealPassword | hdiutil create -size 200g -type SPARSEBUNDLE -encryption -stdinpass -volname \"Encrypted Storage for Matt\" -fs \"Case-sensitive Journaled HFS+\" -verbose ~/Desktop/SparseBundle -
@GregHNZ,为什么?这不是他使用 Perl 传递给 shell 的内容。
-
@Matt O.,它通过 STDIN 而不是作为参数获取密码的原因是机器上的其他用户可以看到命令。使用 IPC::Run3 的
run3来做正确的事情 -
在你做
$password = chomp($password);之后马上放print $password;是你期望的吗?