aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cerberus.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/cerberus.c b/src/cerberus.c
new file mode 100644
index 0000000..5f4afdc
--- /dev/null
+++ b/src/cerberus.c
@@ -0,0 +1,106 @@
+/**
+ * cerberus – Minimal login program
+ *
+ * Copyright © 2013 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <stdio.h>
+#include <termios.h>
+#include <unistd.h>
+
+
+/**
+ * Mane method
+ *
+ * @param argc The number of command line arguments
+ * @param argv The command line arguments
+ * @return Return code
+ */
+int main(int argc, char** argv)
+{
+ char* username = NULL;
+ char* hostname = NULL;
+ char preserve_env = 0;
+ struct termios saved_stty;
+ struct termios stty;
+ int i;
+
+ /* Disable echoing */
+ tcgetattr(STDIN_FILENO, &saved_stty);
+ stty = saved_stty;
+ stty.c_lflag &= ~ECHO;
+ tcsetattr(STDIN_FILENO, TCSAFLUSH, &stty);
+ /* This should be done as early and quickly as possible so as little
+ as possible of the passphrase gets leaked to the output if the user
+ begins entering the passphrase directly after the username. */
+
+ /* Parse command line arguments */
+ {
+ char double_dashed = 0;
+ char hostname_on_next = 0;
+ for (i = 1; i < argc; i++)
+ {
+ char *arg = *(argv + i);
+ char c;
+
+ if (*arg == 0)
+ ;
+ else if ((*arg == '-') && (double_dashed == 0))
+ while ((c = *(++arg)))
+ if ((c == 'V') || (c == 'H'))
+ ;
+ else if (c == 'p')
+ preserve_env = 1;
+ else if (c == 'h')
+ {
+ if (*(arg + 1))
+ hostname = arg + 1;
+ else
+ hostname_on_next = 1;
+ break;
+ }
+ else if (c == 'f')
+ {
+ if (*(arg + 1))
+ username = arg + 1;
+ break;
+ }
+ else if (c == '-')
+ {
+ double_dashed = 1;
+ break;
+ }
+ else
+ fprintf(stderr, "%s: unrecognised options: -%c\n", *argv, c);
+ else if (hostname_on_next)
+ {
+ hostname = arg;
+ hostname_on_next = 0;
+ }
+ else
+ username = arg;
+ }
+ }
+
+ printf("Passphrase: ");
+ fflush(stdout);
+
+
+ /* Reset terminal settings */
+ tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_stty);
+
+ return 0;
+}
+