OSDN Git Service

* exceptions.cc (set_signal_mask): Remove useless debugging output.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / pwdgrp.h
1 /* pwdgrp.h
2
3    Copyright 2001, 2002, 2003 Red Hat inc.
4
5    Stuff common to pwd and grp handling.
6
7 This file is part of Cygwin.
8
9 This software is a copyrighted work licensed under the terms of the
10 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
11 details. */
12
13 /* These functions are needed to allow searching and walking through
14    the passwd and group lists */
15 extern struct passwd *internal_getpwsid (cygpsid &);
16 extern struct passwd *internal_getpwnam (const char *, bool = FALSE);
17 extern struct passwd *internal_getpwuid (__uid32_t, bool = FALSE);
18 extern struct __group32 *internal_getgrsid (cygpsid &);
19 extern struct __group32 *internal_getgrgid (__gid32_t gid, bool = FALSE);
20 extern struct __group32 *internal_getgrnam (const char *, bool = FALSE);
21 extern struct __group32 *internal_getgrent (int);
22 int internal_getgroups (int, __gid32_t *, cygpsid * = NULL);
23
24 #include "sync.h"
25 #include "cygtls.h"
26 class pwdgrp
27 {
28   unsigned pwdgrp_buf_elem_size;
29   union
30   {
31     passwd **passwd_buf;
32     __group32 **group_buf;
33     void **pwdgrp_buf;
34   };
35   void (pwdgrp::*read) ();
36   bool (pwdgrp::*parse) ();
37   int etc_ix;
38   UNICODE_STRING upath;
39   PWCHAR path;
40   char *buf, *lptr;
41   int max_lines;
42   bool initialized;
43   static muto pglock;
44
45   bool parse_passwd ();
46   bool parse_group ();
47   void read_passwd ();
48   void read_group ();
49   char *add_line (char *);
50   char *raw_ptr () const {return lptr;}
51   char *next_str (char);
52   bool next_num (unsigned long&);
53   bool next_num (unsigned int& i)
54   {
55     unsigned long x;
56     bool res = next_num (x);
57     i = (unsigned int) x;
58     return res;
59   }
60   inline bool next_num (int& i)
61   {
62     unsigned long x;
63     bool res = next_num (x);
64     i = (int) x;
65     return res;
66   }
67
68 public:
69   int curr_lines;
70
71   void load (const wchar_t *);
72   inline void refresh (bool check)
73   {
74     if (!check && initialized)
75       return;
76     if (pglock.acquire () == 1 &&
77         (!initialized || (check && etc::file_changed (etc_ix))))
78       (this->*read) ();
79     pglock.release ();
80   }
81
82   pwdgrp (passwd *&pbuf);
83   pwdgrp (__group32 *&gbuf);
84 };