1 /* Copyright (c) 2008, 2009
2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4 * Micah Cowan (micah@cowan.name)
5 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
6 * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
7 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
8 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
9 * Copyright (c) 1987 Oliver Laumann
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program (see the file COPYING); if not, see
23 * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 ****************************************************************
31 #include <sys/types.h>
33 /* XXX: WHY IS THIS HERE?? :XXX */
37 # include <stdio.h> /* needed by <pwd.h> */
38 # endif /* _SEQUENT_ */
42 # endif /* SHADOWPW */
43 #endif /* CHECKLOGIN */
49 #include "screen.h" /* includes acls.h */
53 /************************************************************************
54 * user managing code, this does not really belong into the acl stuff *
55 ************************************************************************/
57 extern struct comm comms
[];
58 extern struct win
*windows
, **wtab
;
59 extern char NullStr
[];
60 extern char SockPath
[];
61 extern struct display
*display
, *displays
;
62 struct acluser
*users
;
65 int maxusercount
= 0; /* used in process.c: RC_MONITOR, RC_SILENCE */
67 /* record given user ids here */
68 static AclBits userbits
;
71 * rights a new unknown user will have on windows and cmds.
72 * These are changed by a "umask ?-..." command:
74 static char default_w_bit
[ACL_BITS_PER_WIN
] =
81 static char default_c_bit
[ACL_BITS_PER_CMD
] =
86 /* rights of all users per newly created window */
88 * are now stored per user (umask)
89 * static AclBits default_w_userbits[ACL_BITS_PER_WIN];
90 * static AclBits default_c_userbits[ACL_BITS_PER_CMD];
93 static int GrowBitfield
__P((AclBits
*, int, int, int));
94 static struct aclusergroup
**FindGroupPtr
__P((struct aclusergroup
**, struct acluser
*, int));
95 static int AclSetPermCmd
__P((struct acluser
*, char *, struct comm
*));
96 static int AclSetPermWin
__P((struct acluser
*, struct acluser
*, char *, struct win
*));
97 static int UserAcl
__P((struct acluser
*, struct acluser
**, int, char **));
98 static int UserAclCopy
__P((struct acluser
**, struct acluser
**));
102 GrowBitfield(bfp
, len
, delta
, defaultbit
)
104 int len
, delta
, defaultbit
;
109 if (!(n
= (AclBits
)calloc(1, (unsigned long)(&ACLBYTE((char *)0, len
+ delta
+ 1)))))
111 for (i
= 0; i
< (len
+ delta
); i
++)
113 if (((i
< len
) && (ACLBIT(i
) & ACLBYTE(o
, i
))) ||
114 ((i
>= len
) && (defaultbit
)))
115 ACLBYTE(n
, i
) |= ACLBIT(i
);
123 #endif /* MULTIUSER */
126 * Returns an nonzero Address. Its contents is either a User-ptr,
127 * or NULL which may be replaced by a User-ptr to create the entry.
135 for (u
= &users
; *u
; u
= &(*u
)->u_next
)
136 if (!strcmp((*u
)->u_name
, name
))
139 debug3("FindUserPtr %s %sfound, id %d\n", name
, (*u
)?"":"not ",
141 #else /* MULTIUSER */
142 debug2("FindUserPtr %s %sfound\n", name
, (*u
)?"":"not ");
143 #endif /* MULTIUSER */
147 int DefaultEsc
= -1; /* initialised by screen.c:main() */
148 int DefaultMetaEsc
= -1;
151 * Add a new user. His password may be NULL or "" if none. His name must not
152 * be "none", as this represents the NULL-pointer when dealing with groups.
153 * He has default rights, determined by umask.
156 UserAdd(name
, pass
, up
)
165 up
= FindUserPtr(name
);
169 (*up
)->u_password
= SaveStr(pass
);
170 return 1; /* he is already there */
172 if (strcmp("none", name
)) /* "none" is a reserved word */
173 *up
= (struct acluser
*)calloc(1, sizeof(struct acluser
));
175 return -1; /* he still does not exist */
177 (*up
)->u_plop
.buf
= NULL
;
178 (*up
)->u_plop
.len
= 0;
180 (*up
)->u_plop
.enc
= 0;
183 (*up
)->u_Esc
= DefaultEsc
;
184 (*up
)->u_MetaEsc
= DefaultMetaEsc
;
185 strncpy((*up
)->u_name
, name
, 20);
186 (*up
)->u_password
= NULL
;
188 (*up
)->u_password
= SaveStr(pass
);
189 if (!(*up
)->u_password
)
190 (*up
)->u_password
= NullStr
;
191 (*up
)->u_detachwin
= -1;
192 (*up
)->u_detachotherwin
= -1;
195 (*up
)->u_group
= NULL
;
196 /* now find an unused index */
197 for ((*up
)->u_id
= 0; (*up
)->u_id
< maxusercount
; (*up
)->u_id
++)
198 if (!(ACLBIT((*up
)->u_id
) & ACLBYTE(userbits
, (*up
)->u_id
)))
200 debug2("UserAdd %s id %d\n", name
, (*up
)->u_id
);
201 if ((*up
)->u_id
== maxusercount
)
207 debug2("growing all bitfields %d += %d\n", maxusercount
, USER_CHUNK
);
208 /* the bitfields are full, grow a chunk */
209 /* first, the used_uid_indicator: */
210 if (GrowBitfield(&userbits
, maxusercount
, USER_CHUNK
, 0))
212 free((char *)*up
); *up
= NULL
; return -1;
214 /* second, default command bits */
215 /* (only if we generate commands dynamically) */
217 for (j = 0; j < ACL_BITS_PER_CMD; j++)
218 if (GrowBitfield(&default_c_userbits[j], maxusercount, USER_CHUNK,
221 free((char *)*up); *up = NULL; return -1;
224 /* third, the bits for each commands */
225 for (j
= 0; j
<= RC_LAST
; j
++)
229 for (i
= 0; i
< ACL_BITS_PER_CMD
; i
++)
230 if (GrowBitfield(&comms
[j
].userbits
[i
], maxusercount
, USER_CHUNK
,
233 free((char *)*up
); *up
= NULL
; return -1;
236 /* fourth, default window creation bits per user */
237 for (u
= users
; u
!= *up
; u
= u
->u_next
)
239 for (j
= 0; j
< ACL_BITS_PER_WIN
; j
++)
241 if (GrowBitfield(&u
->u_umask_w_bits
[j
], maxusercount
, USER_CHUNK
,
244 free((char *)*up
); *up
= NULL
; return -1;
249 /* fifth, the bits for each window */
250 /* keep these in sync with NewWindowAcl() */
251 for (w
= windows
; w
; w
= w
->w_next
)
253 /* five a: the access control list */
254 for (j
= 0; j
< ACL_BITS_PER_WIN
; j
++)
255 if (GrowBitfield(&w
->w_userbits
[j
], maxusercount
, USER_CHUNK
,
258 free((char *)*up
); *up
= NULL
; return -1;
260 /* five b: the activity notify list */
261 /* five c: the silence notify list */
262 if (GrowBitfield(&w
->w_mon_notify
, maxusercount
, USER_CHUNK
, 0) ||
263 GrowBitfield(&w
->w_lio_notify
, maxusercount
, USER_CHUNK
, 0))
265 free((char *)*up
); *up
= NULL
; return -1;
268 maxusercount
+= USER_CHUNK
;
271 /* mark the user-entry as "in-use" */
272 ACLBYTE(userbits
, (*up
)->u_id
) |= ACLBIT((*up
)->u_id
);
274 /* user id 0 is the session creator, he has all rights */
275 if ((*up
)->u_id
== 0)
276 AclSetPerm(NULL
, *up
, "+a", "#?");
278 /* user nobody has a fixed set of rights: */
279 if (!strcmp((*up
)->u_name
, "nobody"))
281 AclSetPerm(NULL
, *up
, "-rwx", "#?");
282 AclSetPerm(NULL
, *up
, "+x", "su");
283 AclSetPerm(NULL
, *up
, "+x", "detach");
284 AclSetPerm(NULL
, *up
, "+x", "displays");
285 AclSetPerm(NULL
, *up
, "+x", "version");
290 * Give default_w_bit's for all users,
291 * but allow himself everything on "his" windows.
293 for (j
= 0; j
< ACL_BITS_PER_WIN
; j
++)
295 if (GrowBitfield(&(*up
)->u_umask_w_bits
[j
], 0, maxusercount
,
298 free((char *)*up
); *up
= NULL
; return -1;
300 ACLBYTE((*up
)->u_umask_w_bits
[j
], (*up
)->u_id
) |= ACLBIT((*up
)->u_id
);
302 #else /* MULTIUSER */
303 debug1("UserAdd %s\n", name
);
304 #endif /* MULTIUSER */
309 /* change user's password */
311 UserSetPass(name
, pass
, up
)
316 up
= FindUserPtr(name
);
318 return UserAdd(name
, pass
, up
);
319 if (!strcmp(name
, "nobody")) /* he remains without password */
321 strncpy((*up
)->u_password
, pass
? pass
: "", 20);
322 (*up
)->u_password
[20] = '\0';
328 * Remove a user from the list.
329 * Destroy all his permissions and completely detach him from the session.
340 struct display
*old
, *next
;
343 up
= FindUserPtr(name
);
345 return -1; /* he who does not exist cannot be removed */
347 for (display
= displays
; display
; display
= next
)
349 next
= display
->d_next
; /* read the next ptr now, Detach may zap it. */
360 for (up
= &users
; *up
; up
= &(*up
)->u_next
)
362 /* unlink all group references to this user */
363 struct aclusergroup
**g
= &(*up
)->u_group
;
369 struct aclusergroup
*next
= (*g
)->next
;
378 ACLBYTE(userbits
, u
->u_id
) &= ~ACLBIT(u
->u_id
);
379 /* restore the bits in his slot to default: */
380 AclSetPerm(NULL
, u
, default_w_bit
[ACL_READ
] ? "+r" : "-r", "#");
381 AclSetPerm(NULL
, u
, default_w_bit
[ACL_WRITE
]? "+w" : "-w", "#");
382 AclSetPerm(NULL
, u
, default_w_bit
[ACL_EXEC
] ? "+x" : "-x", "#");
383 AclSetPerm(NULL
, u
, default_c_bit
[ACL_EXEC
] ? "+x" : "-x", "?");
384 for (i
= 0; i
< ACL_BITS_PER_WIN
; i
++)
385 free((char *)u
->u_umask_w_bits
[i
]);
386 #endif /* MULTIUSER */
387 debug1("FREEING user structure for %s\n", u
->u_name
);
389 UserFreeCopyBuffer(u
);
394 debug("Last user deleted. Feierabend.\n");
395 Finit(0); /* Destroying whole session. Noone could ever attach again. */
404 * returns 0 if the copy buffer was really deleted.
405 * Also removes any references into the users copybuffer
408 UserFreeCopyBuffer(u
)
416 for (w
= windows
; w
; w
= w
->w_next
)
419 if (pa
->pa_pasteptr
>= u
->u_plop
.buf
&&
420 pa
->pa_pasteptr
- u
->u_plop
.buf
< u
->u_plop
.len
)
423 free((char *)u
->u_plop
.buf
);
428 #endif /* COPY_PASTE */
432 * Traverses group nodes. It searches for a node that references user u.
433 * If recursive is true, nodes found in the users are also searched using
434 * depth first method. If none of the nodes references u, the address of
435 * the last next pointer is returned. This address will contain NULL.
437 static struct aclusergroup
**
438 FindGroupPtr(gp
, u
, recursive
)
439 struct aclusergroup
**gp
;
443 struct aclusergroup
**g
;
445 ASSERT(recursive
< 1000); /* Ouch, cycle detection failed */
449 return gp
; /* found him here. */
451 *(g
= FindGroupPtr(&(*gp
)->u
->u_group
, u
, recursive
+ 1)))
452 return g
; /* found him there. */
455 return gp
; /* *gp is NULL */
459 * Returns nonzero if failed or already linked.
460 * Both users are created on demand.
461 * Cyclic links are prevented.
464 AclLinkUser(from
, to
)
467 struct acluser
**u1
, **u2
;
468 struct aclusergroup
**g
;
470 if (!*(u1
= FindUserPtr(from
)) && UserAdd(from
, NULL
, u1
))
472 if (!*(u2
= FindUserPtr(to
)) && UserAdd(to
, NULL
, u2
))
473 return -1; /* hmm, could not find both users. */
475 if (*FindGroupPtr(&(*u2
)->u_group
, *u1
, 1))
476 return 1; /* cyclic link detected! */
477 if (*(g
= FindGroupPtr(&(*u1
)->u_group
, *u2
, 0)))
478 return 2; /* aha, we are already linked! */
480 if (!(*g
= (struct aclusergroup
*)malloc(sizeof(struct aclusergroup
))))
481 return -1; /* Could not alloc link. Poor screen */
488 * The user pointer stored at *up will be substituted by a pointer
489 * to the named user's structure, if passwords match.
490 * returns NULL if successfull, an static error string otherwise
493 DoSu(up
, name
, pw1
, pw2
)
495 char *name
, *pw1
, *pw2
;
500 if (!(u
= *FindUserPtr(name
)))
512 if (!(pp
= getpwnam(name
)))
514 debug1("getpwnam(\"%s\") failed\n", name
);
515 if (!(pw1
&& *pw1
&& *pw1
!= '\377'))
517 debug("no unix account, no screen passwd\n");
522 pass
= pp
->pw_passwd
;
524 for (t
= 0; t
< 13; t
++)
527 if (!(c
== '.' || c
== '/' ||
528 (c
>= '0' && c
<= '9') ||
529 (c
>= 'a' && c
<= 'z') ||
530 (c
>= 'A' && c
<= 'Z')))
535 if (!(ss
= getspnam(name
)))
537 debug1("getspnam(\"%s\") failed\n", name
);
543 #endif /* SHADOWPW */
545 if (pw2
&& *pw2
&& *pw2
!= '\377') /* provided a system password */
547 if (!*pass
|| /* but needed none */
548 strcmp(crypt(pw2
, pass
), pass
))
550 debug("System password mismatch\n");
554 else /* no pasword provided */
555 if (*pass
) /* but need one */
558 if (pw1
&& *pw1
&& *pw1
!= '\377') /* provided a screen password */
560 if (!*u
->u_password
|| /* but needed none */
561 strcmp(crypt(pw1
, u
->u_password
), u
->u_password
))
563 debug("screen password mismatch\n");
567 else /* no pasword provided */
568 if (*u
->u_password
) /* but need one */
572 debug2("syslog(LOG_NOTICE, \"screen %s: \"su %s\" ", SockPath
, name
);
573 debug2("%s for \"%s\"\n", sorry
? "failed" : "succeded", (*up
)->u_name
);
576 openlog("screen", LOG_PID
);
578 openlog("screen", LOG_PID
, LOG_AUTH
);
580 syslog(LOG_NOTICE
, "%s: \"su %s\" %s for \"%s\"", SockPath
, name
,
581 sorry
? "failed" : "succeded", (*up
)->u_name
);
584 debug("NOT LOGGED.\n");
585 #endif /* NOSYSLOG */
590 *up
= u
; /* substitute user now */
593 #endif /* MULTIUSER */
595 /************************************************************************
596 * end of user managing code *
597 ************************************************************************/
602 /* This gives the users default rights to the new window w created by u */
610 debug2("NewWindowAcl %s's umask_w_bits for window %d\n",
611 u
? u
->u_name
: "everybody", w
->w_number
);
613 /* keep these in sync with UserAdd part five. */
614 if (GrowBitfield(&w
->w_mon_notify
, 0, maxusercount
, 0) ||
615 GrowBitfield(&w
->w_lio_notify
, 0, maxusercount
, 0))
617 for (j
= 0; j
< ACL_BITS_PER_WIN
; j
++)
619 /* we start with len 0 for the new bitfield size and add maxusercount */
620 if (GrowBitfield(&w
->w_userbits
[j
], 0, maxusercount
, 0))
623 free((char *)w
->w_userbits
[j
]);
624 free((char *)w
->w_mon_notify
);
625 free((char *)w
->w_lio_notify
);
628 for (i
= 0; i
< maxusercount
; i
++)
629 if (u
? (ACLBIT(i
) & ACLBYTE(u
->u_umask_w_bits
[j
], i
)) :
631 ACLBYTE(w
->w_userbits
[j
], i
) |= ACLBIT(i
);
642 for (i
= 0; i
< ACL_BITS_PER_WIN
; i
++)
643 free((char *)w
->w_userbits
[i
]);
644 free((char *)w
->w_mon_notify
);
645 free((char *)w
->w_lio_notify
);
649 /* if mode starts with '-' we remove the users exec bit for cmd */
651 * NOTE: before you make this function look the same as
652 * AclSetPermWin, try to merge both functions.
655 AclSetPermCmd(u
, mode
, cmd
)
676 /* debug3("AclSetPermCmd %s %s %s\n", u->u_name, mode, cmd->name); */
678 ACLBYTE(cmd
->userbits
[ACL_EXEC
], u
->u_id
) &= ~ACLBIT(u
->u_id
);
680 ACLBYTE(cmd
->userbits
[ACL_EXEC
], u
->u_id
) |= ACLBIT(u
->u_id
);
692 /* mode strings of the form +rwx -w+rx r -wx are parsed and evaluated */
695 * releases a writelock on window 2 held by user nerd.
696 * Letter n allows network access on a window.
697 * uu should be NULL, except if you want to change his umask.
700 AclSetPermWin(uu
, u
, mode
, win
)
701 struct acluser
*u
, *uu
;
712 debug3("AclSetPermWin %s UMASK %s %s\n", uu
->u_name
, u
->u_name
, mode
);
713 bitarray
= uu
->u_umask_w_bits
;
718 bitarray
= win
->w_userbits
;
719 debug3("AclSetPermWin %s %s %d\n", u
->u_name
, mode
, win
->w_number
);
733 bits
= (1 << ACL_READ
);
736 bits
= (1 << ACL_WRITE
);
739 bits
= (1 << ACL_EXEC
);
742 bits
= (1 << ACL_BITS_PER_WIN
) - 1;
747 for (bit
= 0; bit
< ACL_BITS_PER_WIN
; bit
++)
749 if (!(bits
& (1 << bit
)))
752 ACLBYTE(bitarray
[bit
], u
->u_id
) &= ~ACLBIT(u
->u_id
);
754 ACLBYTE(bitarray
[bit
], u
->u_id
) |= ACLBIT(u
->u_id
);
755 if (!uu
&& (win
->w_wlockuser
== u
) && neg
&& (bit
== ACL_WRITE
))
757 debug2("%s lost writelock on win %d\n", u
->u_name
, win
->w_number
);
758 win
->w_wlockuser
= NULL
;
759 if (win
->w_wlock
== WLOCK_ON
)
760 win
->w_wlock
= WLOCK_AUTO
;
764 if (uu
&& u
->u_name
[0] == '?' && u
->u_name
[1] == '\0')
767 * It is Mr. '?', the unknown user. He deserves special treatment as
768 * he defines the defaults. Sorry, this is global, not per user.
772 debug1("AclSetPermWin: default_w_bits '%s'.\n", mode
);
773 for (bit
= 0; bit
< ACL_BITS_PER_WIN
; bit
++)
775 (ACLBYTE(bitarray
[bit
], u
->u_id
) & ACLBIT(u
->u_id
)) ? 1 : 0;
780 * Hack. I do not want to duplicate all the above code for
781 * AclSetPermCmd. This asumes that there are not more bits
782 * per cmd than per win.
784 debug1("AclSetPermWin: default_c_bits '%s'.\n", mode
);
785 for (bit
= 0; bit
< ACL_BITS_PER_CMD
; bit
++)
787 (ACLBYTE(bitarray
[bit
], u
->u_id
) & ACLBIT(u
->u_id
)) ? 1 : 0;
789 UserDel(u
->u_name
, NULL
);
795 * String is broken down into comand and window names, mode applies
796 * A command name matches first, so do not use these as window names.
797 * uu should be NULL, except if you want to change his umask.
800 AclSetPerm(uu
, u
, mode
, s
)
801 struct acluser
*uu
, *u
;
808 debug3("AclSetPerm(uu, user '%s', mode '%s', object '%s')\n",
814 case '*': /* all windows and all commands */
815 return AclSetPerm(uu
, u
, mode
, "#?");
817 if (uu
) /* window umask or .. */
818 AclSetPermWin(uu
, u
, mode
, (struct win
*)1);
819 else /* .. or all windows */
820 for (w
= windows
; w
; w
= w
->w_next
)
821 AclSetPermWin((struct acluser
*)0, u
, mode
, w
);
825 if (uu
) /* command umask or .. */
826 AclSetPermWin(uu
, u
, mode
, (struct win
*)0);
827 else /* .. or all commands */
828 for (i
= 0; i
<= RC_LAST
; i
++)
829 AclSetPermCmd(u
, mode
, &comms
[i
]);
833 for (p
= s
; *p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ','; p
++)
837 if ((i
= FindCommnr(s
)) != RC_ILLEGAL
)
838 AclSetPermCmd(u
, mode
, &comms
[i
]);
839 else if (((i
= WindowByNoN(s
)) >= 0) && wtab
[i
])
840 AclSetPermWin((struct acluser
*)0, u
, mode
, wtab
[i
]);
842 /* checking group name */
853 * Generic ACL Manager:
855 * This handles acladd and aclchg identical.
856 * With 2 or 4 parameters, the second parameter is a password.
857 * With 3 or 4 parameters the last two parameters specify the permissions
858 * else user is added with full permissions.
859 * With 1 parameter the users permissions are copied from user *argv.
860 * Unlike the other cases, u->u_name should not match *argv here.
861 * uu should be NULL, except if you want to change his umask.
864 UserAcl(uu
, u
, argc
, argv
)
865 struct acluser
*uu
, **u
;
869 if ((*u
&& !strcmp((*u
)->u_name
, "nobody")) ||
870 (argc
> 1 && !strcmp(argv
[0], "nobody")))
871 return -1; /* do not change nobody! */
876 debug2("UserAcl: user '%s', password '%s':", argv
[0], argv
[1]);
877 return (UserAdd(argv
[0], argv
[1], u
) < 0) ||
878 AclSetPerm(uu
, *u
, argv
[2], argv
[3]);
880 debug1("UserAcl: user '%s', no password:", argv
[0]);
881 return (UserAdd(argv
[0], NULL
, u
) < 0) ||
882 AclSetPerm(uu
, *u
, argv
[1], argv
[2]);
884 debug2("UserAcl: user '%s', password '%s'\n", argv
[0], argv
[1]);
885 return UserAdd(argv
[0], argv
[1], u
) < 0;
887 debug1("UserAcl: user '%s', no password:", argv
[0]);
888 return (UserAdd(argv
[0], NULL
, u
) < 0) ||
889 AclSetPerm(uu
, *u
, "+a", "#?");
896 UserAclCopy(to_up
, from_up
)
897 struct acluser
**to_up
, **from_up
;
900 int i
, j
, to_id
, from_id
;
902 if (!*to_up
|| !*from_up
)
904 debug2("UserAclCopy: from user '%s' to user '%s'\n",
905 (*from_up
)->u_name
, (*to_up
)->u_name
);
906 if ((to_id
= (*to_up
)->u_id
) == (from_id
= (*from_up
)->u_id
))
908 for (w
= windows
; w
; w
= w
->w_next
)
910 for (i
= 0; i
< ACL_BITS_PER_WIN
; i
++)
912 if (ACLBYTE(w
->w_userbits
[i
], from_id
) & ACLBIT(from_id
))
913 ACLBYTE(w
->w_userbits
[i
], to_id
) |= ACLBIT(to_id
);
916 ACLBYTE(w
->w_userbits
[i
], to_id
) &= ~ACLBIT(to_id
);
917 if ((w
->w_wlockuser
== *to_up
) && (i
== ACL_WRITE
))
919 debug2("%s lost wlock on win %d\n",
920 (*to_up
)->u_name
, w
->w_number
);
921 w
->w_wlockuser
= NULL
;
922 if (w
->w_wlock
== WLOCK_ON
)
923 w
->w_wlock
= WLOCK_AUTO
;
928 for (j
= 0; j
<= RC_LAST
; j
++)
930 for (i
= 0; i
< ACL_BITS_PER_CMD
; i
++)
932 if (ACLBYTE(comms
[j
].userbits
[i
], from_id
) & ACLBIT(from_id
))
933 ACLBYTE(comms
[j
].userbits
[i
], to_id
) |= ACLBIT(to_id
);
935 ACLBYTE(comms
[j
].userbits
[i
], to_id
) &= ~ACLBIT(to_id
);
944 * user [password] [+rwx #?]
945 * * [password] [+rwx #?]
946 * user1,user2,user3 [password] [+rwx #?]
947 * user1,user2,user3=user
948 * uu should be NULL, except if you want to change his umask.
951 UsersAcl(uu
, argc
, argv
)
958 struct acluser
**cf_u
= NULL
;
966 if (*s
++ == '=') p
= s
;
970 cf_u
= FindUserPtr(p
);
974 if (argv
[0][0] == '*' && argv
[0][1] == '\0')
978 debug("all users acls.\n");
979 for (u
= &users
; *u
; u
= &(*u
)->u_next
)
980 if (strcmp("nobody", (*u
)->u_name
) &&
982 ((r
= UserAclCopy(u
, cf_u
)) < 0) :
983 ((r
= UserAcl(uu
, u
, argc
, argv
)) < 0)))
990 for (s
= argv
[0]; *s
&& *s
!=' ' && *s
!='\t' && *s
!=',' && *s
!='='; s
++)
992 *s
? (*s
++ = '\0') : (*s
= '\0');
993 debug2("UsersAcl(uu, \"%s\", argc=%d)\n", argv
[0], argc
);
995 ((r
= UserAclCopy(FindUserPtr(argv
[0]), cf_u
)) < 0) :
996 ((r
= UserAcl(uu
, FindUserPtr(argv
[0]), argc
, argv
)) < 0))
998 } while (*(argv
[0] = s
));
1003 * Preprocess argments, so that umask can be set with UsersAcl
1005 * all current users umask ±rwxn
1006 * one specific user umask user1±rwxn
1007 * several users umask user1,user2,...±rwxn
1008 * default_w_bits umask ?±rwxn
1009 * default_c_bits umask ??±rwxn
1012 AclUmask(u
, str
, errp
)
1021 /* split str into user and bits section. */
1022 for (p
= str
; *p
; p
++)
1023 if ((c
= *p
) == '+' || c
== '-')
1027 *errp
= "Bad argument. Should be ``[user[,user...]{+|-}rwxn''.";
1030 strncpy(mode
, p
, 15);
1034 /* construct argument vector */
1035 if (!strcmp("??", str
))
1043 av
[0] = *str
? str
: "*";
1045 if (UsersAcl(u
, 3, av
))
1047 *errp
= "UsersAcl failed. Hmmm.";
1059 debug2("AclWinSwap(%d, %d) NOP.\n", a
, b
);
1062 struct acluser
*EffectiveAclUser
= NULL
; /* hook for AT command permission */
1065 AclCheckPermWin(u
, mode
, w
)
1072 if (mode
< 0 || mode
>= ACL_BITS_PER_WIN
)
1074 if (EffectiveAclUser
)
1076 debug1("AclCheckPermWin: WARNING user %s overridden!\n", u
->u_name
);
1077 u
= EffectiveAclUser
;
1079 ok
= ACLBYTE(w
->w_userbits
[mode
], u
->u_id
) & ACLBIT(u
->u_id
);
1080 debug3("AclCheckPermWin(%s, %d, %d) = ", u
->u_name
, mode
, w
->w_number
);
1084 struct aclusergroup
**g
= &u
->u_group
;
1085 struct acluser
*saved_eff
= EffectiveAclUser
;
1087 EffectiveAclUser
= NULL
;
1090 if (!AclCheckPermWin((*g
)->u
, mode
, w
))
1094 EffectiveAclUser
= saved_eff
;
1098 debug1("%d\n", !ok
);
1103 AclCheckPermCmd(u
, mode
, c
)
1110 if (mode
< 0 || mode
>= ACL_BITS_PER_CMD
)
1112 if (EffectiveAclUser
)
1114 debug1("AclCheckPermCmd: WARNING user %s overridden!\n", u
->u_name
);
1115 u
= EffectiveAclUser
;
1117 ok
= ACLBYTE(c
->userbits
[mode
], u
->u_id
) & ACLBIT(u
->u_id
);
1118 debug3("AclCheckPermCmd(%s %d %s) = ", u
->u_name
, mode
, c
->name
);
1121 struct aclusergroup
**g
= &u
->u_group
;
1122 struct acluser
*saved_eff
= EffectiveAclUser
;
1124 EffectiveAclUser
= NULL
;
1127 if (!AclCheckPermCmd((*g
)->u
, mode
, c
))
1131 EffectiveAclUser
= saved_eff
;
1135 debug1("%d\n", !ok
);
1139 #endif /* MULTIUSER */