blob: d979f121e9a81e048f6c37f725ed9618ce3da850 (
plain)
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
|
/*
** Copyright 2002 Double Precision, Inc. See COPYING for
** distribution information.
*/
/*
*/
#include "config.h"
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <pwd.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#include <errno.h>
#include <sysconfdir.h>
#include "calendardir.h"
char *auth_myhostname()
{
char buf[1024];
static char *my_hostname=0;
FILE *f;
if (my_hostname == 0)
{
buf[0]=0;
f=fopen(HOSTNAMEFILE, "r");
if (!f)
f=fopen(HOSTNAMEFILE2, "r");
if (f != 0)
{
char *p;
if (fgets(buf, sizeof(buf), f) == NULL)
buf[0]=0;
fclose(f);
if ((p=strchr(buf, '\n')) != 0)
*p=0;
}
if (buf[0] == 0 && gethostname(buf, sizeof(buf)-1))
strcpy(buf, "localhost");
if ((my_hostname=malloc(strlen(buf)+1)) == 0)
{
fprintf(stderr, "NOTICE: malloc: out of memory.\n");
return strdup("localhost");
}
strcpy(my_hostname, buf);
}
return (my_hostname);
}
|