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
23 #include <lib/version.h>
28 #include <security/pam_appl.h>
29 #ifdef HAVE_PAM_MISC_H
30 #include <security/pam_misc.h>
33 #include <security/openpam.h>
42 static struct pam_conv conv
=
49 vtysh_pam (const char *user
)
52 pam_handle_t
*pamh
= NULL
;
55 ret
= pam_start(QUAGGA_PROGNAME
, user
, &conv
, &pamh
);
56 /* printf ("ret %d\n", ret); */
58 /* Is user really user? */
59 if (ret
== PAM_SUCCESS
)
60 ret
= pam_authenticate (pamh
, 0);
61 /* printf ("ret %d\n", ret); */
64 /* Permitted access? */
65 if (ret
== PAM_SUCCESS
)
66 ret
= pam_acct_mgmt (pamh
, 0);
67 printf ("ret %d\n", ret
);
69 if (ret
== PAM_AUTHINFO_UNAVAIL
)
73 /* This is where we have been authorized or not. */
75 if (ret
== PAM_SUCCESS
)
76 printf("Authenticated\n");
78 printf("Not Authenticated\n");
82 if (pam_end (pamh
, ret
) != PAM_SUCCESS
)
85 fprintf(stderr
, "vtysh_pam: failed to release authenticator\n");
89 return ret
== PAM_SUCCESS
? 0 : 1;
99 struct list
*userlist
;
104 return XCALLOC (0, sizeof (struct vtysh_user
));
108 user_free (struct vtysh_user
*user
)
114 user_lookup (const char *name
)
116 struct listnode
*node
, *nnode
;
117 struct vtysh_user
*user
;
119 for (ALL_LIST_ELEMENTS (userlist
, node
, nnode
, user
))
121 if (strcmp (user
->name
, name
) == 0)
130 struct listnode
*node
, *nnode
;
131 struct vtysh_user
*user
;
133 for (ALL_LIST_ELEMENTS (userlist
, node
, nnode
, user
))
135 if (user
->nopassword
)
136 printf (" username %s nopassword\n", user
->name
);
141 user_get (const char *name
)
143 struct vtysh_user
*user
;
144 user
= user_lookup (name
);
149 user
->name
= strdup (name
);
150 listnode_add (userlist
, user
);
155 DEFUN (username_nopassword
,
156 username_nopassword_cmd
,
157 "username WORD nopassword",
162 struct vtysh_user
*user
;
163 user
= user_get (argv
[0]);
164 user
->nopassword
= 1;
171 struct vtysh_user
*user
;
172 struct passwd
*passwd
;
174 passwd
= getpwuid (geteuid ());
176 user
= user_lookup (passwd
->pw_name
);
177 if (user
&& user
->nopassword
)
182 if (vtysh_pam (passwd
->pw_name
))
192 userlist
= list_new ();
193 install_element (CONFIG_NODE
, &username_nopassword_cmd
);