1 /* 2 * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Philippe Houdoin 7 * Jérôme Duval, korli@users.berlios.de 8 * Axel Dörfler, axeld@pinc-software.de 9 */ 10 11 12 #include <SupportDefs.h> 13 #include <TLS.h> 14 15 #include <stdio.h> 16 #include <string.h> 17 #include <unistd.h> 18 19 20 struct net_settings; 21 22 extern "C" { 23 int *_h_errnop(void); 24 int _netstat(int fd, char **output, int verbose); 25 int _socket_interrupt(void); 26 int closesocket(int socket); 27 char *find_net_setting(net_settings* settings, const char* heading, 28 const char* name, char* value, unsigned numBytes); 29 status_t set_net_setting(net_settings* settings, const char* heading, 30 const char* name, const char* value); 31 int getusername(char *user, size_t bufferLength); 32 int getpassword(char *password, size_t bufferLength); 33 char *_netconfig_find(const char *heaading, const char *name, char *value, int nbytes); 34 } 35 36 37 int32 __gHErrnoTLS = tls_allocate(); 38 39 40 int * 41 _h_errnop(void) 42 { 43 return (int *)tls_address(__gHErrnoTLS); 44 } 45 46 47 int 48 _netstat(int fd, char **output, int verbose) 49 { 50 return ENOSYS; 51 } 52 53 54 int 55 _socket_interrupt(void) 56 { 57 return -1; 58 } 59 60 61 int 62 closesocket(int socket) 63 { 64 return close(socket); 65 } 66 67 68 /* TODO: This is a terrible hack :( 69 * TODO: We should really get these settings values by parsing the real settings 70 */ 71 72 char * 73 find_net_setting(net_settings* settings, const char* heading, 74 const char* name, char* value, unsigned numBytes) 75 { 76 if (strcmp(heading, "GLOBAL") != 0) 77 return NULL; 78 79 if (!strcmp(name, "HOSTNAME")) 80 strlcpy(value, "hostname", numBytes); 81 else if (!strcmp(name, "USERNAME")) 82 strlcpy(value, "baron", numBytes); 83 else if (!strcmp(name, "PASSWORD")) 84 strlcpy(value, "password", numBytes); 85 else if (!strcmp(name, "FTP_ENABLED")) 86 strlcpy(value, "1", numBytes); 87 else if (!strcmp(name, "TELNETD_ENABLED")) 88 strlcpy(value, "1", numBytes); 89 else 90 return NULL; 91 92 return value; 93 } 94 95 96 status_t 97 set_net_setting(net_settings* settings, const char* heading, 98 const char* name, const char* value) 99 { 100 return B_UNSUPPORTED; 101 } 102 103 104 int 105 getusername(char *user, size_t length) 106 { 107 if (find_net_setting(NULL, "GLOBAL", "USERNAME", user, length) == NULL) 108 return B_ERROR; 109 110 return strlen(user); 111 } 112 113 114 int 115 getpassword(char *password, size_t length) 116 { 117 if (find_net_setting(NULL, "GLOBAL", "PASSWORD", password, length) == NULL) 118 return B_ERROR; 119 120 return strlen(password); 121 } 122 123 char * 124 _netconfig_find(const char *heading, const char *name, char *value, int nbytes) 125 { 126 return find_net_setting(NULL, heading, name, value, nbytes); 127 } 128