X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=vtysh%2Fvtysh_user.c;h=e575b7154914a8ed396154168e5d07efab69a7c9;hb=c52e2ecf95a9be318912caacc0851d9307e679f7;hp=97720e9fd66bbcd92f18c023a7f80b0d45087731;hpb=b440fe5c82f73a4f34ebc59ac07e95f56e1193e0;p=mirror_frr.git diff --git a/vtysh/vtysh_user.c b/vtysh/vtysh_user.c index 97720e9fd..e575b7154 100644 --- a/vtysh/vtysh_user.c +++ b/vtysh/vtysh_user.c @@ -38,7 +38,7 @@ #include "command.h" #include "vtysh/vtysh_user.h" -/* +/* * Compiler is warning about prototypes not being declared. * The DEFUNSH and DEFUN macro's are messing with the * compiler I believe. This is just to make it happy. @@ -53,27 +53,22 @@ extern struct list *config_top; extern void config_add_line(struct list *config, const char *line); #ifdef USE_PAM -static struct pam_conv conv = -{ - PAM_CONV_FUNC, - NULL -}; +static struct pam_conv conv = {PAM_CONV_FUNC, NULL}; -static int -vtysh_pam (const char *user) +static int vtysh_pam(const char *user) { - int ret; - pam_handle_t *pamh = NULL; + int ret; + pam_handle_t *pamh = NULL; - /* Start PAM. */ - ret = pam_start(FRR_PAM_NAME, user, &conv, &pamh); - /* printf ("ret %d\n", ret); */ + /* Start PAM. */ + ret = pam_start(FRR_PAM_NAME, user, &conv, &pamh); + /* printf ("ret %d\n", ret); */ + + /* Is user really user? */ + if (ret == PAM_SUCCESS) + ret = pam_authenticate(pamh, 0); +/* printf ("ret %d\n", ret); */ - /* Is user really user? */ - if (ret == PAM_SUCCESS) - ret = pam_authenticate (pamh, 0); - /* printf ("ret %d\n", ret); */ - #if 0 /* Permitted access? */ if (ret == PAM_SUCCESS) @@ -83,85 +78,76 @@ vtysh_pam (const char *user) if (ret == PAM_AUTHINFO_UNAVAIL) ret = PAM_SUCCESS; #endif /* 0 */ - - /* This is where we have been authorized or not. */ + +/* This is where we have been authorized or not. */ #ifdef DEBUG - if (ret == PAM_SUCCESS) - printf("Authenticated\n"); - else - printf("Not Authenticated\n"); + if (ret == PAM_SUCCESS) + printf("Authenticated\n"); + else + printf("Not Authenticated\n"); #endif /* DEBUG */ - /* close Linux-PAM */ - if (pam_end (pamh, ret) != PAM_SUCCESS) - { - pamh = NULL; - fprintf(stderr, "vtysh_pam: failed to release authenticator\n"); - exit(1); - } + /* close Linux-PAM */ + if (pam_end(pamh, ret) != PAM_SUCCESS) { + pamh = NULL; + fprintf(stderr, "vtysh_pam: failed to release authenticator\n"); + exit(1); + } - return ret == PAM_SUCCESS ? 0 : 1; + return ret == PAM_SUCCESS ? 0 : 1; } #endif /* USE_PAM */ -struct vtysh_user -{ - char *name; - u_char nopassword; +struct vtysh_user { + char *name; + uint8_t nopassword; }; struct list *userlist; -static struct vtysh_user * -user_new (void) +static struct vtysh_user *user_new(void) { - return XCALLOC (MTYPE_TMP, sizeof (struct vtysh_user)); + return XCALLOC(MTYPE_TMP, sizeof(struct vtysh_user)); } -static struct vtysh_user * -user_lookup (const char *name) +static struct vtysh_user *user_lookup(const char *name) { - struct listnode *node, *nnode; - struct vtysh_user *user; + struct listnode *node, *nnode; + struct vtysh_user *user; - for (ALL_LIST_ELEMENTS (userlist, node, nnode, user)) - { - if (strcmp (user->name, name) == 0) - return user; - } - return NULL; + for (ALL_LIST_ELEMENTS(userlist, node, nnode, user)) { + if (strcmp(user->name, name) == 0) + return user; + } + return NULL; } -void -user_config_write () +void user_config_write() { - struct listnode *node, *nnode; - struct vtysh_user *user; - char line[128]; - - for (ALL_LIST_ELEMENTS (userlist, node, nnode, user)) - { - if (user->nopassword) - { - sprintf(line, "username %s nopassword", user->name); - config_add_line (config_top, line); + struct listnode *node, *nnode; + struct vtysh_user *user; + char line[128]; + + for (ALL_LIST_ELEMENTS(userlist, node, nnode, user)) { + if (user->nopassword) { + sprintf(line, "username %s nopassword", user->name); + config_add_line(config_top, line); + } } - } } -static struct vtysh_user * -user_get (const char *name) +static struct vtysh_user *user_get(const char *name) { - struct vtysh_user *user; - user = user_lookup (name); - if (user) - return user; + struct vtysh_user *user; + user = user_lookup(name); + if (user) + return user; - user = user_new (); - user->name = strdup (name); - listnode_add (userlist, user); + user = user_new(); + user->name = strdup(name); + listnode_add(userlist, user); - return user; + return user; } DEFUN (vtysh_banner_motd_file, @@ -172,8 +158,8 @@ DEFUN (vtysh_banner_motd_file, "Banner from a file\n" "Filename\n") { - int idx_file = 3; - return cmd_banner_motd_file (argv[idx_file]->arg); + int idx_file = 3; + return cmd_banner_motd_file(argv[idx_file]->arg); } DEFUN (username_nopassword, @@ -183,57 +169,53 @@ DEFUN (username_nopassword, "\n" "\n") { - int idx_word = 1; - struct vtysh_user *user; - user = user_get (argv[idx_word]->arg); - user->nopassword = 1; - return CMD_SUCCESS; + int idx_word = 1; + struct vtysh_user *user; + user = user_get(argv[idx_word]->arg); + user->nopassword = 1; + return CMD_SUCCESS; } -int -vtysh_auth (void) +int vtysh_auth(void) { - struct vtysh_user *user; - struct passwd *passwd; - - if ((passwd = getpwuid (geteuid ())) == NULL) - { - fprintf (stderr, "could not lookup user ID %d\n", (int) geteuid()); - exit (1); - } - - user = user_lookup (passwd->pw_name); - if (user && user->nopassword) - /* Pass through */; - else - { + struct vtysh_user *user; + struct passwd *passwd; + + if ((passwd = getpwuid(geteuid())) == NULL) { + fprintf(stderr, "could not lookup user ID %d\n", + (int)geteuid()); + exit(1); + } + + user = user_lookup(passwd->pw_name); + if (user && user->nopassword) + /* Pass through */; + else { #ifdef USE_PAM - if (vtysh_pam (passwd->pw_name)) - exit (0); + if (vtysh_pam(passwd->pw_name)) + exit(0); #endif /* USE_PAM */ - } - return 0; + } + return 0; } -char * -vtysh_get_home (void) +char *vtysh_get_home(void) { - struct passwd *passwd; - char * homedir; + struct passwd *passwd; + char *homedir; - if ((homedir = getenv("HOME")) != 0) - return homedir; + if ((homedir = getenv("HOME")) != 0) + return homedir; - /* Fallback if HOME is undefined */ - passwd = getpwuid (getuid ()); + /* Fallback if HOME is undefined */ + passwd = getpwuid(getuid()); - return passwd ? passwd->pw_dir : NULL; + return passwd ? passwd->pw_dir : NULL; } -void -vtysh_user_init (void) +void vtysh_user_init(void) { - userlist = list_new (); - install_element (CONFIG_NODE, &username_nopassword_cmd); - install_element (CONFIG_NODE, &vtysh_banner_motd_file_cmd); + userlist = list_new(); + install_element(CONFIG_NODE, &username_nopassword_cmd); + install_element(CONFIG_NODE, &vtysh_banner_motd_file_cmd); }