acl_support.c (208785) | acl_support.c (209147) |
---|---|
1/*- 2 * Copyright (c) 1999-2001, 2008 Robert N. M. Watson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 */ 26/* 27 * Support functionality for the POSIX.1e ACL interface 28 * These calls are intended only to be called within the library. 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1999-2001, 2008 Robert N. M. Watson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 */ 26/* 27 * Support functionality for the POSIX.1e ACL interface 28 * These calls are intended only to be called within the library. 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/lib/libc/posix1e/acl_support.c 208785 2010-06-03 14:29:17Z trasz $"); | 32__FBSDID("$FreeBSD: head/lib/libc/posix1e/acl_support.c 209147 2010-06-14 02:26:13Z kientzle $"); |
33 34#include <sys/types.h> 35#include "namespace.h" 36#include <sys/acl.h> 37#include "un-namespace.h" 38#include <errno.h> 39#include <grp.h> 40#include <pwd.h> --- 223 unchanged lines hidden (view full) --- 264 return (EINVAL); 265 266 if (count_other != 1) 267 return (EINVAL); 268 269 return (0); 270} 271 | 33 34#include <sys/types.h> 35#include "namespace.h" 36#include <sys/acl.h> 37#include "un-namespace.h" 38#include <errno.h> 39#include <grp.h> 40#include <pwd.h> --- 223 unchanged lines hidden (view full) --- 264 return (EINVAL); 265 266 if (count_other != 1) 267 return (EINVAL); 268 269 return (0); 270} 271 |
272 | |
273/* | 272/* |
274 * Given a uid/gid, return a username/groupname for the text form of an ACL. 275 * Note that we truncate user and group names, rather than error out, as 276 * this is consistent with other tools manipulating user and group names. 277 * XXX NOT THREAD SAFE, RELIES ON GETPWUID, GETGRGID 278 * XXX USES *PW* AND *GR* WHICH ARE STATEFUL AND THEREFORE THIS ROUTINE 279 * MAY HAVE SIDE-EFFECTS 280 */ 281int 282_posix1e_acl_id_to_name(acl_tag_t tag, uid_t id, ssize_t buf_len, char *buf, 283 int flags) 284{ 285 struct group *g; 286 struct passwd *p; 287 int i; 288 289 switch(tag) { 290 case ACL_USER: 291 if (flags & ACL_TEXT_NUMERIC_IDS) 292 p = NULL; 293 else 294 p = getpwuid(id); 295 if (!p) 296 i = snprintf(buf, buf_len, "%d", id); 297 else 298 i = snprintf(buf, buf_len, "%s", p->pw_name); 299 300 if (i < 0) { 301 errno = ENOMEM; 302 return (-1); 303 } 304 return (0); 305 306 case ACL_GROUP: 307 if (flags & ACL_TEXT_NUMERIC_IDS) 308 g = NULL; 309 else 310 g = getgrgid(id); 311 if (g == NULL) 312 i = snprintf(buf, buf_len, "%d", id); 313 else 314 i = snprintf(buf, buf_len, "%s", g->gr_name); 315 316 if (i < 0) { 317 errno = ENOMEM; 318 return (-1); 319 } 320 return (0); 321 322 default: 323 return (EINVAL); 324 } 325} 326 327/* | |
328 * Given a right-shifted permission (i.e., direct ACL_PERM_* mask), fill 329 * in a string describing the permissions. 330 */ 331int 332_posix1e_acl_perm_to_string(acl_perm_t perm, ssize_t buf_len, char *buf) 333{ 334 335 if (buf_len < _POSIX1E_ACL_STRING_PERM_MAXSIZE + 1) { --- 138 unchanged lines hidden --- | 273 * Given a right-shifted permission (i.e., direct ACL_PERM_* mask), fill 274 * in a string describing the permissions. 275 */ 276int 277_posix1e_acl_perm_to_string(acl_perm_t perm, ssize_t buf_len, char *buf) 278{ 279 280 if (buf_len < _POSIX1E_ACL_STRING_PERM_MAXSIZE + 1) { --- 138 unchanged lines hidden --- |