source: roaraudio/roard/auth.c @ 4474:bf3206323cae

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

got auth stuff basicly to work

File size: 2.9 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_regkey_simple(ROAR_AUTH_T_NONE, ACCLEV_ALL) == NULL )
41  return -1;
42
43 return 0;
44}
45
46int auth_free (void) {
47 return 0;
48}
49
50union auth_typeunion * auth_regkey_simple(int type, enum roard_client_acclev acclev) {
51 struct auth_key * key;
52 int i;
53
54 for (i = 0; i < AUTH_KEYRING_LEN; i++) {
55  if ( (key = &(g_auth_keyring[i]))->type == _NONE ) {
56   memset(key, 0, sizeof(struct auth_key));
57   key->type   = type;
58   key->acclev = acclev;
59   return &(key->at_data);
60  }
61 }
62
63 return NULL;
64}
65
66static int _ck_password(struct auth_key * key, struct roar_auth_message * authmes) {
67 size_t len = strlen(key->at_data.password.password);
68
69 // need to check here if we have a padding \0-byte.
70
71 if ( len == authmes->len ) {
72  if ( memcmp(key->at_data.password.password, authmes->data, len) ) {
73   return -1;
74  } else {
75   return 1;
76  }
77 }
78
79 return -1;
80}
81
82int auth_client_ckeck(struct roar_client_server * cs, struct roar_auth_message * authmes) {
83 struct auth_key * key;
84 int i;
85 int ret;
86
87 if ( cs == NULL || authmes == NULL )
88  return -1;
89
90 for (i = 0; i < AUTH_KEYRING_LEN; i++) {
91  if ( (key = &(g_auth_keyring[i]))->type == authmes->type ) {
92    ret = -1;
93   switch (key->type) {
94    case ROAR_AUTH_T_NONE:
95      ret = 1;
96     break;
97    case ROAR_AUTH_T_PASSWORD:
98      ret = _ck_password(key, authmes);
99     break;
100    case ROAR_AUTH_T_TRUST:
101    case ROAR_AUTH_T_COOKIE:
102    case ROAR_AUTH_T_SYSUSER:
103    case ROAR_AUTH_T_RHOST:
104    default:
105      /* don't know what to do... */
106      return -1;
107     break;
108   }
109   switch (ret) {
110    case -1:
111      /* ignore this case and continue */
112     break;
113    case 0:
114      return 0;
115     break;
116    case 1:
117      cs->acclev = key->acclev;
118      return 1;
119     break;
120    default: /* error! */
121      return -1;
122     break;
123   }
124  }
125 }
126
127 return -1;
128}
129
130//ll
Note: See TracBrowser for help on using the repository browser.