source: roaraudio/roard/auth.c @ 4476:f5d7c266e5de

Last change on this file since 4476:f5d7c266e5de was 4476:f5d7c266e5de, checked in by phi, 14 years ago

implemented auth time NONE and PASSWORD

File size: 3.3 KB
Line 
1//auth.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "roard.h"
27
28#define _NONE ROAR_AUTH_T_AUTO
29
30int auth_init (void) {
31 int i;
32
33 memset(g_auth_keyring, 0, sizeof(g_auth_keyring));
34
35 for (i = 0; i < AUTH_KEYRING_LEN; i++) {
36  g_auth_keyring[i].type = _NONE;
37 }
38
39 // enable guest access.
40 if ( auth_addkey_anonymous(ACCLEV_ALL) == -1 )
41  return -1;
42
43#if 0
44 // test password for API tests...
45 auth_addkey_password(ACCLEV_ALL, "test");
46#endif
47
48 return 0;
49}
50
51int auth_free (void) {
52 return 0;
53}
54
55union auth_typeunion * auth_regkey_simple(int type, enum roard_client_acclev acclev) {
56 struct auth_key * key;
57 int i;
58
59 for (i = 0; i < AUTH_KEYRING_LEN; i++) {
60  if ( (key = &(g_auth_keyring[i]))->type == _NONE ) {
61   memset(key, 0, sizeof(struct auth_key));
62   key->type   = type;
63   key->acclev = acclev;
64   return &(key->at_data);
65  }
66 }
67
68 return NULL;
69}
70
71static int _ck_password(struct auth_key * key, struct roar_auth_message * authmes) {
72 size_t len = strlen(key->at_data.password.password);
73
74 // need to check here if we have a padding \0-byte.
75
76 if ( len == authmes->len ) {
77  if ( memcmp(key->at_data.password.password, authmes->data, len) ) {
78   return -1;
79  } else {
80   return 1;
81  }
82 }
83
84 return -1;
85}
86
87int auth_client_ckeck(struct roar_client_server * cs, struct roar_auth_message * authmes) {
88 struct auth_key * key;
89 int i;
90 int ret;
91
92 if ( cs == NULL || authmes == NULL )
93  return -1;
94
95 for (i = 0; i < AUTH_KEYRING_LEN; i++) {
96  if ( (key = &(g_auth_keyring[i]))->type == authmes->type ) {
97    ret = -1;
98   switch (key->type) {
99    case ROAR_AUTH_T_NONE:
100      ret = 1;
101     break;
102    case ROAR_AUTH_T_PASSWORD:
103      ret = _ck_password(key, authmes);
104     break;
105    case ROAR_AUTH_T_TRUST:
106    case ROAR_AUTH_T_COOKIE:
107    case ROAR_AUTH_T_SYSUSER:
108    case ROAR_AUTH_T_RHOST:
109    default:
110      /* don't know what to do... */
111      return -1;
112     break;
113   }
114   switch (ret) {
115    case -1:
116      /* ignore this case and continue */
117     break;
118    case 0:
119      return 0;
120     break;
121    case 1:
122      cs->acclev = key->acclev;
123      return 1;
124     break;
125    default: /* error! */
126      return -1;
127     break;
128   }
129  }
130 }
131
132 return -1;
133}
134
135int auth_addkey_anonymous(enum roard_client_acclev acclev) {
136 if ( auth_regkey_simple(ROAR_AUTH_T_NONE, acclev) == NULL )
137  return -1;
138 return 0;
139}
140
141int auth_addkey_password(enum roard_client_acclev acclev, const char * password) {
142 union auth_typeunion * pw;
143
144 if ( (pw = auth_regkey_simple(ROAR_AUTH_T_PASSWORD, acclev)) == NULL )
145  return -1;
146
147 pw->password.password = password;
148
149 return 0;
150}
151
152//ll
Note: See TracBrowser for help on using the repository browser.