]>
git.proxmox.com Git - mirror_frr.git/blob - vtysh/vtysh_user.c
1 /* User authentication for vtysh.
2 * Copyright (C) 2000 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include <security/pam_appl.h>
28 #ifdef HAVE_PAM_MISC_H
29 #include <security/pam_misc.h>
32 #include <security/openpam.h>
41 static struct pam_conv conv
=
48 vtysh_pam (char *user
)
51 pam_handle_t
*pamh
= NULL
;
54 ret
= pam_start("zebra", user
, &conv
, &pamh
);
55 /* printf ("ret %d\n", ret); */
57 /* Is user really user? */
58 if (ret
== PAM_SUCCESS
)
59 ret
= pam_authenticate (pamh
, 0);
60 /* printf ("ret %d\n", ret); */
63 /* Permitted access? */
64 if (ret
== PAM_SUCCESS
)
65 ret
= pam_acct_mgmt (pamh
, 0);
66 printf ("ret %d\n", ret
);
68 if (ret
== PAM_AUTHINFO_UNAVAIL
)
72 /* This is where we have been authorized or not. */
74 if (ret
== PAM_SUCCESS
)
75 printf("Authenticated\n");
77 printf("Not Authenticated\n");
81 if (pam_end (pamh
, ret
) != PAM_SUCCESS
)
84 fprintf(stderr
, "vtysh_pam: failed to release authenticator\n");
88 return ret
== PAM_SUCCESS
? 0 : 1;
98 struct list
*userlist
;
104 user
= XMALLOC (0, sizeof (struct user
));
105 memset (user
, 0, sizeof (struct user
));
110 user_free (struct user
*user
)
116 user_lookup (char *name
)
121 LIST_LOOP (userlist
, user
, nn
)
123 if (strcmp (user
->name
, name
) == 0)
135 LIST_LOOP (userlist
, user
, nn
)
137 if (user
->nopassword
)
138 printf (" username %s nopassword\n", user
->name
);
143 user_get (char *name
)
146 user
= user_lookup (name
);
151 user
->name
= strdup (name
);
152 listnode_add (userlist
, user
);
157 DEFUN (username_nopassword
,
158 username_nopassword_cmd
,
159 "username WORD nopassword",
165 user
= user_get (argv
[0]);
166 user
->nopassword
= 1;
174 struct passwd
*passwd
;
176 passwd
= getpwuid (geteuid ());
178 user
= user_lookup (passwd
->pw_name
);
179 if (user
&& user
->nopassword
)
184 if (vtysh_pam (passwd
->pw_name
))
194 userlist
= list_new ();
195 install_element (CONFIG_NODE
, &username_nopassword_cmd
);