How to get Mac OS to remember previous auth. from my executable file
I'm writing a tiny unix executable file that changes my macbook's system time manually. Of course, this requires a password, and so I used the system() function to interface with the terminal and change the date using echo and sudo.
See below:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
// Retrieve password:
printf("Enter Sudo Password:n");
char *pswrd;
pswrd = getpass("Password: ");
char strA[512];
// Instruction to manually change the date:
char *strA1 = "echo "";
char *strA2 = "" | sudo -S date 020821002014";
// Stitch fields into one string:
strcat(strA, strA1);
strcat(strA, pswrd);
strcat(strA, strA2);
// Run string in Terminal:
system(strA);
}
You can create a Unix executable to test.
In terminal line, it is equivalent to: Sudo date 020821002014
> Anyway, my question:
I don't like that every time I run the executable file, I have to
enter a password. Does anyone have suggestions for a way to input the
admin password once and have my MacBook recognize the executable in
future so I just have to click on the executable and change the date
effortlessly.
Oh, and I only picked the date because it typically requires a password, but this would of-course generalize to other administrator instructions.
Things I've considered:
- Using root superuser, but it seems overkill - there must be another way
- Writing password into .c code directly, but that sounds sketchy, and doesn't scale easily for multiple users
shell-script command-line sudo password c
add a comment |
I'm writing a tiny unix executable file that changes my macbook's system time manually. Of course, this requires a password, and so I used the system() function to interface with the terminal and change the date using echo and sudo.
See below:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
// Retrieve password:
printf("Enter Sudo Password:n");
char *pswrd;
pswrd = getpass("Password: ");
char strA[512];
// Instruction to manually change the date:
char *strA1 = "echo "";
char *strA2 = "" | sudo -S date 020821002014";
// Stitch fields into one string:
strcat(strA, strA1);
strcat(strA, pswrd);
strcat(strA, strA2);
// Run string in Terminal:
system(strA);
}
You can create a Unix executable to test.
In terminal line, it is equivalent to: Sudo date 020821002014
> Anyway, my question:
I don't like that every time I run the executable file, I have to
enter a password. Does anyone have suggestions for a way to input the
admin password once and have my MacBook recognize the executable in
future so I just have to click on the executable and change the date
effortlessly.
Oh, and I only picked the date because it typically requires a password, but this would of-course generalize to other administrator instructions.
Things I've considered:
- Using root superuser, but it seems overkill - there must be another way
- Writing password into .c code directly, but that sounds sketchy, and doesn't scale easily for multiple users
shell-script command-line sudo password c
A C program is very rarely called "a script". "Script" is usually used for programs written in interpreted languages.
– Kusalananda
Aug 24 '18 at 19:15
Thank you for that point @Kusalananda, what is a more appropriate synonym for .c file? I'll edit my post accordingly.
– McMath
Aug 24 '18 at 19:26
Just make a script that runssudo date 020821002014. Sudo caches credentials per terminal based on user policy. The stuff you're doing is unecessary an error prone (getpassshouldn't be used and your quoting of the password is brittle). There shouldn't be a need for any of it.
– PSkocik
Aug 24 '18 at 20:23
@McMath Well, I would call it the source code and I would call the compiled executable "the executable" or "the binary".
– Kusalananda
Aug 24 '18 at 21:06
add a comment |
I'm writing a tiny unix executable file that changes my macbook's system time manually. Of course, this requires a password, and so I used the system() function to interface with the terminal and change the date using echo and sudo.
See below:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
// Retrieve password:
printf("Enter Sudo Password:n");
char *pswrd;
pswrd = getpass("Password: ");
char strA[512];
// Instruction to manually change the date:
char *strA1 = "echo "";
char *strA2 = "" | sudo -S date 020821002014";
// Stitch fields into one string:
strcat(strA, strA1);
strcat(strA, pswrd);
strcat(strA, strA2);
// Run string in Terminal:
system(strA);
}
You can create a Unix executable to test.
In terminal line, it is equivalent to: Sudo date 020821002014
> Anyway, my question:
I don't like that every time I run the executable file, I have to
enter a password. Does anyone have suggestions for a way to input the
admin password once and have my MacBook recognize the executable in
future so I just have to click on the executable and change the date
effortlessly.
Oh, and I only picked the date because it typically requires a password, but this would of-course generalize to other administrator instructions.
Things I've considered:
- Using root superuser, but it seems overkill - there must be another way
- Writing password into .c code directly, but that sounds sketchy, and doesn't scale easily for multiple users
shell-script command-line sudo password c
I'm writing a tiny unix executable file that changes my macbook's system time manually. Of course, this requires a password, and so I used the system() function to interface with the terminal and change the date using echo and sudo.
See below:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
// Retrieve password:
printf("Enter Sudo Password:n");
char *pswrd;
pswrd = getpass("Password: ");
char strA[512];
// Instruction to manually change the date:
char *strA1 = "echo "";
char *strA2 = "" | sudo -S date 020821002014";
// Stitch fields into one string:
strcat(strA, strA1);
strcat(strA, pswrd);
strcat(strA, strA2);
// Run string in Terminal:
system(strA);
}
You can create a Unix executable to test.
In terminal line, it is equivalent to: Sudo date 020821002014
> Anyway, my question:
I don't like that every time I run the executable file, I have to
enter a password. Does anyone have suggestions for a way to input the
admin password once and have my MacBook recognize the executable in
future so I just have to click on the executable and change the date
effortlessly.
Oh, and I only picked the date because it typically requires a password, but this would of-course generalize to other administrator instructions.
Things I've considered:
- Using root superuser, but it seems overkill - there must be another way
- Writing password into .c code directly, but that sounds sketchy, and doesn't scale easily for multiple users
shell-script command-line sudo password c
shell-script command-line sudo password c
edited 2 hours ago
Rui F Ribeiro
39.6k1479132
39.6k1479132
asked Aug 24 '18 at 19:13
McMathMcMath
13
13
A C program is very rarely called "a script". "Script" is usually used for programs written in interpreted languages.
– Kusalananda
Aug 24 '18 at 19:15
Thank you for that point @Kusalananda, what is a more appropriate synonym for .c file? I'll edit my post accordingly.
– McMath
Aug 24 '18 at 19:26
Just make a script that runssudo date 020821002014. Sudo caches credentials per terminal based on user policy. The stuff you're doing is unecessary an error prone (getpassshouldn't be used and your quoting of the password is brittle). There shouldn't be a need for any of it.
– PSkocik
Aug 24 '18 at 20:23
@McMath Well, I would call it the source code and I would call the compiled executable "the executable" or "the binary".
– Kusalananda
Aug 24 '18 at 21:06
add a comment |
A C program is very rarely called "a script". "Script" is usually used for programs written in interpreted languages.
– Kusalananda
Aug 24 '18 at 19:15
Thank you for that point @Kusalananda, what is a more appropriate synonym for .c file? I'll edit my post accordingly.
– McMath
Aug 24 '18 at 19:26
Just make a script that runssudo date 020821002014. Sudo caches credentials per terminal based on user policy. The stuff you're doing is unecessary an error prone (getpassshouldn't be used and your quoting of the password is brittle). There shouldn't be a need for any of it.
– PSkocik
Aug 24 '18 at 20:23
@McMath Well, I would call it the source code and I would call the compiled executable "the executable" or "the binary".
– Kusalananda
Aug 24 '18 at 21:06
A C program is very rarely called "a script". "Script" is usually used for programs written in interpreted languages.
– Kusalananda
Aug 24 '18 at 19:15
A C program is very rarely called "a script". "Script" is usually used for programs written in interpreted languages.
– Kusalananda
Aug 24 '18 at 19:15
Thank you for that point @Kusalananda, what is a more appropriate synonym for .c file? I'll edit my post accordingly.
– McMath
Aug 24 '18 at 19:26
Thank you for that point @Kusalananda, what is a more appropriate synonym for .c file? I'll edit my post accordingly.
– McMath
Aug 24 '18 at 19:26
Just make a script that runs
sudo date 020821002014. Sudo caches credentials per terminal based on user policy. The stuff you're doing is unecessary an error prone (getpass shouldn't be used and your quoting of the password is brittle). There shouldn't be a need for any of it.– PSkocik
Aug 24 '18 at 20:23
Just make a script that runs
sudo date 020821002014. Sudo caches credentials per terminal based on user policy. The stuff you're doing is unecessary an error prone (getpass shouldn't be used and your quoting of the password is brittle). There shouldn't be a need for any of it.– PSkocik
Aug 24 '18 at 20:23
@McMath Well, I would call it the source code and I would call the compiled executable "the executable" or "the binary".
– Kusalananda
Aug 24 '18 at 21:06
@McMath Well, I would call it the source code and I would call the compiled executable "the executable" or "the binary".
– Kusalananda
Aug 24 '18 at 21:06
add a comment |
1 Answer
1
active
oldest
votes
Another method (that does not leave the password lying around nor expose it to various process listing and diagnostic tools) would be to set a NOPASSWD entry in the sudo configuration file that allows only the date command to be run, possibly an exact date command:
fixmeyourusernamehere ALL=(root) NOPASSWD: /bin/date 020821002014
with this set at the bottom of the /etc/sudoers file (better edited with sudo visudo, though) then the user fixmeyourusernamehere should be able to run 'sudo date 020821002014without a password, but not any other commands (unless thesudo` configuration allows them other commands).
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f464704%2fhow-to-get-mac-os-to-remember-previous-auth-from-my-executable-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Another method (that does not leave the password lying around nor expose it to various process listing and diagnostic tools) would be to set a NOPASSWD entry in the sudo configuration file that allows only the date command to be run, possibly an exact date command:
fixmeyourusernamehere ALL=(root) NOPASSWD: /bin/date 020821002014
with this set at the bottom of the /etc/sudoers file (better edited with sudo visudo, though) then the user fixmeyourusernamehere should be able to run 'sudo date 020821002014without a password, but not any other commands (unless thesudo` configuration allows them other commands).
add a comment |
Another method (that does not leave the password lying around nor expose it to various process listing and diagnostic tools) would be to set a NOPASSWD entry in the sudo configuration file that allows only the date command to be run, possibly an exact date command:
fixmeyourusernamehere ALL=(root) NOPASSWD: /bin/date 020821002014
with this set at the bottom of the /etc/sudoers file (better edited with sudo visudo, though) then the user fixmeyourusernamehere should be able to run 'sudo date 020821002014without a password, but not any other commands (unless thesudo` configuration allows them other commands).
add a comment |
Another method (that does not leave the password lying around nor expose it to various process listing and diagnostic tools) would be to set a NOPASSWD entry in the sudo configuration file that allows only the date command to be run, possibly an exact date command:
fixmeyourusernamehere ALL=(root) NOPASSWD: /bin/date 020821002014
with this set at the bottom of the /etc/sudoers file (better edited with sudo visudo, though) then the user fixmeyourusernamehere should be able to run 'sudo date 020821002014without a password, but not any other commands (unless thesudo` configuration allows them other commands).
Another method (that does not leave the password lying around nor expose it to various process listing and diagnostic tools) would be to set a NOPASSWD entry in the sudo configuration file that allows only the date command to be run, possibly an exact date command:
fixmeyourusernamehere ALL=(root) NOPASSWD: /bin/date 020821002014
with this set at the bottom of the /etc/sudoers file (better edited with sudo visudo, though) then the user fixmeyourusernamehere should be able to run 'sudo date 020821002014without a password, but not any other commands (unless thesudo` configuration allows them other commands).
answered Aug 24 '18 at 20:12
thrigthrig
24.6k23056
24.6k23056
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f464704%2fhow-to-get-mac-os-to-remember-previous-auth-from-my-executable-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
A C program is very rarely called "a script". "Script" is usually used for programs written in interpreted languages.
– Kusalananda
Aug 24 '18 at 19:15
Thank you for that point @Kusalananda, what is a more appropriate synonym for .c file? I'll edit my post accordingly.
– McMath
Aug 24 '18 at 19:26
Just make a script that runs
sudo date 020821002014. Sudo caches credentials per terminal based on user policy. The stuff you're doing is unecessary an error prone (getpassshouldn't be used and your quoting of the password is brittle). There shouldn't be a need for any of it.– PSkocik
Aug 24 '18 at 20:23
@McMath Well, I would call it the source code and I would call the compiled executable "the executable" or "the binary".
– Kusalananda
Aug 24 '18 at 21:06