]>
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
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 * Compiler is warning about prototypes not being declared.
43 * The DEFUNSH and DEFUN macro's are messing with the
44 * compiler I believe. This is just to make it happy.
46 int vtysh_pam(const char *);
47 struct vtysh_user
*user_new(void);
48 void user_free(struct vtysh_user
*);
49 struct vtysh_user
*user_lookup(const char *);
50 void user_config_write(void);
51 struct vtysh_user
*user_get(const char *);
53 void vtysh_user_init(void);
56 static struct pam_conv conv
=
63 vtysh_pam (const char *user
)
66 pam_handle_t
*pamh
= NULL
;
69 ret
= pam_start(QUAGGA_PROGNAME
, user
, &conv
, &pamh
);
70 /* printf ("ret %d\n", ret); */
72 /* Is user really user? */
73 if (ret
== PAM_SUCCESS
)
74 ret
= pam_authenticate (pamh
, 0);
75 /* printf ("ret %d\n", ret); */
78 /* Permitted access? */
79 if (ret
== PAM_SUCCESS
)
80 ret
= pam_acct_mgmt (pamh
, 0);
81 printf ("ret %d\n", ret
);
83 if (ret
== PAM_AUTHINFO_UNAVAIL
)
87 /* This is where we have been authorized or not. */
89 if (ret
== PAM_SUCCESS
)
90 printf("Authenticated\n");
92 printf("Not Authenticated\n");
96 if (pam_end (pamh
, ret
) != PAM_SUCCESS
)
99 fprintf(stderr
, "vtysh_pam: failed to release authenticator\n");
103 return ret
== PAM_SUCCESS
? 0 : 1;
113 struct list
*userlist
;
118 return XCALLOC (0, sizeof (struct vtysh_user
));
122 user_free (struct vtysh_user
*user
)
128 user_lookup (const char *name
)
130 struct listnode
*node
, *nnode
;
131 struct vtysh_user
*user
;
133 for (ALL_LIST_ELEMENTS (userlist
, node
, nnode
, user
))
135 if (strcmp (user
->name
, name
) == 0)
144 struct listnode
*node
, *nnode
;
145 struct vtysh_user
*user
;
147 for (ALL_LIST_ELEMENTS (userlist
, node
, nnode
, user
))
149 if (user
->nopassword
)
150 printf (" username %s nopassword\n", user
->name
);
155 user_get (const char *name
)
157 struct vtysh_user
*user
;
158 user
= user_lookup (name
);
163 user
->name
= strdup (name
);
164 listnode_add (userlist
, user
);
169 DEFUN (username_nopassword
,
170 username_nopassword_cmd
,
171 "username WORD nopassword",
176 struct vtysh_user
*user
;
177 user
= user_get (argv
[0]);
178 user
->nopassword
= 1;
185 struct vtysh_user
*user
;
186 struct passwd
*passwd
;
188 passwd
= getpwuid (geteuid ());
190 user
= user_lookup (passwd
->pw_name
);
191 if (user
&& user
->nopassword
)
196 if (vtysh_pam (passwd
->pw_name
))
206 userlist
= list_new ();
207 install_element (CONFIG_NODE
, &username_nopassword_cmd
);