File: Cns_auth.c

package info (click to toggle)
dpm-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,788 kB
  • ctags: 10,782
  • sloc: ansic: 146,136; sh: 13,362; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 955; fortran: 113
file content (107 lines) | stat: -rw-r--r-- 2,453 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright (C) 2005 by CERN/IT/GD/CT
 * All rights reserved
 */

#ifndef lint
static char sccsid[] = "@(#)$RCSfile: Cns_auth.c,v $ $Revision: 1.3 $ $Date: 2006/08/28 07:47:57 $ CERN IT-GD/SC Jean-Philippe Baud";
#endif /* not lint */

#include <errno.h>
#include <sys/types.h>
#include <string.h>
#include "Castor_limits.h"
#include "Cns_api.h"
#include "serrno.h"

/*      Cns_client_getAuthorizationId - get the authorization id from the thread-specific structure */

int DLL_DECL
Cns_client_getAuthorizationId(uid_t *uid, gid_t *gid, char **mech, char **id)
{
	struct Cns_api_thread_info *thip;

#ifdef CSEC
	if (Cns_apiinit (&thip))
		return (-1);
	if (thip->use_authorization_id == 0)
		return (0);
	if (uid)
		*uid = thip->Csec_uid;
	if (gid)
		*gid = thip->Csec_gid;
	if (mech)
		*mech = thip->Csec_mech;
	if (id)
		*id = thip->Csec_auth_id;
#endif
	return (0);
}

/*      Cns_client_resetAuthorizationId - reset the authorization id in the thread-specific structure */

int DLL_DECL
Cns_client_resetAuthorizationId()
{
	char func[32];
	struct Cns_api_thread_info *thip;

#ifdef CSEC
	strcpy (func, "Cns_client_resetAuthorizationId");
	if (Cns_apiinit (&thip))
		return (-1);
	thip->use_authorization_id = 0;
#endif
	return (0);
}

/*      Cns_client_setAuthorizationId - set the authorization id in the thread-specific structure */

int DLL_DECL
Cns_client_setAuthorizationId(uid_t uid, gid_t gid, const char *mech, char *id)
{
	char func[30];
	struct Cns_api_thread_info *thip;

#ifdef CSEC
	strcpy (func, "Cns_client_setAuthorizationId");
	if (Cns_apiinit (&thip))
		return (-1);
	thip->Csec_uid = uid;
	thip->Csec_gid = gid;
	if (strlen (mech) > CA_MAXCSECPROTOLEN) {
		Cns_errmsg (func, "Supplied Csec protocol is too long\n");
		serrno = EINVAL;
		return (-1);
	}
	strcpy (thip->Csec_mech, mech);
	if (strlen (id) > CA_MAXCSECNAMELEN) {
		Cns_errmsg (func, "Supplied authorization id is too long\n");
		serrno = EINVAL;
		return (-1);
	}
	strcpy (thip->Csec_auth_id, id);
	thip->voname = NULL;
	thip->nbfqan = 0;
	thip->fqan = NULL;
	thip->use_authorization_id = 1;
#endif
	return (0);
}

/*      Cns_client_setVOMS_data - set the VOMS data in the thread-specific structure */

int DLL_DECL
Cns_client_setVOMS_data(char *voname, char **fqan, int nbfqan)
{
	struct Cns_api_thread_info *thip;

#ifdef CSEC
	if (Cns_apiinit (&thip))
		return (-1);
	thip->voname = voname;
	thip->nbfqan = nbfqan;
	thip->fqan = fqan;
#endif
	return (0);
}