23 |
#include <unistd.h> /* read close getuid getgid getpid getppid gethostname */ |
#include <unistd.h> /* read close getuid getgid getpid getppid gethostname */ |
24 |
#include <fcntl.h> /* open */ |
#include <fcntl.h> /* open */ |
25 |
#include <pwd.h> /* getpwuid */ |
#include <pwd.h> /* getpwuid */ |
26 |
|
#include <limits.h> /* PATH_MAX */ |
27 |
#include <sys/stat.h> /* stat */ |
#include <sys/stat.h> /* stat */ |
28 |
#include <sys/time.h> /* gettimeofday */ |
#include <sys/time.h> /* gettimeofday */ |
29 |
#include <sys/times.h> /* times */ |
#include <sys/times.h> /* times */ |
349 |
line += thisline; |
line += thisline; |
350 |
} |
} |
351 |
} |
} |
352 |
|
|
353 |
|
int |
354 |
|
load_licence(unsigned char **data) |
355 |
|
{ |
356 |
|
char path[PATH_MAX]; |
357 |
|
char *home; |
358 |
|
struct stat st; |
359 |
|
int fd; |
360 |
|
|
361 |
|
home = getenv("HOME"); |
362 |
|
if (home == NULL) |
363 |
|
return -1; |
364 |
|
|
365 |
|
STRNCPY(path, home, sizeof(path)); |
366 |
|
strncat(path, "/.rdesktop/licence", sizeof(path)-strlen(path)-1); |
367 |
|
|
368 |
|
fd = open(path, O_RDONLY); |
369 |
|
if (fd == -1) |
370 |
|
return -1; |
371 |
|
|
372 |
|
if (fstat(fd, &st)) |
373 |
|
return -1; |
374 |
|
|
375 |
|
*data = xmalloc(st.st_size); |
376 |
|
return read(fd, *data, st.st_size); |
377 |
|
} |
378 |
|
|
379 |
|
void |
380 |
|
save_licence(unsigned char *data, int length) |
381 |
|
{ |
382 |
|
char path[PATH_MAX]; |
383 |
|
char *home; |
384 |
|
int fd; |
385 |
|
|
386 |
|
home = getenv("HOME"); |
387 |
|
if (home == NULL) |
388 |
|
return; |
389 |
|
|
390 |
|
STRNCPY(path, home, sizeof(path)); |
391 |
|
strncat(path, "/.rdesktop", sizeof(path)-strlen(path)-1); |
392 |
|
mkdir(path, 0700); |
393 |
|
|
394 |
|
strncat(path, "/licence", sizeof(path)-strlen(path)-1); |
395 |
|
|
396 |
|
fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0600); |
397 |
|
if (fd == -1) |
398 |
|
{ |
399 |
|
perror("open"); |
400 |
|
return; |
401 |
|
} |
402 |
|
|
403 |
|
write(fd, data, length); |
404 |
|
close(fd); |
405 |
|
} |
406 |
|
|