2 * uhttpd - Tiny single-threaded httpd
4 * Copyright (C) 2010-2012 Jo-Philipp Wich <xm@subsignal.org>
5 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 static LIST_HEAD(auth_realms
);
24 void uh_auth_add(const char *path
, const char *user
, const char *pass
)
26 struct auth_realm
*new = NULL
;
28 const char *new_pass
= NULL
;
29 char *dest_path
, *dest_user
, *dest_pass
;
35 /* given password refers to a passwd entry */
36 if ((strlen(pass
) > 3) && !strncmp(pass
, "$p$", 3)) {
38 /* try to resolve shadow entry */
39 spwd
= getspnam(&pass
[3]);
41 new_pass
= spwd
->sp_pwdp
;
44 pwd
= getpwnam(&pass
[3]);
45 if (pwd
&& pwd
->pw_passwd
&& pwd
->pw_passwd
[0] &&
46 pwd
->pw_passwd
[0] != '!')
47 new_pass
= pwd
->pw_passwd
;
53 if (!new_pass
|| !new_pass
[0])
56 new = calloc_a(sizeof(*new),
57 &dest_path
, strlen(path
) + 1,
58 &dest_user
, strlen(user
) + 1,
59 &dest_pass
, strlen(new_pass
) + 1);
64 new->path
= strcpy(dest_path
, path
);
65 new->user
= strcpy(dest_user
, user
);
66 new->pass
= strcpy(dest_pass
, new_pass
);
67 list_add(&new->list
, &auth_realms
);