QT CLI Option Add more value names - qt

I am improving a QT CLI and I would like to simplify some options, for example to add a username with password, right now it is necessary to pass --passwod.
-a, --add <username> Adds a new user.
--password <password> Password
I would like to have something like this, but it seems QT only allows one value name.
-a, --add <username> <password> Adds a new user.
Is there a way I can implement this with QT?
Thanks in advance.

QCommandLineParser expects one value for each option. You can use positional argument for password in your case.

Related

How to configure rsync with password in OpenStack Swift

I am currently working on Swfit. For safe, the op ask me to set password for rsync.
While, as we use Swift, we just set rsync work as server with "/etc/rsync.conf" , then Swift works as the client without password.
So, my question is, if i start the rsync with "secrets file" option, which set the user:password. Then, how to set Swift with the password?
Read the Swift code about the rsync in replicator, i can't find the option to set the password.
Or, Swift doesn't support the function?
Luckly, by reading the source code, i find the way to support rsync with 'secrets file' option:
By adding the '--password-file=/your_passwd_file_path' to rsync order in this two function:
swift/common/db_replicator.py/_rsync_file() and swift/obj/replicator/rsync()
Then, restart your swift, it will work right.

Should I create a new file for the new RSA key or just append the new RSA key without overwriting the old one ?

I am in this situation (Please note that I am still new to the idea of this ssh thing):
Basically, I have already set up SSH for my Github, so every time I do git push origin master, it will not prompt me to enter username and password, which is good. Now I want to set up another SSH for logging onto my school server. I wanted to follow the same instruction which I did for Github in this link. But after I typed in ssh-keygen -t rsa -C "me#school.com" . It says that /.ssh/id_rsa already exists. Overwrite (y/n)? .
Obviously, I do not want to overwrite it, since I still want instant access to my Github account. I know that I can create another id_rsa under a different name, but is this a good approach ? Does it have any side-effects ? It seems to look nicer if I can just append the new RSA key to the existing id_rsa but I have no idea how to do so. (Need to know the right command to do this I guess)
You don't need to create a new key. you can us the same public key and put it on your school account. The parameter -C just put's a comment to your key and it is only there, so that you can easily recognize it as your key. It has nothing to do with the ability log in on a specific server.

Provide password to SSOCONFIG.EXE as parameter?

How can you provide the password to ssoconfig.exe -restoresecret as parameter?
I'm trying to use the sysprep scripts from Colin Meade on TechNet
Checked on MSDN and ssoconfig -restoresecret only has <restore file> as a parameter ... no reference to "password"
Yet when I run the command, I get the prompt for a password, along with the password hint!
As described in http://msdn.microsoft.com/en-us/library/aa560589.aspx, the command does not let you restore a secret with a password as a parameter. So it doesn't seem to be viable via the command line.
I don't know what the use-case is in your case, but in general I'm not sure if this would be something you want to automate?
What you can do is automate it yourself by writing a wrapper (e.g. console application) for it. You can do so by sending keystrokes to the command line, there are various examples available here on SO.

Prompt user for password with dialog window when using sudo

I need to execute a command with sudo and want to display a dialog window for the user to enter their credentials. Attempts to customize a prompt with Applescript have been nothing short of excruciating and using the built in "do shell script with with administrator privileges" doesn't allow for customizing the window so the user knows where the request is coming from.
Surely, there is a way to display a window, have the user enter their credentials and send the values back to sudo to execute the command? cocoasudo looks promising but it also writes "cocoasudo" in the prompt window which I need to replace with the name of my application. Has anyone found a solution for implementing this kind of functionality?
Building custom windows is beyond the scope of basic applescript. You will need to expand your programming skills if you want this. You'll need to learn how to leverage to tools that Apple supplies for creating windows and such. Bottom line is you'll need to learn either AppleScriptObjC or Objective-C/Cocoa APIs and how to use them in Xcode.
With that said, if you're not into learning new stuff then use the tools you have. Something like this will work. You can customize the icon, the buttons, the text etc. you can even have a hidden answer to protect the user when entering passwords. There's lots you can do with Applescript without further learning...
display dialog "OSAScript will need an Admin User name and password in order to make your changes." & return & return & "Please enter an admin username." default answer "" with icon 2
set username to text returned of result
display dialog "OSAScript will need an Admin User name and password in order to make your changes." & return & return & "Please enter an admin password." default answer "" with icon 2 with hidden answer
set pssword to text returned of result
do shell script "osascript -e \"return 1\"" user name username password pssword with administrator privileges
In addition, consider that once you authenticate with sudo, you don't need to provide a password again for the next five minutes. That doesn't directly solve your problem, but it gives you more options for the way you interact with the user. The -n option to sudo prevents it from prompting for a password (the command runs, or sudo quits with an error).
You could use -n in combination with the -A option, which causes sudo to run a separate program whose only job is to collect and output a password. Would that let you use AppleScript to better do what you want?
If you are familiar with Javascript, you can use the sudo-prompt module for Node to run your command using sudo and to prompt with a dialog window if necessary. The dialog is a native prompt raised by the operating system so that the user's password is never exposed to your application. You can also provide the name and icon of your application on macOS. The module also works on Windows and Linux.

How can I pass a password to the "su" command?

I have a program that is going to take a password as input and then do a shell execute to perform a "su" (switch user) command in UNIX. However, I don't know how to pass the password variable to the UNIX su command. The language I have to use for this is pretty limited (UniBasic).
Any ideas?
Well, the best way to do that would be a setuid-root binary that ask for the password then execute whatever command is needed but it requires knowledge you say not to possess. I'd advise in looking at sudo(1) instead.
You could ssh to localhost as another user to execute whatever command you want. Or, use sudo and edit /etc/sudoers such that sudo does not ask for a password. However, there could be security implications.
EDIT: Please let me know why when you vote it down. My answer may not be perfect but at least it works. I do that myself for some licensed software that can only be run under a weird user name.
You do not want to specify the password as a command-line argument. Not so much because of #unwind's answer (scripts could be made private) but because if someone runs a list of processes, you could see the command argument and hence the password in question.
The version of su I have on my Linux server does not support such an option. I checked sudo, but it doesn't either. They want to do the prompting themselves, to ensure it's done in a safe manner and (I guess) to discourage people from putting passwords verbatim in scripts and so on.
You could also look at the 'expect' utility that was designed to script complex user inputs into a programs that weren't flexible enough to receive this input from places other than stdin.

Resources