-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot.c
119 lines (110 loc) · 3.83 KB
/
root.c
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
108
109
110
111
112
113
114
115
116
117
118
119
#include "config.h"
#include <sys/param.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "root.h"
int
get_root( char *radmind_path, char *path, char *file_root, char *xattr_root,
char *tran_root, char *tran_name )
{
char real_path[ PATH_MAX ];
char test_path[ MAXPATHLEN ];
char radmind_real_path[ PATH_MAX ];
char *p;
if ( realpath( radmind_path, radmind_real_path ) == NULL ) {
perror( radmind_real_path );
return( -1 );
}
if ( realpath( path, real_path ) == NULL ) {
perror( real_path );
return( -1 );
}
/* Get transcript name */
if (( p = strrchr( real_path, '/' )) == real_path ) {
fprintf( stderr, "%s: invalid transcript location\n", real_path );
return( -1 );
}
*p++ = '\0';
if ( strlen( p ) >= MAXPATHLEN ) {
fprintf( stderr, "%s: path too long\n", p );
return( -1 );
}
strcpy( tran_name, p );
if ( snprintf( test_path, MAXPATHLEN, "%s/tmp/transcript",
radmind_real_path ) >= MAXPATHLEN ) {
fprintf( stderr, "%s/tmp/transcirpt: path too long\n",
radmind_real_path );
return( -1 );
}
if ( strstr( real_path, test_path ) != NULL ) {
if ( snprintf( file_root, MAXPATHLEN, "%s/tmp/file%s",
radmind_real_path, &real_path[ strlen( test_path ) ])
>= MAXPATHLEN ) {
fprintf( stderr, "%s/tmp/file%s: path too long\n",
radmind_real_path, &real_path[ strlen( test_path )] );
return( -1 );
}
if ( snprintf( tran_root, MAXPATHLEN, "%s/tmp/transcript%s",
radmind_real_path, &real_path[ strlen( test_path ) ])
>= MAXPATHLEN ) {
fprintf( stderr, "%s/tmp/transcript%s: path too long\n",
radmind_real_path, &real_path[ strlen( test_path )] );
return( -1 );
}
#ifdef ENABLE_XATTR
if ( snprintf( xattr_root, MAXPATHLEN, "%s/tmp/xattr%s",
radmind_real_path, &real_path[ strlen( test_path ) ] )
>= MAXPATHLEN ) {
fprintf( stderr, "%s/tmp/xattr%s: path too long\n",
radmind_real_path, &real_path[ strlen( test_path ) ] );
return( -1 );
}
#endif /* ENABLE_XATTR */
} else {
if ( snprintf( test_path, MAXPATHLEN, "%s/transcript",
radmind_real_path ) >= MAXPATHLEN ) {
fprintf( stderr, "%s/transcript: path too long\n",
radmind_real_path );
return( -1 );
}
if ( strstr( real_path, test_path ) != NULL ) {
if ( snprintf( file_root, MAXPATHLEN, "%s/file%s",
radmind_real_path, &real_path[ strlen( test_path ) ])
>= MAXPATHLEN ) {
fprintf( stderr, "%s/file%s: path too long\n",
radmind_real_path, &real_path[ strlen( test_path ) ]);
return( -1 );
}
if ( snprintf( tran_root, MAXPATHLEN, "%s/transcript%s",
radmind_real_path, &real_path[ strlen( test_path ) ])
>= MAXPATHLEN ) {
fprintf( stderr, "%s/transcript%s: path too long\n",
radmind_real_path, &real_path[ strlen( test_path )] );
return( -1 );
}
#ifdef ENABLE_XATTR
if ( snprintf( xattr_root, MAXPATHLEN, "%s/xattr%s",
radmind_real_path, &real_path[ strlen( test_path ) ])
>= MAXPATHLEN ) {
fprintf( stderr, "%s/xattr%s: path too long\n",
radmind_real_path, &real_path[ strlen( test_path ) ]);
return( -1 );
}
#endif /* ENABLE_XATTR */
} else {
if ( snprintf( file_root, MAXPATHLEN, "%s/../file",
real_path ) >= MAXPATHLEN ) {
fprintf( stderr, "%s/../file: path too long\n",
real_path);
return( -1);
}
snprintf( tran_root, MAXPATHLEN, "%s", real_path );
#ifdef ENABLE_XATTR
snprintf( xattr_root, MAXPATHLEN, "%s/../xattr", real_path );
#endif /* ENABLE_XATTR */
}
}
return( 0 );
}