ReactOS 0.4.15-dev-7942-gd23573b
util.c File Reference
#include "syshdrs.h"
#include "shell.h"
#include "trace.h"
#include "util.h"
Include dependency graph for util.c:

Go to the source code of this file.

Functions

void ToBase64 (void *dst0, const void *src0, size_t n, int terminate)
 
void FromBase64 (void *dst0, const void *src0, size_t n, int terminate)
 
void OutOfMemory (void)
 
void MyInetAddr (char *dst, size_t siz, char **src, int i)
 
struct hostentGetHostEntry (const char *host, struct in_addr *ip_address)
 
void CompressPath (char *const dst, const char *const src, const size_t dsize)
 
void PathCat (char *const dst, const size_t dsize, const char *const cwd, const char *const src)
 
charFileToURL (char *url, size_t urlsize, const char *const fn, const char *const rcwd, const char *const startdir, const char *const user, const char *const pass, const char *const hname, const unsigned int port)
 
void AbbrevStr (char *dst, const char *src, size_t max, int mode)
 
charPath (char *const dst, const size_t siz, const char *const parent, const char *const fname)
 
charOurDirectoryPath (char *const dst, const size_t siz, const char *const fname)
 
charOurInstallationPath (char *const dst, const size_t siz, const char *const fname)
 
void InitOurDirectory (void)
 
void InitUserInfo (void)
 
int MayUseFirewall (const char *const hn, int firewallType, const char *const firewallExceptionList)
 
int StrToBool (const char *const s)
 
void AbsoluteToRelative (char *const dst, const size_t dsize, const char *const dir, const char *const root, const size_t rootlen)
 
static void CancelGetHostByName (int sigNum)
 
int GetHostByName (char *const volatile dst, size_t dsize, const char *const hn, int t)
 
time_t UnDate (char *dstr)
 
int DecodeDirectoryURL (const FTPCIPtr cip, char *url, LineListPtr cdlist, char *fn, size_t fnsize)
 

Variables

uid_t gUid
 
char gUser [32]
 
char gHome [256]
 
char gShell [256]
 
char gOurDirectoryPath [260]
 
char gOurInstallationPath [260]
 
jmp_buf gGetHostByNameJmp
 
static const unsigned char B64EncodeTable [64]
 
static const unsigned char B64DecodeTable [256]
 

Function Documentation

◆ AbbrevStr()

void AbbrevStr ( char dst,
const char src,
size_t  max,
int  mode 
)

Definition at line 451 of file util.c.

452{
453 int len;
454
455 len = (int) strlen(src);
456 if (len > (int) max) {
457 if (mode == 0) {
458 /* ...Put ellipses at left */
459 (void) strcpy(dst, "...");
460 (void) Strncat(dst, (char *) src + len - (int) max + 3, max + 1);
461 } else {
462 /* Put ellipses at right... */
463 (void) Strncpy(dst, (char *) src, max + 1);
464 (void) strcpy(dst + max - 3, "...");
465 }
466 } else {
467 (void) Strncpy(dst, (char *) src, max + 1);
468 }
469} /* AbbrevStr */
char * Strncat(char *const, const char *const, const size_t)
Definition: Strncat.c:13
char * Strncpy(char *const, const char *const, const size_t)
Definition: Strncpy.c:11
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLenum src
Definition: glext.h:6340
GLenum mode
Definition: glext.h:6217
GLenum GLenum dst
Definition: glext.h:6340
GLenum GLsizei len
Definition: glext.h:6722
#define max(a, b)
Definition: svc.c:63

Referenced by MakePrompt(), PrSizeAndRateMeter(), PrStatBar(), and Usage().

◆ AbsoluteToRelative()

void AbsoluteToRelative ( char *const  dst,
const size_t  dsize,
const char *const  dir,
const char *const  root,
const size_t  rootlen 
)

Definition at line 785 of file util.c.

786{
787 *dst = '\0';
788 if (strcmp(dir, root) != 0) {
789 if (strcmp(root, "/") == 0) {
790 (void) Strncpy(dst, dir + 1, dsize);
791 } else if ((strncmp(root, dir, rootlen) == 0) && (dir[rootlen] == '/')) {
792 (void) Strncpy(dst, dir + rootlen + 1, dsize);
793 } else {
794 /* Still absolute. */
795 (void) Strncpy(dst, dir, dsize);
796 }
797 }
798} /* AbsoluteToRelative */
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
unsigned int dir
Definition: maze.c:112

Referenced by CurrentURL(), and FillBookmarkInfo().

◆ CancelGetHostByName()

static void CancelGetHostByName ( int  sigNum)
static

Definition at line 808 of file util.c.

809{
810#ifdef ncftp
811 gResolveSig = sigNum;
812#endif
813#ifdef HAVE_SIGSETJMP
814 siglongjmp(gGetHostByNameJmp, (sigNum != 0) ? 1 : 0);
815#else /* HAVE_SIGSETJMP */
816 longjmp(gGetHostByNameJmp, (sigNum != 0) ? 1 : 0);
817#endif /* HAVE_SIGSETJMP */
818} /* CancelGetHostByName */
jmp_buf gGetHostByNameJmp
Definition: util.c:27
void siglongjmp(sigjmp_buf buf, int val)

Referenced by GetHostByName().

◆ CompressPath()

void CompressPath ( char *const  dst,
const char *const  src,
const size_t  dsize 
)

Definition at line 247 of file util.c.

248{
249 int c;
250 const char *s;
251 char *d, *lim;
252 char *a, *b;
253
254 if (src[0] == '\0') {
255 *dst = '\0';
256 return;
257 }
258
259 s = src;
260 d = dst;
261 lim = d + dsize - 1; /* leave room for nul byte. */
262 for (;;) {
263 c = *s;
264 if (c == '.') {
265 if (((s == src) || (s[-1] == '/')) && ((s[1] == '/') || (s[1] == '\0'))) {
266 /* Don't copy "./" */
267 if (s[1] == '/')
268 ++s;
269 ++s;
270 } else if (d < lim) {
271 *d++ = *s++;
272 } else {
273 ++s;
274 }
275 } else if (c == '/') {
276 /* Don't copy multiple slashes. */
277 if (d < lim)
278 *d++ = *s++;
279 else
280 ++s;
281 for (;;) {
282 c = *s;
283 if (c == '/') {
284 /* Don't copy multiple slashes. */
285 ++s;
286 } else if (c == '.') {
287 c = s[1];
288 if (c == '/') {
289 /* Skip "./" */
290 s += 2;
291 } else if (c == '\0') {
292 /* Skip "./" */
293 s += 1;
294 } else {
295 break;
296 }
297 } else {
298 break;
299 }
300 }
301 } else if (c == '\0') {
302 /* Remove trailing slash. */
303 if ((d[-1] == '/') && (d > (dst + 1)))
304 d[-1] = '\0';
305 *d = '\0';
306 break;
307 } else if (d < lim) {
308 *d++ = *s++;
309 } else {
310 ++s;
311 }
312 }
313 a = dst;
314
315 /* fprintf(stderr, "<%s>\n", dst); */
316 /* Go through and remove .. in the path when we know what the
317 * parent directory is. After we get done with this, the only
318 * .. nodes in the path will be at the front.
319 */
320 while (*a != '\0') {
321 b = a;
322 for (;;) {
323 /* Get the next node in the path. */
324 if (*a == '\0')
325 return;
326 if (*a == '/') {
327 ++a;
328 break;
329 }
330 ++a;
331 }
332 if ((b[0] == '.') && (b[1] == '.')) {
333 if (b[2] == '/') {
334 /* We don't know what the parent of this
335 * node would be.
336 */
337 continue;
338 }
339 }
340 if ((a[0] == '.') && (a[1] == '.')) {
341 if (a[2] == '/') {
342 /* Remove the .. node and the one before it. */
343 if ((b == dst) && (*dst == '/'))
344 (void) memmove(b + 1, a + 3, strlen(a + 3) + 1);
345 else
346 (void) memmove(b, a + 3, strlen(a + 3) + 1);
347 a = dst; /* Start over. */
348 } else if (a[2] == '\0') {
349 /* Remove a trailing .. like: /aaa/bbb/.. */
350 if ((b <= dst + 1) && (*dst == '/'))
351 dst[1] = '\0';
352 else
353 b[-1] = '\0';
354 a = dst; /* Start over. */
355 } else {
356 /* continue processing this node.
357 * It is probably some bogus path,
358 * like ".../", "..foo/", etc.
359 */
360 }
361 }
362 }
363} /* CompressPath */
GLdouble s
Definition: gl.h:2039
const GLubyte * c
Definition: glext.h:8905
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define d
Definition: ke_i.h:81
#define a
Definition: ke_i.h:78
#define c
Definition: ke_i.h:80
#define b
Definition: ke_i.h:79
#define memmove(s1, s2, n)
Definition: mkisofs.h:881

Referenced by PathCat().

◆ DecodeDirectoryURL()

int DecodeDirectoryURL ( const FTPCIPtr  cip,
char url,
LineListPtr  cdlist,
char fn,
size_t  fnsize 
)

Definition at line 1086 of file util.c.

1093{
1094 int rc;
1095 char urlstr2[256];
1096 char *cp;
1097
1098 /* Add a trailing slash, if needed, i.e., convert
1099 * "ftp://ftp.gnu.org/pub/gnu" to
1100 * "ftp://ftp.gnu.org/pub/gnu/"
1101 *
1102 * We also generalize and assume that if the user specified
1103 * something with a .extension that the user was intending
1104 * to specify a file instead of a directory.
1105 */
1106 cp = strrchr(url, '/');
1107 if ((cp != NULL) && (cp[1] != '\0') && (strchr(cp, '.') == NULL)) {
1108
1109 (void) STRNCPY(urlstr2, url);
1110 (void) STRNCAT(urlstr2, "/");
1111 url = urlstr2;
1112 }
1113 rc = FTPDecodeURL(cip, url, cdlist, fn, fnsize, NULL, NULL);
1114 return (rc);
1115} /* DecodeDirectoryURL */
#define STRNCAT(d, s)
Definition: Strn.h:48
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define STRNCPY(dst, src, n)
Definition: rdesktop.h:168
#define NULL
Definition: types.h:112
POINT cp
Definition: magnifier.c:59
static const WCHAR url[]
Definition: encode.c:1432
int FTPDecodeURL(const FTPCIPtr cip, char *const url, LineListPtr cdlist, char *const fn, const size_t fnsize, int *const xtype, int *const wantnlst)
Definition: open.c:639
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159

Referenced by OpenCmd(), and SetStartupURL().

◆ FileToURL()

char * FileToURL ( char url,
size_t  urlsize,
const char *const  fn,
const char *const  rcwd,
const char *const  startdir,
const char *const  user,
const char *const  pass,
const char *const  hname,
const unsigned int  port 
)

Definition at line 387 of file util.c.

388{
389 size_t ulen, dsize;
390 char *dst, pbuf[32];
391 int isUser;
392
393 /* //<user>:<password>@<host>:<port>/<url-path> */
394 /* Note that if an absolute path is given,
395 * you need to escape the first entry, i.e. /pub -> %2Fpub
396 */
397 (void) Strncpy(url, "ftp://", urlsize);
398 isUser = 0;
399 if ((user != NULL) && (user[0] != '\0') && (strcmp(user, "anonymous") != 0) && (strcmp(user, "ftp") != 0)) {
400 isUser = 1;
401 (void) Strncat(url, user, urlsize);
402 if ((pass != NULL) && (pass[0] != '\0')) {
403 (void) Strncat(url, ":", urlsize);
404 (void) Strncat(url, "PASSWORD", urlsize);
405 }
406 (void) Strncat(url, "@", urlsize);
407 }
408 (void) Strncat(url, hname, urlsize);
409 if ((port != 21) && (port != 0)) {
410 (void) sprintf(pbuf, ":%u", (unsigned int) port);
411 (void) Strncat(url, pbuf, urlsize);
412 }
413
414 ulen = strlen(url);
415 dst = url + ulen;
416 dsize = urlsize - ulen;
417 PathCat(dst, dsize, rcwd, fn);
418 if ((startdir != NULL) && (startdir[0] != '\0') && (startdir[1] /* i.e. not "/" */ != '\0')) {
419 if (strncmp(dst, startdir, strlen(startdir)) == 0) {
420 /* Form relative URL. */
421 memmove(dst, dst + strlen(startdir), strlen(dst) - strlen(startdir) + 1);
422 } else if (isUser != 0) {
423 /* Absolute URL, but different from start dir.
424 * Make sure to use %2f as first slash so that
425 * the translation uses "/pub" instead of "pub"
426 * since the / characters are just delimiters.
427 */
428 dst[dsize - 1] = '\0';
429 dst[dsize - 2] = '\0';
430 dst[dsize - 3] = '\0';
431 dst[dsize - 4] = '\0';
432 memmove(dst + 4, dst + 1, strlen(dst + 1));
433 dst[0] = '/';
434 dst[1] = '%';
435 dst[2] = '2';
436 dst[3] = 'F';
437 }
438 }
439
440 return (url);
441} /* FileToURL */
void user(int argc, const char *argv[])
Definition: cmds.c:1350
USHORT port
Definition: uri.c:228
void PathCat(char *const dst, const size_t dsize, const char *const cwd, const char *const src)
Definition: util.c:368
#define sprintf(buf, format,...)
Definition: sprintf.c:55
Definition: pbuf.h:79
pass
Definition: typegen.h:25

Referenced by PrPhilBar(), PrSizeAndRateMeter(), and PrStatBar().

◆ FromBase64()

void FromBase64 ( void dst0,
const void src0,
size_t  n,
int  terminate 
)

Definition at line 128 of file util.c.

129{
130 unsigned char *dst;
131 const unsigned char *src, *srclim;
132 unsigned int c0, c1, c2, c3;
133 unsigned int ch;
134
135 src = src0;
136 srclim = src + n;
137 dst = dst0;
138
139 while (src < srclim) {
140 c0 = *src++;
141 if (src < srclim) {
142 c1 = *src++;
143 } else {
144 c1 = 0;
145 }
146 if (src < srclim) {
147 c2 = *src++;
148 } else {
149 c2 = 0;
150 }
151 if (src < srclim) {
152 c3 = *src++;
153 } else {
154 c3 = 0;
155 }
156
157 ch = (((unsigned int) B64DecodeTable[c0]) << 2) | (((unsigned int) B64DecodeTable[c1]) >> 4);
158 dst[0] = (unsigned char) ch;
159
160 ch = (((unsigned int) B64DecodeTable[c1]) << 4) | (((unsigned int) B64DecodeTable[c2]) >> 2);
161 dst[1] = (unsigned char) ch;
162
163 ch = (((unsigned int) B64DecodeTable[c2]) << 6) | (((unsigned int) B64DecodeTable[c3]));
164 dst[2] = (unsigned char) ch;
165
166 dst += 3;
167 }
168 if (terminate != 0)
169 *dst = '\0';
170} /* FromBase64 */
unsigned char
Definition: typeof.h:29
GLdouble n
Definition: glext.h:7729
void MSVCRT() terminate()
static const unsigned char B64DecodeTable[256]
Definition: util.c:46

Referenced by ParseHostLine().

◆ GetHostByName()

int GetHostByName ( char *const volatile  dst,
size_t  dsize,
const char *const  hn,
int  t 
)

Definition at line 826 of file util.c.

827{
828#if defined(WIN32) || defined(_WINDOWS)
829 struct hostent *hp;
830 struct in_addr ina;
831
832 if (inet_addr(hn) != (unsigned long) 0xFFFFFFFF) {
833 /* Address is an IP address string, which is what we want. */
834 (void) Strncpy(dst, hn, dsize);
835 return (0);
836 }
837
838 hp = gethostbyname(hn);
839 if (hp != NULL) {
840 (void) memcpy(&ina.s_addr, hp->h_addr_list[0], (size_t) hp->h_length);
841 (void) Strncpy(dst, inet_ntoa(ina), dsize);
842 return (0);
843 }
844
845#else
846 int sj;
847 vsigproc_t osigpipe, osigint, osigalrm;
848 struct hostent *hp;
849#ifndef HAVE_INET_NTOP
850 struct in_addr ina;
851#endif
852
853#ifdef HAVE_INET_ATON
854 if (inet_aton(hn, &ina) != 0) {
855 /* Address is an IP address string, which is what we want. */
856 (void) Strncpy(dst, hn, dsize);
857 return (0);
858 }
859#else
860 if (inet_addr(hn) != (unsigned long) 0xFFFFFFFF) {
861 /* Address is an IP address string, which is what we want. */
862 (void) Strncpy(dst, hn, dsize);
863 return (0);
864 }
865#endif
866
867#ifdef HAVE_SIGSETJMP
868 osigpipe = osigint = osigalrm = (sigproc_t) 0;
870#else /* HAVE_SIGSETJMP */
871 osigpipe = osigint = osigalrm = (sigproc_t) 0;
873#endif /* HAVE_SIGSETJMP */
874
875 if (sj != 0) {
876 /* Caught a signal. */
877 (void) alarm(0);
878 (void) NcSignal(SIGPIPE, osigpipe);
879 (void) NcSignal(SIGINT, osigint);
880 (void) NcSignal(SIGALRM, osigalrm);
881#ifdef ncftp
882 Trace(0, "Canceled GetHostByName because of signal %d.\n", gResolveSig);
883#endif
884 } else {
887 osigalrm = NcSignal(SIGALRM, CancelGetHostByName);
888 if (t > 0)
889 (void) alarm((unsigned int) t);
890 hp = gethostbyname(hn);
891 if (t > 0)
892 (void) alarm(0);
893 (void) NcSignal(SIGPIPE, osigpipe);
894 (void) NcSignal(SIGINT, osigint);
895 (void) NcSignal(SIGALRM, osigalrm);
896 if (hp != NULL) {
897#ifdef HAVE_INET_NTOP /* Mostly to workaround bug in IRIX 6.5's inet_ntoa */
898 (void) memset(dst, 0, dsize);
899 (void) inet_ntop(AF_INET, hp->h_addr_list[0], dst, dsize - 1);
900#else
901 (void) memcpy(&ina.s_addr, hp->h_addr_list[0], (size_t) hp->h_length);
902 (void) Strncpy(dst, inet_ntoa(ina), dsize);
903#endif
904 return (0);
905 }
906 }
907#endif /* !Windows */
908
909 *dst = '\0';
910 return (-1);
911} /* GetHostByName */
#define setjmp
Definition: setjmp.h:209
#define SIGINT
Definition: signal.h:23
#define SIGPIPE
Definition: signal.h:35
#define Trace(x)
Definition: inflate.c:42
#define AF_INET
Definition: tcpip.h:117
PHOSTENT WSAAPI gethostbyname(IN const char FAR *name)
Definition: getxbyxx.c:221
GLdouble GLdouble t
Definition: gl.h:2047
#define inet_addr(cp)
Definition: inet.h:98
#define inet_aton(cp, addr)
Definition: inet.h:99
#define inet_ntoa(addr)
Definition: inet.h:100
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void CancelGetHostByName(int sigNum)
Definition: util.c:808
volatile sigproc_t vsigproc_t
Definition: util.h:11
void(* sigproc_t)(int)
Definition: util.h:10
int sigsetjmp(sigjmp_buf buf, int savesigs)
#define NcSignal
Definition: ncftp.h:604
#define long
Definition: qsort.c:33
#define memset(x, y, z)
Definition: compat.h:39
short h_length
Definition: winsock.h:137
char ** h_addr_list
Definition: winsock.h:138
Definition: tcpip.h:126
const char *WSAAPI inet_ntop(int af, const void *src, char *dst, size_t cnt)
Definition: unix_func.c:8

Referenced by DoOpen().

◆ GetHostEntry()

struct hostent * GetHostEntry ( const char host,
struct in_addr ip_address 
)

Definition at line 215 of file util.c.

216{
217 struct in_addr ip;
218 struct hostent *hp;
219
220 /* See if the host was given in the dotted IP format, like "36.44.0.2."
221 * If it was, inet_addr will convert that to a 32-bit binary value;
222 * it not, inet_addr will return (-1L).
223 */
224 ip.s_addr = inet_addr(host);
225 if (ip.s_addr != INADDR_NONE) {
226 hp = gethostbyaddr((char *) &ip, (int) sizeof(ip), AF_INET);
227 } else {
228 /* No IP address, so it must be a hostname, like ftp.wustl.edu. */
229 hp = gethostbyname(host);
230 if (hp != NULL)
231 ip = * (struct in_addr *) hp->h_addr_list;
232 }
233 if (ip_address != NULL)
234 *ip_address = ip;
235 return (hp);
236} /* GetHostEntry */
#define INADDR_NONE
Definition: tcp.c:42
PHOSTENT WSAAPI gethostbyaddr(IN const char FAR *addr, IN int len, IN int type)
Definition: getxbyxx.c:309
Definition: dhcpd.h:62
char * host
Definition: whois.c:55

◆ InitOurDirectory()

void InitOurDirectory ( void  )

Definition at line 506 of file util.c.

507{
508#if defined(WIN32) || defined(_WINDOWS)
509 DWORD dwType, dwSize;
510 HKEY hkey;
511 char *cp;
512 int rc;
513
516
517 if (RegOpenKeyEx(
519 "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\ncftp.exe",
520 (DWORD) 0,
522 &hkey) == ERROR_SUCCESS)
523 {
524 dwSize = (DWORD) (sizeof(gOurInstallationPath) - 1);
525 dwType = 0;
526 if (RegQueryValueEx(
527 hkey,
528 NULL,
529 (DWORD *) 0,
530 &dwType,
533 {
534 // This gave us the path to ncftp.exe;
535 // But we use a subdirectory in that directory.
536 //
538 if (cp == NULL)
540 else
542 }
543 RegCloseKey(hkey);
544 }
545
546 if (gOurInstallationPath[0] == '\0') {
549 } else {
550 // This gave us the path to the current .exe;
551 // But we use a subdirectory in that directory.
552 //
554 if (cp == NULL)
556 else
558 }
559 }
560
561 if (gOurInstallationPath[0] != '\0') {
562 if ((cp = getenv("NCFTPDIR")) != NULL) {
563 if (*cp == '"')
564 cp++;
567 if ((cp != NULL) && (cp[1] == '\0'))
568 *cp = '\0';
569 } else if ((cp = getenv("HOME")) != NULL) {
570 if (*cp == '"')
571 cp++;
574 if ((cp != NULL) && (cp[1] == '\0'))
575 *cp = '\0';
576 } else {
578 if (gUser[0] == '\0') {
579 STRNCAT(gOurDirectoryPath, "\\Users\\default");
580 } else {
581 STRNCAT(gOurDirectoryPath, "\\Users\\");
583 }
584 }
585 rc = MkDirs(gOurDirectoryPath, 00755);
586 }
587
588#else
589 struct stat st;
590 char *cp;
591
592#ifdef BINDIR
594#else
596#endif
597
598 cp = getenv("NCFTPDIR");
599 if (cp != NULL) {
601 } else if (STREQ(gHome, "/")) {
602 /* Don't create it if you're root and your home directory
603 * is the root directory.
604 *
605 * If you are root and you want to store your ncftp
606 * config files, move your home directory somewhere else,
607 * such as /root or /home/root.
608 */
609 gOurDirectoryPath[0] = '\0';
610 return;
611 } else {
613 sizeof(gOurDirectoryPath),
614 gHome,
616 );
617 }
618
619 if (stat(gOurDirectoryPath, &st) < 0) {
620 if (mkdir(gOurDirectoryPath, 00755) < 0) {
621 gOurDirectoryPath[0] = '\0';
622 }
623 }
624#endif
625} /* InitOurDirectory */
PRTL_UNICODE_STRING_BUFFER Path
#define stat
Definition: acwin.h:99
#define mkdir
Definition: acwin.h:101
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned long DWORD
Definition: ntddk_ex.h:95
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
#define STREQ(a, b)
Definition: util.h:20
char gHome[256]
Definition: util.c:15
char gUser[32]
Definition: util.c:14
char gOurInstallationPath[260]
Definition: util.c:18
char gOurDirectoryPath[260]
Definition: util.c:17
#define kOurDirectoryName
Definition: util.h:45
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define StrRFindLocalPathDelim(a)
Definition: ncftp.h:495
int MkDirs(const char *const, int mode1)
Definition: util.c:785
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define DWORD
Definition: nt_native.h:44
Definition: stat.h:55
unsigned char * LPBYTE
Definition: typedefs.h:53
#define ZeroMemory
Definition: winbase.h:1712
#define GetModuleFileName
Definition: winbase.h:3831
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegQueryValueEx
Definition: winreg.h:524

Referenced by InitUserInfo().

◆ InitUserInfo()

void InitUserInfo ( void  )

Definition at line 630 of file util.c.

631{
632#if defined(WIN32) || defined(_WINDOWS)
633 DWORD nSize;
634 char *cp;
635
636 memset(gUser, 0, sizeof(gUser));
637 nSize = sizeof(gUser) - 1;
638 if (! GetUserName(gUser, &nSize))
639 STRNCPY(gUser, "default");
640
641 memset(gHome, 0, sizeof(gHome));
642 (void) GetTempPath((DWORD) sizeof(gHome) - 1, gHome);
643 cp = strrchr(gHome, '\\');
644 if ((cp != NULL) && (cp[1] == '\0'))
645 *cp = '\0';
646
647 memset(gShell, 0, sizeof(gShell));
648#else
649 struct passwd *pwptr;
650 char *envp;
651
652 gUid = geteuid();
653 pwptr = getpwuid(gUid);
654
655 if (pwptr == NULL) {
656 envp = getenv("LOGNAME");
657 if (envp == NULL) {
658 (void) fprintf(stderr, "Who are you?\n");
659 (void) fprintf(stderr, "You have a user id number of %d, but no username associated with it.\n", (int) gUid);
660 (void) STRNCPY(gUser, "unknown");
661 } else {
662 (void) STRNCPY(gUser, envp);
663 }
664
665 envp = getenv("HOME");
666 if (envp == NULL)
667 (void) STRNCPY(gHome, "/");
668 else
669 (void) STRNCPY(gHome, envp);
670
671 envp = getenv("SHELL");
672 if (envp == NULL)
673 (void) STRNCPY(gShell, "/bin/sh");
674 else
675 (void) STRNCPY(gShell, envp);
676 } else {
677 /* Copy home directory. */
678 (void) STRNCPY(gHome, pwptr->pw_dir);
679
680 /* Copy user name. */
681 (void) STRNCPY(gUser, pwptr->pw_name);
682
683 /* Copy shell. */
684 (void) STRNCPY(gShell, pwptr->pw_shell);
685 }
686#endif
687
689} /* InitUserInfo */
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
char gShell[256]
Definition: util.c:16
void InitOurDirectory(void)
Definition: util.c:506
uid_t gUid
Definition: util.c:13
EXPORT uid_t geteuid()
Definition: uid.c:37
#define GetTempPath
Definition: winbase.h:3850
#define GetUserName
Definition: winbase.h:3851
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2084

Referenced by PreInit().

◆ MayUseFirewall()

int MayUseFirewall ( const char *const  hn,
int  firewallType,
const char *const  firewallExceptionList 
)

Definition at line 695 of file util.c.

696{
697#ifdef HAVE_STRSTR
698 char buf[256];
699 char *tok;
700 char *parse;
701#endif /* HAVE_STRSTR */
702
703 if (firewallType == kFirewallNotInUse)
704 return (0);
705
706 if (firewallExceptionList[0] == '\0') {
707 if (strchr(hn, '.') == NULL) {
708 /* Unqualified host name,
709 * assume it is in local domain.
710 */
711 return (0);
712 } else {
713 return (1);
714 }
715 }
716
717 if (strchr(hn, '.') == NULL) {
718 /* Unqualified host name,
719 * assume it is in local domain.
720 *
721 * If "localdomain" is in the exception list,
722 * do not use the firewall for this host.
723 */
724 (void) STRNCPY(buf, firewallExceptionList);
725 for (parse = buf; (tok = strtok(parse, ", \n\t\r")) != NULL; parse = NULL) {
726 if (strcmp(tok, "localdomain") == 0)
727 return (0);
728 }
729 /* fall through */
730 }
731
732#ifdef HAVE_STRSTR
733 (void) STRNCPY(buf, firewallExceptionList);
734 for (parse = buf; (tok = strtok(parse, ", \n\t\r")) != NULL; parse = NULL) {
735 /* See if host or domain was from exclusion list
736 * matches the host to open.
737 */
738 if (strstr(hn, tok) != NULL)
739 return (0);
740 }
741#endif /* HAVE_STRSTR */
742 return (1);
743} /* MayUseFirewall */
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
char * strtok(char *String, const char *Delimiters)
Definition: utclib.c:338
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define kFirewallNotInUse
Definition: ncftp.h:388

Referenced by OpenCmd(), and SetStartupURL().

◆ MyInetAddr()

void MyInetAddr ( char dst,
size_t  siz,
char **  src,
int  i 
)

Definition at line 185 of file util.c.

186{
187 struct in_addr *ia;
188#ifndef HAVE_INET_NTOP
189 char *cp;
190#endif
191
192 (void) Strncpy(dst, "???", siz);
193 if (src != (char **) 0) {
194 ia = (struct in_addr *) src[i];
195#ifdef HAVE_INET_NTOP /* Mostly to workaround bug in IRIX 6.5's inet_ntoa */
196 (void) inet_ntop(AF_INET, ia, dst, siz - 1);
197#else
198 cp = inet_ntoa(*ia);
199 if ((cp != (char *) 0) && (cp != (char *) -1) && (cp[0] != '\0'))
200 (void) Strncpy(dst, cp, siz);
201#endif
202 }
203} /* MyInetAddr */
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by LookupCmd().

◆ OurDirectoryPath()

char * OurDirectoryPath ( char *const  dst,
const size_t  siz,
const char *const  fname 
)

◆ OurInstallationPath()

char * OurInstallationPath ( char *const  dst,
const size_t  siz,
const char *const  fname 
)

Definition at line 494 of file util.c.

495{
496 return (Path(dst, siz, gOurInstallationPath, fname));
497} /* OurInstallationPath */

Referenced by HaveSpool(), RunBatch(), and RunBookmarkEditor().

◆ OutOfMemory()

void OutOfMemory ( void  )

Definition at line 176 of file util.c.

177{
178 (void) fprintf(stderr, "Out of memory!\n");
179 exit(1);
180} /* OutOfMemory */
#define exit(n)
Definition: config.h:202

◆ Path()

char * Path ( char *const  dst,
const size_t  siz,
const char *const  parent,
const char *const  fname 
)

Definition at line 475 of file util.c.

476{
477 (void) Strncpy(dst, parent, siz);
479 return (Strncat(dst, fname, siz));
480} /* Path */
r parent
Definition: btrfs.c:3010
#define LOCAL_PATH_DELIM_STR
Definition: ncftp.h:493

◆ PathCat()

void PathCat ( char *const  dst,
const size_t  dsize,
const char *const  cwd,
const char *const  src 
)

Definition at line 368 of file util.c.

369{
370 char *cp;
371 char tmp[512];
372
373 if (src[0] == '/') {
374 CompressPath(dst, src, dsize);
375 return;
376 }
377 cp = Strnpcpy(tmp, (char *) cwd, sizeof(tmp) - 1);
378 *cp++ = '/';
379 *cp = '\0';
380 (void) Strnpcat(cp, (char *) src, sizeof(tmp) - (cp - tmp));
381 CompressPath(dst, tmp, dsize);
382} /* PathCat */
char * Strnpcpy(char *const, const char *const, size_t)
Definition: Strnpcpy.c:12
char * Strnpcat(char *const, const char *const, size_t)
Definition: Strnpcat.c:16
void CompressPath(char *const dst, const char *const src, const size_t dsize)
Definition: util.c:247

Referenced by Chdirs(), FileToURL(), Ls(), nFTPChdirAndGetCWD(), and RemoteCompletionFunction().

◆ StrToBool()

int StrToBool ( const char *const  s)

Definition at line 748 of file util.c.

749{
750 int c;
751 int result;
752
753 c = *s;
754 if (isupper(c))
755 c = tolower(c);
756 result = 0;
757 switch (c) {
758 case 'f': /* false */
759 /*FALLTHROUGH*/
760 case 'n': /* no */
761 break;
762 case 'o': /* test for "off" and "on" */
763 c = (int) s[1];
764 if (isupper(c))
765 c = tolower(c);
766 if (c == 'f')
767 break;
768 /*FALLTHROUGH*/
769 case 't': /* true */
770 /*FALLTHROUGH*/
771 case 'y': /* yes */
772 result = 1;
773 break;
774 default: /* 1, 0, -1, other number? */
775 if (atoi(s) != 0)
776 result = 1;
777 }
778 return result;
779} /* StrToBool */
#define isupper(c)
Definition: acclib.h:71
int tolower(int c)
Definition: utclib.c:902
GLuint64EXT * result
Definition: glext.h:11304
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)

Referenced by SaveCurrentAsBookmark(), SetAutoResume(), SetAutoSaveChangesToExistingBookmarks(), SetConfirmClose(), SetNoAds(), SetSavePasswords(), and SetXtTitle().

◆ ToBase64()

void ToBase64 ( void dst0,
const void src0,
size_t  n,
int  terminate 
)

Definition at line 83 of file util.c.

84{
85 unsigned char *dst;
86 const unsigned char *src, *srclim;
87 unsigned int c0, c1, c2;
88 unsigned int ch;
89
90 src = src0;
91 srclim = src + n;
92 dst = dst0;
93
94 while (src < srclim) {
95 c0 = *src++;
96 if (src < srclim) {
97 c1 = *src++;
98 } else {
99 c1 = 0;
100 }
101 if (src < srclim) {
102 c2 = *src++;
103 } else {
104 c2 = 0;
105 }
106
107 ch = c0 >> 2;
108 dst[0] = B64EncodeTable[ch & 077];
109
110 ch = ((c0 << 4) & 060) | ((c1 >> 4) & 017);
111 dst[1] = B64EncodeTable[ch & 077];
112
113 ch = ((c1 << 2) & 074) | ((c2 >> 6) & 03);
114 dst[2] = B64EncodeTable[ch & 077];
115
116 ch = (c2 & 077);
117 dst[3] = B64EncodeTable[ch & 077];
118
119 dst += 4;
120 }
121 if (terminate != 0)
122 *dst = '\0';
123} /* ToBase64 */
static const unsigned char B64EncodeTable[64]
Definition: util.c:34

Referenced by SpoolX(), and WriteBmLine().

◆ UnDate()

time_t UnDate ( char dstr)

Definition at line 917 of file util.c.

918{
919#ifndef HAVE_MKTIME
920 return ((time_t) -1);
921#else
922 struct tm ut, *t;
923 time_t now;
924 time_t result = (time_t) -1;
925
926 (void) time(&now);
927 t = localtime(&now);
928
929 /* Copy the whole structure of the 'tm' pointed to by t, so it will
930 * also set all fields we don't specify explicitly to be the same as
931 * they were in t. That way we copy non-standard fields such as
932 * tm_gmtoff, if it exists or not.
933 */
934 ut = *t;
935
936 /* The time we get back from the server is (should be) in UTC. */
937 if (sscanf(dstr, "%04d%02d%02d%02d%02d%02d",
938 &ut.tm_year,
939 &ut.tm_mon,
940 &ut.tm_mday,
941 &ut.tm_hour,
942 &ut.tm_min,
943 &ut.tm_sec) == 6)
944 {
945 --ut.tm_mon;
946 ut.tm_year -= 1900;
947 result = mktime(&ut);
948 }
949 return result;
950#endif /* HAVE_MKTIME */
951} /* UnDate */
__kernel_time_t time_t
Definition: linux.h:252
time_t now
Definition: finger.c:65
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
__u16 time
Definition: mkdosfs.c:8
_CRTIMP time_t __cdecl mktime(struct tm *_Tm)
Definition: time.h:418
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)
Definition: time.h:416
Definition: time.h:68

Referenced by GetStartSpoolDate().

Variable Documentation

◆ B64DecodeTable

const unsigned char B64DecodeTable[256]
static

Definition at line 46 of file util.c.

Referenced by FromBase64().

◆ B64EncodeTable

const unsigned char B64EncodeTable[64]
static
Initial value:
=
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
}

Definition at line 34 of file util.c.

Referenced by ToBase64().

◆ gGetHostByNameJmp

jmp_buf gGetHostByNameJmp

Definition at line 27 of file util.c.

Referenced by CancelGetHostByName(), and GetHostByName().

◆ gHome

char gHome[256]

Definition at line 15 of file util.c.

Referenced by InitOurDirectory(), and InitUserInfo().

◆ gOurDirectoryPath

◆ gOurInstallationPath

char gOurInstallationPath[260]

Definition at line 18 of file util.c.

Referenced by InitOurDirectory(), and OurInstallationPath().

◆ gShell

char gShell[256]

Definition at line 16 of file util.c.

Referenced by InitUserInfo().

◆ gUid

uid_t gUid

Definition at line 13 of file util.c.

Referenced by GetScreenColumns(), and InitUserInfo().

◆ gUser

char gUser[32]

Definition at line 14 of file util.c.

Referenced by InitOurDirectory(), and InitUserInfo().