Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 1 | /* |
Ben Lindstrom | 92a2e38 | 2001-03-05 06:59:27 +0000 | [diff] [blame] | 2 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 14 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 15 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 16 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 17 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 19 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 20 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | #include "includes.h" |
Ben Lindstrom | 60567ff | 2001-06-05 20:27:53 +0000 | [diff] [blame] | 26 | RCSID("$OpenBSD: auth.c,v 1.23 2001/05/24 11:12:42 markus Exp $"); |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 27 | |
Damien Miller | d2c208a | 2000-05-17 22:00:02 +1000 | [diff] [blame] | 28 | #ifdef HAVE_LOGIN_H |
| 29 | #include <login.h> |
| 30 | #endif |
Damien Miller | 1f335fb | 2000-06-26 11:31:33 +1000 | [diff] [blame] | 31 | #if defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) |
| 32 | #include <shadow.h> |
| 33 | #endif /* defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) */ |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 34 | |
Ben Lindstrom | bfb3a0e | 2001-06-05 20:25:05 +0000 | [diff] [blame] | 35 | #include <libgen.h> |
| 36 | |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 37 | #include "xmalloc.h" |
| 38 | #include "match.h" |
| 39 | #include "groupaccess.h" |
| 40 | #include "log.h" |
| 41 | #include "servconf.h" |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 42 | #include "auth.h" |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 43 | #include "auth-options.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 44 | #include "canohost.h" |
Ben Lindstrom | bfb3a0e | 2001-06-05 20:25:05 +0000 | [diff] [blame] | 45 | #include "buffer.h" |
| 46 | #include "bufaux.h" |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 47 | |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 48 | /* import */ |
| 49 | extern ServerOptions options; |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 50 | |
| 51 | /* |
Kevin Steves | 7b61cfa | 2001-01-14 19:11:00 +0000 | [diff] [blame] | 52 | * Check if the user is allowed to log in via ssh. If user is listed |
| 53 | * in DenyUsers or one of user's groups is listed in DenyGroups, false |
| 54 | * will be returned. If AllowUsers isn't empty and user isn't listed |
| 55 | * there, or if AllowGroups isn't empty and one of user's groups isn't |
| 56 | * listed there, false will be returned. |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 57 | * If the user's shell is not executable, false will be returned. |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 58 | * Otherwise true is returned. |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 59 | */ |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 60 | int |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 61 | allowed_user(struct passwd * pw) |
| 62 | { |
| 63 | struct stat st; |
Damien Miller | e7cf07c | 2001-03-20 09:15:57 +1100 | [diff] [blame] | 64 | char *shell; |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 65 | int i; |
| 66 | #ifdef WITH_AIXAUTHENTICATE |
| 67 | char *loginmsg; |
| 68 | #endif /* WITH_AIXAUTHENTICATE */ |
Kevin Steves | a58e0af | 2000-10-29 14:38:55 +0000 | [diff] [blame] | 69 | #if !defined(USE_PAM) && defined(HAVE_SHADOW_H) && \ |
Damien Miller | 62dd94b | 2000-09-23 14:26:32 +1100 | [diff] [blame] | 70 | !defined(DISABLE_SHADOW) && defined(HAS_SHADOW_EXPIRE) |
Kevin Steves | 7b61cfa | 2001-01-14 19:11:00 +0000 | [diff] [blame] | 71 | struct spwd *spw; |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 72 | |
| 73 | /* Shouldn't be called if pw is NULL, but better safe than sorry... */ |
Kevin Steves | 7b61cfa | 2001-01-14 19:11:00 +0000 | [diff] [blame] | 74 | if (!pw || !pw->pw_name) |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 75 | return 0; |
| 76 | |
Damien Miller | 1f335fb | 2000-06-26 11:31:33 +1000 | [diff] [blame] | 77 | spw = getspnam(pw->pw_name); |
Damien Miller | c708843 | 2000-07-02 18:44:54 +1000 | [diff] [blame] | 78 | if (spw != NULL) { |
| 79 | int days = time(NULL) / 86400; |
Damien Miller | 1f335fb | 2000-06-26 11:31:33 +1000 | [diff] [blame] | 80 | |
Damien Miller | c708843 | 2000-07-02 18:44:54 +1000 | [diff] [blame] | 81 | /* Check account expiry */ |
Damien Miller | 62dd94b | 2000-09-23 14:26:32 +1100 | [diff] [blame] | 82 | if ((spw->sp_expire >= 0) && (days > spw->sp_expire)) |
Damien Miller | c708843 | 2000-07-02 18:44:54 +1000 | [diff] [blame] | 83 | return 0; |
| 84 | |
| 85 | /* Check password expiry */ |
Kevin Steves | ef4eea9 | 2001-02-05 12:42:17 +0000 | [diff] [blame] | 86 | if ((spw->sp_lstchg >= 0) && (spw->sp_max >= 0) && |
Damien Miller | 606f880 | 2000-09-16 15:39:56 +1100 | [diff] [blame] | 87 | (days > (spw->sp_lstchg + spw->sp_max))) |
Damien Miller | c708843 | 2000-07-02 18:44:54 +1000 | [diff] [blame] | 88 | return 0; |
| 89 | } |
Damien Miller | 1f335fb | 2000-06-26 11:31:33 +1000 | [diff] [blame] | 90 | #else |
| 91 | /* Shouldn't be called if pw is NULL, but better safe than sorry... */ |
Kevin Steves | 7b61cfa | 2001-01-14 19:11:00 +0000 | [diff] [blame] | 92 | if (!pw || !pw->pw_name) |
Damien Miller | 1f335fb | 2000-06-26 11:31:33 +1000 | [diff] [blame] | 93 | return 0; |
| 94 | #endif |
| 95 | |
Damien Miller | ef7df54 | 2000-05-19 00:03:23 +1000 | [diff] [blame] | 96 | /* |
| 97 | * Get the shell from the password data. An empty shell field is |
| 98 | * legal, and means /bin/sh. |
| 99 | */ |
| 100 | shell = (pw->pw_shell[0] == '\0') ? _PATH_BSHELL : pw->pw_shell; |
| 101 | |
| 102 | /* deny if shell does not exists or is not executable */ |
| 103 | if (stat(shell, &st) != 0) |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 104 | return 0; |
| 105 | if (!((st.st_mode & S_IFREG) && (st.st_mode & (S_IXOTH|S_IXUSR|S_IXGRP)))) |
| 106 | return 0; |
| 107 | |
| 108 | /* Return false if user is listed in DenyUsers */ |
| 109 | if (options.num_deny_users > 0) { |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 110 | for (i = 0; i < options.num_deny_users; i++) |
| 111 | if (match_pattern(pw->pw_name, options.deny_users[i])) |
| 112 | return 0; |
| 113 | } |
| 114 | /* Return false if AllowUsers isn't empty and user isn't listed there */ |
| 115 | if (options.num_allow_users > 0) { |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 116 | for (i = 0; i < options.num_allow_users; i++) |
| 117 | if (match_pattern(pw->pw_name, options.allow_users[i])) |
| 118 | break; |
| 119 | /* i < options.num_allow_users iff we break for loop */ |
| 120 | if (i >= options.num_allow_users) |
| 121 | return 0; |
| 122 | } |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 123 | if (options.num_deny_groups > 0 || options.num_allow_groups > 0) { |
Kevin Steves | 7b61cfa | 2001-01-14 19:11:00 +0000 | [diff] [blame] | 124 | /* Get the user's group access list (primary and supplementary) */ |
| 125 | if (ga_init(pw->pw_name, pw->pw_gid) == 0) |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 126 | return 0; |
| 127 | |
Kevin Steves | 7b61cfa | 2001-01-14 19:11:00 +0000 | [diff] [blame] | 128 | /* Return false if one of user's groups is listed in DenyGroups */ |
| 129 | if (options.num_deny_groups > 0) |
| 130 | if (ga_match(options.deny_groups, |
| 131 | options.num_deny_groups)) { |
| 132 | ga_free(); |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 133 | return 0; |
Kevin Steves | 7b61cfa | 2001-01-14 19:11:00 +0000 | [diff] [blame] | 134 | } |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 135 | /* |
Kevin Steves | 7b61cfa | 2001-01-14 19:11:00 +0000 | [diff] [blame] | 136 | * Return false if AllowGroups isn't empty and one of user's groups |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 137 | * isn't listed there |
| 138 | */ |
Kevin Steves | 7b61cfa | 2001-01-14 19:11:00 +0000 | [diff] [blame] | 139 | if (options.num_allow_groups > 0) |
| 140 | if (!ga_match(options.allow_groups, |
| 141 | options.num_allow_groups)) { |
| 142 | ga_free(); |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 143 | return 0; |
Kevin Steves | 7b61cfa | 2001-01-14 19:11:00 +0000 | [diff] [blame] | 144 | } |
| 145 | ga_free(); |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | #ifdef WITH_AIXAUTHENTICATE |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 149 | if (loginrestrictions(pw->pw_name, S_RLOGIN, NULL, &loginmsg) != 0) { |
Damien Miller | d2c208a | 2000-05-17 22:00:02 +1000 | [diff] [blame] | 150 | if (loginmsg && *loginmsg) { |
| 151 | /* Remove embedded newlines (if any) */ |
| 152 | char *p; |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 153 | for (p = loginmsg; *p; p++) { |
Damien Miller | d2c208a | 2000-05-17 22:00:02 +1000 | [diff] [blame] | 154 | if (*p == '\n') |
| 155 | *p = ' '; |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 156 | } |
Damien Miller | d2c208a | 2000-05-17 22:00:02 +1000 | [diff] [blame] | 157 | /* Remove trailing newline */ |
| 158 | *--p = '\0'; |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 159 | log("Login restricted for %s: %.100s", pw->pw_name, loginmsg); |
Damien Miller | d2c208a | 2000-05-17 22:00:02 +1000 | [diff] [blame] | 160 | } |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 161 | return 0; |
Damien Miller | d2c208a | 2000-05-17 22:00:02 +1000 | [diff] [blame] | 162 | } |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 163 | #endif /* WITH_AIXAUTHENTICATE */ |
| 164 | |
| 165 | /* We found no reason not to let this user try to log on... */ |
| 166 | return 1; |
| 167 | } |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 168 | |
| 169 | Authctxt * |
| 170 | authctxt_new(void) |
| 171 | { |
Kevin Steves | ef4eea9 | 2001-02-05 12:42:17 +0000 | [diff] [blame] | 172 | Authctxt *authctxt = xmalloc(sizeof(*authctxt)); |
| 173 | memset(authctxt, 0, sizeof(*authctxt)); |
| 174 | return authctxt; |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 177 | void |
| 178 | auth_log(Authctxt *authctxt, int authenticated, char *method, char *info) |
| 179 | { |
| 180 | void (*authlog) (const char *fmt,...) = verbose; |
| 181 | char *authmsg; |
| 182 | |
| 183 | /* Raise logging level */ |
| 184 | if (authenticated == 1 || |
| 185 | !authctxt->valid || |
| 186 | authctxt->failures >= AUTH_FAIL_LOG || |
| 187 | strcmp(method, "password") == 0) |
| 188 | authlog = log; |
| 189 | |
| 190 | if (authctxt->postponed) |
| 191 | authmsg = "Postponed"; |
| 192 | else |
| 193 | authmsg = authenticated ? "Accepted" : "Failed"; |
| 194 | |
| 195 | authlog("%s %s for %s%.100s from %.200s port %d%s", |
| 196 | authmsg, |
| 197 | method, |
| 198 | authctxt->valid ? "" : "illegal user ", |
| 199 | authctxt->valid && authctxt->pw->pw_uid == 0 ? "ROOT" : authctxt->user, |
| 200 | get_remote_ipaddr(), |
| 201 | get_remote_port(), |
| 202 | info); |
| 203 | } |
| 204 | |
| 205 | /* |
Ben Lindstrom | d8a9021 | 2001-02-15 03:08:27 +0000 | [diff] [blame] | 206 | * Check whether root logins are disallowed. |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 207 | */ |
| 208 | int |
Ben Lindstrom | d8a9021 | 2001-02-15 03:08:27 +0000 | [diff] [blame] | 209 | auth_root_allowed(char *method) |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 210 | { |
Ben Lindstrom | d8a9021 | 2001-02-15 03:08:27 +0000 | [diff] [blame] | 211 | switch (options.permit_root_login) { |
| 212 | case PERMIT_YES: |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 213 | return 1; |
Ben Lindstrom | d8a9021 | 2001-02-15 03:08:27 +0000 | [diff] [blame] | 214 | break; |
| 215 | case PERMIT_NO_PASSWD: |
| 216 | if (strcmp(method, "password") != 0) |
| 217 | return 1; |
| 218 | break; |
| 219 | case PERMIT_FORCED_ONLY: |
| 220 | if (forced_command) { |
| 221 | log("Root login accepted for forced command."); |
| 222 | return 1; |
| 223 | } |
| 224 | break; |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 225 | } |
Ben Lindstrom | d8a9021 | 2001-02-15 03:08:27 +0000 | [diff] [blame] | 226 | log("ROOT LOGIN REFUSED FROM %.200s", get_remote_ipaddr()); |
| 227 | return 0; |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 228 | } |
Ben Lindstrom | bfb3a0e | 2001-06-05 20:25:05 +0000 | [diff] [blame] | 229 | |
| 230 | |
| 231 | /* |
| 232 | * Given a template and a passwd structure, build a filename |
| 233 | * by substituting % tokenised options. Currently, %% becomes '%', |
| 234 | * %h becomes the home directory and %u the username. |
| 235 | * |
| 236 | * This returns a buffer allocated by xmalloc. |
| 237 | */ |
| 238 | char * |
| 239 | expand_filename(const char *filename, struct passwd *pw) |
| 240 | { |
| 241 | Buffer buffer; |
| 242 | char *file; |
| 243 | const char *cp; |
| 244 | |
| 245 | /* |
| 246 | * Build the filename string in the buffer by making the appropriate |
| 247 | * substitutions to the given file name. |
| 248 | */ |
| 249 | buffer_init(&buffer); |
| 250 | for (cp = filename; *cp; cp++) { |
| 251 | if (cp[0] == '%' && cp[1] == '%') { |
| 252 | buffer_append(&buffer, "%", 1); |
| 253 | cp++; |
| 254 | continue; |
| 255 | } |
| 256 | if (cp[0] == '%' && cp[1] == 'h') { |
| 257 | buffer_append(&buffer, pw->pw_dir, strlen(pw->pw_dir)); |
| 258 | cp++; |
| 259 | continue; |
| 260 | } |
| 261 | if (cp[0] == '%' && cp[1] == 'u') { |
| 262 | buffer_append(&buffer, pw->pw_name, |
| 263 | strlen(pw->pw_name)); |
| 264 | cp++; |
| 265 | continue; |
| 266 | } |
| 267 | buffer_append(&buffer, cp, 1); |
| 268 | } |
| 269 | buffer_append(&buffer, "\0", 1); |
| 270 | |
| 271 | /* |
| 272 | * Ensure that filename starts anchored. If not, be backward |
| 273 | * compatible and prepend the '%h/' |
| 274 | */ |
| 275 | file = xmalloc(MAXPATHLEN); |
| 276 | cp = buffer_ptr(&buffer); |
| 277 | if (*cp != '/') |
| 278 | snprintf(file, MAXPATHLEN, "%s/%s", pw->pw_dir, cp); |
| 279 | else |
| 280 | strlcpy(file, cp, MAXPATHLEN); |
| 281 | |
| 282 | buffer_free(&buffer); |
| 283 | return file; |
| 284 | } |
| 285 | |
| 286 | char * |
| 287 | authorized_keys_file(struct passwd *pw) |
| 288 | { |
| 289 | return expand_filename(options.authorized_keys_file, pw); |
| 290 | } |
| 291 | |
| 292 | char * |
| 293 | authorized_keys_file2(struct passwd *pw) |
| 294 | { |
| 295 | return expand_filename(options.authorized_keys_file2, pw); |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * Check a given file for security. This is defined as all components |
| 300 | * of the path to the file must either be owned by either the owner of |
Ben Lindstrom | 60567ff | 2001-06-05 20:27:53 +0000 | [diff] [blame] | 301 | * of the file or root and no directories must be group or world writable. |
Ben Lindstrom | bfb3a0e | 2001-06-05 20:25:05 +0000 | [diff] [blame] | 302 | * |
| 303 | * XXX Should any specific check be done for sym links ? |
| 304 | * |
| 305 | * Takes an open file descriptor, the file name, a uid and and |
| 306 | * error buffer plus max size as arguments. |
| 307 | * |
| 308 | * Returns 0 on success and -1 on failure |
| 309 | */ |
| 310 | int |
| 311 | secure_filename(FILE *f, const char *file, uid_t uid, char *err, size_t errlen) |
| 312 | { |
| 313 | char buf[MAXPATHLEN]; |
| 314 | char *cp; |
| 315 | struct stat st; |
| 316 | |
| 317 | if (realpath(file, buf) == NULL) { |
| 318 | snprintf(err, errlen, "realpath %s failed: %s", file, |
| 319 | strerror(errno)); |
| 320 | return -1; |
| 321 | } |
| 322 | |
| 323 | /* check the open file to avoid races */ |
| 324 | if (fstat(fileno(f), &st) < 0 || |
| 325 | (st.st_uid != 0 && st.st_uid != uid) || |
| 326 | (st.st_mode & 022) != 0) { |
| 327 | snprintf(err, errlen, "bad ownership or modes for file %s", |
| 328 | buf); |
| 329 | return -1; |
| 330 | } |
| 331 | |
| 332 | /* for each component of the canonical path, walking upwards */ |
| 333 | for (;;) { |
| 334 | if ((cp = dirname(buf)) == NULL) { |
| 335 | snprintf(err, errlen, "dirname() failed"); |
| 336 | return -1; |
| 337 | } |
| 338 | strlcpy(buf, cp, sizeof(buf)); |
| 339 | |
| 340 | debug3("secure_filename: checking '%s'", buf); |
| 341 | if (stat(buf, &st) < 0 || |
| 342 | (st.st_uid != 0 && st.st_uid != uid) || |
| 343 | (st.st_mode & 022) != 0) { |
| 344 | snprintf(err, errlen, |
| 345 | "bad ownership or modes for directory %s", buf); |
| 346 | return -1; |
| 347 | } |
| 348 | |
| 349 | /* |
| 350 | * dirname should always complete with a "/" path, |
| 351 | * but we can be paranoid and check for "." too |
| 352 | */ |
| 353 | if ((strcmp("/", buf) == 0) || (strcmp(".", buf) == 0)) |
| 354 | break; |
| 355 | } |
| 356 | return 0; |
| 357 | } |