]>
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>
40 #include "vtysh/vtysh_user.h"
43 * Compiler is warning about prototypes not being declared.
44 * The DEFUNSH and DEFUN macro's are messing with the
45 * compiler I believe. This is just to make it happy.
47 int vtysh_pam(const char *);
48 struct vtysh_user
*user_new(void);
49 void user_free(struct vtysh_user
*);
50 struct vtysh_user
*user_lookup(const char *);
51 struct vtysh_user
*user_get(const char *);
53 void vtysh_user_init(void);
55 extern struct list
*config_top
;
56 extern void config_add_line(struct list
*config
, const char *line
);
59 static struct pam_conv conv
=
66 vtysh_pam (const char *user
)
69 pam_handle_t
*pamh
= NULL
;
72 ret
= pam_start(QUAGGA_PROGNAME
, user
, &conv
, &pamh
);
73 /* printf ("ret %d\n", ret); */
75 /* Is user really user? */
76 if (ret
== PAM_SUCCESS
)
77 ret
= pam_authenticate (pamh
, 0);
78 /* printf ("ret %d\n", ret); */
81 /* Permitted access? */
82 if (ret
== PAM_SUCCESS
)
83 ret
= pam_acct_mgmt (pamh
, 0);
84 printf ("ret %d\n", ret
);
86 if (ret
== PAM_AUTHINFO_UNAVAIL
)
90 /* This is where we have been authorized or not. */
92 if (ret
== PAM_SUCCESS
)
93 printf("Authenticated\n");
95 printf("Not Authenticated\n");
99 if (pam_end (pamh
, ret
) != PAM_SUCCESS
)
102 fprintf(stderr
, "vtysh_pam: failed to release authenticator\n");
106 return ret
== PAM_SUCCESS
? 0 : 1;
116 struct list
*userlist
;
121 return XCALLOC (0, sizeof (struct vtysh_user
));
125 user_free (struct vtysh_user
*user
)
131 user_lookup (const char *name
)
133 struct listnode
*node
, *nnode
;
134 struct vtysh_user
*user
;
136 for (ALL_LIST_ELEMENTS (userlist
, node
, nnode
, user
))
138 if (strcmp (user
->name
, name
) == 0)
147 struct listnode
*node
, *nnode
;
148 struct vtysh_user
*user
;
151 for (ALL_LIST_ELEMENTS (userlist
, node
, nnode
, user
))
153 if (user
->nopassword
)
155 sprintf(line
, "username %s nopassword", user
->name
);
156 config_add_line (config_top
, line
);
162 user_get (const char *name
)
164 struct vtysh_user
*user
;
165 user
= user_lookup (name
);
170 user
->name
= strdup (name
);
171 listnode_add (userlist
, user
);
176 DEFUN (username_nopassword
,
177 username_nopassword_cmd
,
178 "username WORD nopassword",
183 struct vtysh_user
*user
;
184 user
= user_get (argv
[0]);
185 user
->nopassword
= 1;
192 struct vtysh_user
*user
;
193 struct passwd
*passwd
;
195 passwd
= getpwuid (geteuid ());
197 user
= user_lookup (passwd
->pw_name
);
198 if (user
&& user
->nopassword
)
203 if (vtysh_pam (passwd
->pw_name
))
213 userlist
= list_new ();
214 install_element (CONFIG_NODE
, &username_nopassword_cmd
);