login_class.c (25670) | login_class.c (36351) |
---|---|
1/*- 2 * Copyright (c) 1996 by 3 * Sean Eric Fagan <sef@kithrup.com> 4 * David Nugent <davidn@blaze.net.au> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, is permitted provided that the following conditions --- 7 unchanged lines hidden (view full) --- 16 * 3. This work was done expressly for inclusion into FreeBSD. Other use 17 * is permitted provided this notation is included. 18 * 4. Absolutely no warranty of function or purpose is made by the authors. 19 * 5. Modifications may be freely made to this file providing the above 20 * conditions are met. 21 * 22 * High-level routines relating to use of the user capabilities database 23 * | 1/*- 2 * Copyright (c) 1996 by 3 * Sean Eric Fagan <sef@kithrup.com> 4 * David Nugent <davidn@blaze.net.au> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, is permitted provided that the following conditions --- 7 unchanged lines hidden (view full) --- 16 * 3. This work was done expressly for inclusion into FreeBSD. Other use 17 * is permitted provided this notation is included. 18 * 4. Absolutely no warranty of function or purpose is made by the authors. 19 * 5. Modifications may be freely made to this file providing the above 20 * conditions are met. 21 * 22 * High-level routines relating to use of the user capabilities database 23 * |
24 * $Id: login_class.c,v 1.5 1997/02/22 15:08:22 peter Exp $ | 24 * $Id: login_class.c,v 1.6 1997/05/10 18:55:38 davidn Exp $ |
25 */ 26 27#include <stdio.h> 28#include <stdlib.h> 29#include <string.h> 30#include <unistd.h> 31#include <errno.h> 32#include <sys/types.h> 33#include <sys/stat.h> 34#include <sys/time.h> 35#include <sys/resource.h> 36#include <fcntl.h> 37#include <pwd.h> 38#include <syslog.h> 39#include <login_cap.h> 40#include <paths.h> | 25 */ 26 27#include <stdio.h> 28#include <stdlib.h> 29#include <string.h> 30#include <unistd.h> 31#include <errno.h> 32#include <sys/types.h> 33#include <sys/stat.h> 34#include <sys/time.h> 35#include <sys/resource.h> 36#include <fcntl.h> 37#include <pwd.h> 38#include <syslog.h> 39#include <login_cap.h> 40#include <paths.h> |
41#include <sys/rtprio.h> |
|
41 42 43#undef UNKNOWN 44#define UNKNOWN "su" 45 46 47static struct login_res { 48 const char *what; --- 261 unchanged lines hidden (view full) --- 310 */ 311 312int 313setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned int flags) 314{ 315 quad_t p; 316 mode_t mymask; 317 login_cap_t *llc = NULL; | 42 43 44#undef UNKNOWN 45#define UNKNOWN "su" 46 47 48static struct login_res { 49 const char *what; --- 261 unchanged lines hidden (view full) --- 311 */ 312 313int 314setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned int flags) 315{ 316 quad_t p; 317 mode_t mymask; 318 login_cap_t *llc = NULL; |
319 struct rtprio rtp; |
|
318 319 if (lc == NULL) { 320 if (pwd != NULL && (lc = login_getpwclass(pwd)) != NULL) 321 llc = lc; /* free this when we're done */ 322 } 323 324 if (flags & LOGIN_SETPATH) 325 pathvars[0].def = uid ? _PATH_DEFPATH : _PATH_STDPATH; 326 327 /* we need a passwd entry to set these */ 328 if (pwd == NULL) 329 flags &= ~(LOGIN_SETGROUP | LOGIN_SETLOGIN); 330 331 /* Set the process priority */ 332 if (flags & LOGIN_SETPRIORITY) { 333 p = login_getcapnum(lc, "priority", LOGIN_DEFPRI, LOGIN_DEFPRI); 334 | 320 321 if (lc == NULL) { 322 if (pwd != NULL && (lc = login_getpwclass(pwd)) != NULL) 323 llc = lc; /* free this when we're done */ 324 } 325 326 if (flags & LOGIN_SETPATH) 327 pathvars[0].def = uid ? _PATH_DEFPATH : _PATH_STDPATH; 328 329 /* we need a passwd entry to set these */ 330 if (pwd == NULL) 331 flags &= ~(LOGIN_SETGROUP | LOGIN_SETLOGIN); 332 333 /* Set the process priority */ 334 if (flags & LOGIN_SETPRIORITY) { 335 p = login_getcapnum(lc, "priority", LOGIN_DEFPRI, LOGIN_DEFPRI); 336 |
335 p = (p < PRIO_MIN || p > PRIO_MAX) ? LOGIN_DEFPRI : p; 336 if (setpriority(PRIO_PROCESS, 0, (int)p) != 0) 337 syslog(LOG_WARNING, "setpriority '%s' (%s): %m", 338 pwd->pw_name, lc ? lc->lc_class : LOGIN_DEFCLASS); | 337 if(p > PRIO_MAX) { 338 rtp.type = RTP_PRIO_IDLE; 339 rtp.prio = p - PRIO_MAX - 1; 340 p = (rtp.prio > RTP_PRIO_MAX) ? 31 : p; 341 if(rtprio(RTP_SET, 0, &rtp)) 342 syslog(LOG_WARNING, "rtprio '%s' (%s): %m", 343 pwd->pw_name, lc ? lc->lc_class : LOGIN_DEFCLASS); 344 } else if(p < PRIO_MIN) { 345 rtp.type = RTP_PRIO_REALTIME; 346 rtp.prio = abs(p - PRIO_MIN + RTP_PRIO_MAX); 347 p = (rtp.prio > RTP_PRIO_MAX) ? 1 : p; 348 if(rtprio(RTP_SET, 0, &rtp)) 349 syslog(LOG_WARNING, "rtprio '%s' (%s): %m", 350 pwd->pw_name, lc ? lc->lc_class : LOGIN_DEFCLASS); 351 } else { 352 if (setpriority(PRIO_PROCESS, 0, (int)p) != 0) 353 syslog(LOG_WARNING, "setpriority '%s' (%s): %m", 354 pwd->pw_name, lc ? lc->lc_class : LOGIN_DEFCLASS); 355 } |
339 } 340 341 /* Setup the user's group permissions */ 342 if (flags & LOGIN_SETGROUP) { 343 if (setgid(pwd->pw_gid) != 0) { 344 syslog(LOG_ERR, "setgid(%ld): %m", (long)pwd->pw_gid); 345 login_close(llc); 346 return -1; --- 41 unchanged lines hidden --- | 356 } 357 358 /* Setup the user's group permissions */ 359 if (flags & LOGIN_SETGROUP) { 360 if (setgid(pwd->pw_gid) != 0) { 361 syslog(LOG_ERR, "setgid(%ld): %m", (long)pwd->pw_gid); 362 login_close(llc); 363 return -1; --- 41 unchanged lines hidden --- |