Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / lib / mp / mp_auth.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $TOG: mp_auth.h /main/2 1999/09/10 15:01:41 mgreess $                                                      */
28 /* 
29  * @(#)mp_auth.h        1.36 95/01/25
30  * 
31  * Copyright (c) 1990 by Sun Microsystems, Inc.
32  * 
33  * This file contains the implementation of the _Tt_auth object which
34  * implements the MIT-MAGIC-COOKIE authentication for the _TT_AUTH_ICEAUTH
35  * authentication type.  This class is simply a wrapper for calls to
36  * code copied out of the X11 libICE library.  Alternatively, one can
37  * compile with the OPT_ICE define and call the ICE routines directly.
38  */
39 #ifndef MP_AUTH_H
40 #define MP_AUTH_H
41 #include "tt_options.h"
42 #include "mp/mp_auth_functions.h"
43 #include "util/tt_object.h"
44 #include "util/tt_list.h"
45 #include "util/tt_string.h"
46
47 /*
48  * As of the CDE release of ToolTalk, _TT_AUTH_XAUTH is no longer supported.
49  * It has been removed along with all references in the TT code, but the
50  * value of _TT_AUTH_DES was not changed to the now-missing value of 1.
51  */
52 /*
53  * As of 2.1.30, the libICE MIT-MAGIC-COOKIE  authentication is added in
54  * place of _TT_AUTH_XAUTH.  The code was inlined from libICE in such a
55  * way that it could be easily replaced by libICE itself.
56  */
57
58 #define _TT_ICEAUTH_AUTH_NAME           "MIT-MAGIC-COOKIE-1"
59 #define _TT_ICEAUTH_MAGIC_COOKIE_LEN    16
60 #define _TT_ICEAUTH_PROTOCOL_NAME       "TT"
61
62 #define _TT_ICEAUTH_DEFAULT_RETRIES     10   /* num of competitors we expect */
63 #define _TT_ICEAUTH_DEFAULT_TIMEOUT     2    /* in seconds, be quick */
64 #define _TT_ICEAUTH_DEFAULT_DEADTIME    600L /* 10 minutes in seconds */
65
66
67
68 enum _Tt_auth_level {
69         _TT_AUTH_UNIX   = 0,    /* Unix "authentication" */
70         _TT_AUTH_ICEAUTH= 1,    /* ICE MIT-COOKIE authentication (default) */
71         _TT_AUTH_DES    = 2,    /* Secure RPC (DES encryption)     */
72         _TT_AUTH_NONE   = 3     /* No authentication */
73 };
74
75 class _Tt_auth : public _Tt_object {
76       public:
77         _Tt_auth(_Tt_auth_level auth_level = _TT_AUTH_ICEAUTH);
78         virtual ~_Tt_auth();
79
80         _Tt_auth_level          auth_level() {
81             return _auth_level;
82         }
83         const _Tt_string        &auth_cookie() const {
84             return _auth_cookie;
85         }
86         Tt_status               generate_auth_cookie();
87         Tt_status               retrieve_auth_cookie();
88         Tt_status               set_auth_level(_Tt_auth_level auth_level);
89         Tt_status               set_sessionid(
90                                         int             rpc_program,
91                                         _Tt_auth_level  auth_level,
92                                         _Tt_string      hostaddr,
93                                         int             rpc_version);
94
95       protected:
96         //
97         // state variables
98         //
99         _Tt_auth_level                  _auth_level;
100         _Tt_string                      _auth_cookie;
101         _Tt_string                      _hostaddr;
102         int                             _rpc_program;
103         int                             _rpc_version;
104         _Tt_string                      _sessionid;
105         _Tt_string                      _ttauthfile;
106
107       private:
108         //
109         // variables associated with generating a .ttauthority file entry.
110         //
111         _tt_AuthFileEntryList   *_entries_head;
112         _tt_AuthFileEntryList   *_entries_tail;
113
114         Tt_status               read_auth_file(char*);
115         Tt_status               write_auth_file(char*);
116
117         Tt_status               modify_auth_entry(_tt_AuthFileEntry*,
118                                                   _tt_AuthFileEntryList**);
119         Tt_status               read_auth_entries(FILE*,
120                                                   _tt_AuthFileEntryList**);
121 };
122
123 #endif                          /*  MP_AUTH_H */