version 1.17, 2003/04/05 20:31:58 |
version 1.18, 2003/04/19 17:22:29 |
|
|
* Function to actually send the command char and message to the |
* Function to actually send the command char and message to the |
* remote host. |
* remote host. |
*/ |
*/ |
static int sendcmdmsg(cmd, msg) |
static int sendcmdmsg(cmd, msg, msgsize) |
char cmd; |
char cmd; |
char *msg; |
char *msg; |
|
size_t msgsize; |
{ |
{ |
int len; |
int len; |
|
|
|
|
* All commands except C_NONE should have a newline |
* All commands except C_NONE should have a newline |
*/ |
*/ |
if (cmd != C_NONE && !strchr(msg + 1, '\n')) |
if (cmd != C_NONE && !strchr(msg + 1, '\n')) |
(void) strcat(msg + 1, "\n"); |
(void) strlcat(msg + 1, "\n", msgsize - 1); |
|
|
if (cmd == C_NONE) |
if (cmd == C_NONE) |
len = strlen(msg); |
len = strlen(msg); |
|
|
|
|
va_start(args, fmt); |
va_start(args, fmt); |
if (fmt) |
if (fmt) |
(void) vsprintf((cmd == C_NONE) ? buf : buf + 1, fmt, args); |
(void) vsnprintf(buf + (cmd != C_NONE), |
|
sizeof(buf) - (cmd != C_NONE), fmt, args); |
else |
else |
buf[1] = CNULL; |
buf[1] = CNULL; |
va_end(args); |
va_end(args); |
|
|
return(sendcmdmsg(cmd, buf)); |
return(sendcmdmsg(cmd, buf, sizeof(buf))); |
} |
} |
#endif /* ARG_TYPE == ARG_STDARG */ |
#endif /* ARG_TYPE == ARG_STDARG */ |
|
|
|
|
cmd = (char) va_arg(args, int); |
cmd = (char) va_arg(args, int); |
fmt = va_arg(args, char *); |
fmt = va_arg(args, char *); |
if (fmt) |
if (fmt) |
(void) vsprintf((cmd == C_NONE) ? buf : buf + 1, fmt, args); |
(void) vsnprintf(buf + (cmd != C_NONE), |
|
sizeof(buf) - (cmd != C_NONE), fmt, args); |
else |
else |
buf[1] = CNULL; |
buf[1] = CNULL; |
va_end(args); |
va_end(args); |
|
|
return(sendcmdmsg(cmd, buf)); |
return(sendcmdmsg(cmd, buf, sizeof(buf))); |
} |
} |
#endif /* ARG_TYPE == ARG_VARARGS */ |
#endif /* ARG_TYPE == ARG_VARARGS */ |
|
|
|
|
static char buf[BUFSIZ]; |
static char buf[BUFSIZ]; |
|
|
if (fmt) |
if (fmt) |
(void) sprintf((cmd == C_NONE) ? buf : buf + 1, |
(void) snprintf(buf + (cmd != C_NONE), |
fmt, a1, a2, a3, a4, a5, a6, a7, a8); |
sizeof(buf) - (cmd != C_NONE), |
|
fmt, a1, a2, a3, a4, a5, a6, a7, a8); |
else |
else |
buf[1] = CNULL; |
buf[1] = CNULL; |
|
|
return(sendcmdmsg(cmd, buf)); |
return(sendcmdmsg(cmd, buf, sizeof(buf))); |
} |
} |
#endif /* !ARG_TYPE */ |
#endif /* !ARG_TYPE */ |
|
|
|
|
* user's home directory path name. Return a pointer in buf to the |
* user's home directory path name. Return a pointer in buf to the |
* part corresponding to `file'. |
* part corresponding to `file'. |
*/ |
*/ |
extern char *exptilde(ebuf, file) |
extern char *exptilde(ebuf, file, ebufsize) |
char *ebuf; |
char *ebuf; |
|
size_t ebufsize; |
char *file; |
char *file; |
{ |
{ |
char *s1, *s2, *s3; |
char *pw_dir, *rest; |
|
size_t len; |
extern char *homedir; |
extern char *homedir; |
|
|
if (*file != '~') { |
if (*file != '~') { |
(void) strcpy(ebuf, file); |
notilde: |
|
(void) strlcpy(ebuf, file, ebufsize); |
return(ebuf); |
return(ebuf); |
} |
} |
if (*++file == CNULL) { |
if (*++file == CNULL) { |
s2 = homedir; |
pw_dir = homedir; |
s3 = NULL; |
rest = NULL; |
} else if (*file == '/') { |
} else if (*file == '/') { |
s2 = homedir; |
pw_dir = homedir; |
s3 = file; |
rest = file; |
} else { |
} else { |
s3 = file; |
rest = file; |
while (*s3 && *s3 != '/') |
while (*rest && *rest != '/') |
s3++; |
rest++; |
if (*s3 == '/') |
if (*rest == '/') |
*s3 = CNULL; |
*rest = CNULL; |
else |
else |
s3 = NULL; |
rest = NULL; |
if (pw == NULL || strcmp(pw->pw_name, file) != 0) { |
if (pw == NULL || strcmp(pw->pw_name, file) != 0) { |
if ((pw = getpwnam(file)) == NULL) { |
if ((pw = getpwnam(file)) == NULL) { |
error("%s: unknown user name", file); |
error("%s: unknown user name", file); |
if (s3 != NULL) |
if (rest != NULL) |
*s3 = '/'; |
*rest = '/'; |
return(NULL); |
return(NULL); |
} |
} |
} |
} |
if (s3 != NULL) |
if (rest != NULL) |
*s3 = '/'; |
*rest = '/'; |
s2 = pw->pw_dir; |
pw_dir = pw->pw_dir; |
} |
} |
for (s1 = ebuf; (*s1++ = *s2++); ) |
if ((len = strlcpy(ebuf, pw_dir, ebufsize)) >= ebufsize) |
; |
goto notilde; |
s2 = --s1; |
pw_dir = ebuf + len; |
if (s3 != NULL) { |
if (rest != NULL) { |
s2++; |
pw_dir++; |
while ((*s1++ = *s3++)) |
if ((len = strlcat(ebuf, rest, ebufsize)) >= ebufsize) |
; |
goto notilde; |
} |
} |
return(s2); |
return(pw_dir); |
} |
} |
|
|
#if defined(DIRECT_RCMD) |
#if defined(DIRECT_RCMD) |