Netatalk utility functions. More...
#include <poll.h>#include <stdbool.h>#include <sys/socket.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>#include <bstrlib.h>#include <netatalk/at.h>#include <atalk/cnid.h>#include <atalk/unicode.h>Go to the source code of this file.
Data Structures | |
| struct | asev_data |
| atalk socket event data More... | |
| struct | asev |
| atalk socket event More... | |
Macros | |
| #define | RLIM_MAX 65535 |
| #define | EXITERR_CLNT 1 |
| #define | EXITERR_CONF 2 |
| #define | EXITERR_SYS 3 |
| #define | EXITERR_CLOSED 4 |
| #define | AFP_PANIC(why) |
| #define | AFP_ASSERT(b) |
| #define | MIN(a, b) |
| #define | MAX(a, b) |
| #define | STRCMP(a, b, c) |
| #define | ZERO_STRUCT(a) |
| #define | ZERO_STRUCTP(a) |
| #define | hton64(x) |
| #define | ntoh64(x) |
| #define | SAFE_FREE(x) |
| #define | diatolower(x) |
| #define | diatoupper(x) |
| #define | server_unlock(x) |
| #define | mod_error() |
| #define | strequal(a, b) |
| #define | cfrombstr(b) |
| #define | BSTRING_STRIP_SLASH(a) |
| #define | read_lock(fd, offset, whence, len) |
| place read lock on file | |
| #define | write_lock(fd, offset, whence, len) |
| place write lock on file | |
| #define | unlock(fd, offset, whence, len) |
| unlock a file | |
Enumerations | |
| enum | asev_fdtype { IPC_FD , LISTEN_FD } |
Functions | |
| ssize_t | sys_sendfile (int __out_fd, int __in_fd, off_t *__offset, size_t __count) |
| char ** | getifacelist (void) |
| Get interfaces from the kernel. | |
| void | freeifacelist (char **) |
| int | atalk_aton (char *, struct at_addr *) |
| Check whether "cp" is a valid ascii representation of an AppleTalk address and convert to a binary address. | |
| void | bprint (char *, int) |
| int | strdiacasecmp (const char *, const char *) |
| int | strndiacasecmp (const char *, const char *, size_t) |
| pid_t | server_lock (char *, char *, int) |
| int | check_lockfile (const char *program, const char *pidfile) |
| int | create_lockfile (const char *program, const char *pidfile) |
| void | fault_setup (void(*fn)(void *)) |
| void | netatalk_panic (const char *why) |
| void * | mod_open (const char *) |
| void * | mod_symbol (void *, const char *) |
| void | mod_close (void *) |
| int | lock_reg (int fd, int cmd, int type, off_t offest, int whence, off_t len) |
| lock a file with fctnl | |
| int | setnonblock (int fd, int cmd) |
| set or unset non-blocking IO on a fd | |
| ssize_t | readt (int socket, void *data, const size_t length, int setnonblocking, int timeout) |
| non-blocking drop-in replacement for read with timeout using select | |
| ssize_t | writet (int socket, void *data, const size_t length, int setnonblocking, int timeout) |
| non-blocking drop-in replacement for read with timeout using select | |
| const char * | getip_string (const struct sockaddr *sa) |
| convert an IPv4 or IPv6 address to a static string using inet_ntop | |
| unsigned int | getip_port (const struct sockaddr *sa) |
| return port number from struct sockaddr | |
| void | apply_ip_mask (struct sockaddr *ai, int maskbits) |
| apply netmask to IP (v4 or v6) | |
| int | compare_ip (const struct sockaddr *sa1, const struct sockaddr *sa2) |
| compare IP addresses for equality | |
| int | tokenize_ip_port (const char *ipurl, char **address, char **port) |
| Tokenize IP(4/6) addresses with an optional port into address and port. | |
| struct asev * | asev_init (int max) |
| bool | asev_add_fd (struct asev *sev, int fd, enum asev_fdtype fdtype, void *private, int protocol) |
| Add a fd to a dynamic pollfd array and associated data array. | |
| bool | asev_del_fd (struct asev *sev, int fd) |
| Remove fd from asev. | |
| int | send_fd (int socket, int fd) |
| int | recv_fd (int fd, int nonblocking) |
| Receive a fd on a suitable socket. | |
| const char * | getcwdpath (void) |
| get cwd in static buffer | |
| const char * | fullpathname (const char *) |
| Request absolute path. | |
| char * | stripped_slashes_basename (char *p) |
| Takes a buffer with a path, strips slashs, returns basename. | |
| void | randombytes (void *buf, int n) |
| int | daemonize (void) |
| Fork, exit parent, setsid(), chdir("/"), close all fds. | |
| int | run_cmd (const char *cmd, char **cmd_argv) |
| char * | realpath_safe (const char *path) |
| const char * | basename_safe (const char *path) |
| safe basename() replacement | |
| char * | strtok_quote (char *s, const char *delim) |
| extended strtok allows the quoted strings | |
| const char * | tmpdir (void) |
| Find a suitable temporary directory for Netatalk. | |
| int | ochdir (const char *dir, int options) |
| symlink safe chdir replacement | |
| int | ostat (const char *path, struct stat *buf, int options) |
| int | ostatat (int dirfd, const char *path, struct stat *st, int options) |
| ostat/fsstatat multiplexer | |
| int | ochown (const char *path, uid_t owner, gid_t group, int options) |
| int | ochmod (char *path, mode_t mode, const struct stat *st, int options) |
| chmod() wrapper for symlink and ACL handling | |
| bstring | rel_path_in_vol (const char *path, const char *volpath) |
| Build path relative to volume root. | |
| cnid_t | cnid_for_path (struct _cnid_db *cdb, const char *volpath, const char *path, cnid_t *did) |
| Resolves CNID of a given path. | |
| char * | uuid_strip_dashes (const char *uuid) |
| void | initline (int, char *) |
| int | parseline (int, char *) |
| char * | convert_utf8_to_mac (const struct vol *vol, const char *upath) |
| Convert a UTF-8 filename to a mangled Mac filename. | |
Variables | |
| const int | _diacasemap [] |
| const int | _dialowermap [] |
Netatalk utility functions.
Utility functions for these areas:
| #define AFP_ASSERT | ( | b | ) |
LOG assert errors
| #define AFP_PANIC | ( | why | ) |
Print a SBT and exit
| #define BSTRING_STRIP_SLASH | ( | a | ) |
strip slashes from end of a bstring
| #define diatolower | ( | x | ) |
| #define diatoupper | ( | x | ) |
| #define EXITERR_CLNT 1 |
client related error
| #define EXITERR_CLOSED 4 |
connection was immediately closed after TCP handshake
| #define EXITERR_CONF 2 |
error in config files/cmd line parameters
| #define EXITERR_SYS 3 |
local system error
| #define hton64 | ( | x | ) |
| #define MAX | ( | a, | |
| b ) |
| #define MIN | ( | a, | |
| b ) |
| #define mod_error | ( | ) |
| #define read_lock | ( | fd, | |
| offset, | |||
| whence, | |||
| len ) |
place read lock on file
| [in] | fd | File descriptor |
| [in] | offset | byte offset relative to l_whence |
| [in] | whence | SEEK_SET, SEEK_CUR, SEEK_END |
| [in] | len | no. of bytes (0 means to EOF) |
| #define RLIM_MAX 65535 |
| #define SAFE_FREE | ( | x | ) |
| #define server_unlock | ( | x | ) |
| #define STRCMP | ( | a, | |
| b, | |||
| c ) |
| #define strequal | ( | a, | |
| b ) |
| #define unlock | ( | fd, | |
| offset, | |||
| whence, | |||
| len ) |
unlock a file
| [in] | fd | File descriptor |
| [in] | offset | byte offset relative to l_whence |
| [in] | whence | SEEK_SET, SEEK_CUR, SEEK_END |
| [in] | len | no. of bytes (0 means to EOF) |
| #define write_lock | ( | fd, | |
| offset, | |||
| whence, | |||
| len ) |
place write lock on file
| [in] | fd | File descriptor |
| [in] | offset | byte offset relative to l_whence |
| [in] | whence | SEEK_SET, SEEK_CUR, SEEK_END |
| [in] | len | no. of bytes (0 means to EOF) |
| #define ZERO_STRUCT | ( | a | ) |
| #define ZERO_STRUCTP | ( | a | ) |
| enum asev_fdtype |
|
extern |
apply netmask to IP (v4 or v6)
Modifies IP address in sa->sin[6]_addr-s[6]_addr. The caller is responsible for passing a value for mask that is sensible to the passed address, e.g. 0 <= mask <= 32 for IPv4 or 0<= mask <= 128 for IPv6. mask > 32 for IPv4 is treated as mask = 32, mask > 128 is set to 128 for IPv6.
| [in,out] | sa | pointer to an struct sockaddr |
| [in] | mask | number of maskbits |
|
extern |
Add a fd to a dynamic pollfd array and associated data array.
This uses an additional array of struct polldata which stores type information (enum fdtype) and a pointer to anciliary user data.
|
extern |
Remove fd from asev.
|
extern |
Allocate and initialize atalk socket event struct
|
extern |
Check whether "cp" is a valid ascii representation of an AppleTalk address and convert to a binary address.
Examples of accepted forms are (in decimal, net of 4321, node of 65):
If hex is used, and the first digit is one of A-F, the leading 0x is redundant. Returns 1 if the address is valid, 0 if not.
Unlike Internet addresses, AppleTalk addresses can have leading 0's. This means that we can't support octal addressing.
|
extern |
safe basename() replacement
|
extern |
|
extern |
Check lockfile
|
extern |
Resolves CNID of a given path.
path might be:
path MUST be pointing inside vol, this is usually the case as vol has been build from path using loadvolinfo and friends.
| [in] | cdb | CNID db handle |
| [in] | volpath | UNIX path of volume |
| [in] | path | path, see above |
| [out] | did | parent CNID of returned CNID |
|
extern |
compare IP addresses for equality
| [in] | sa1 | pointer to an struct sockaddr |
| [in] | sa2 | pointer to an struct sockaddr |
|
extern |
Convert a UTF-8 filename to a mangled Mac filename.
| vol | volume structure |
| upath | input path in UTF-8 |
|
extern |
Check and create lockfile
|
extern |
Fork, exit parent, setsid(), chdir("/"), close all fds.
|
extern |
setup our fault handlers
|
extern |
go through and free the interface list
|
extern |
Request absolute path.
|
extern |
get cwd in static buffer
|
extern |
Get interfaces from the kernel.
|
extern |
return port number from struct sockaddr
| [in] | sa | pointer to an struct sockaddr |
|
extern |
convert an IPv4 or IPv6 address to a static string using inet_ntop
IPv6 mapped IPv4 addresses are returned as IPv4 addreses e.g. ::ffff:10.0.0.0 is returned as "10.0.0.0".
| [in] | sa | pointer to an struct sockaddr |
|
extern |
|
extern |
lock a file with fctnl
This function is called via the macros: read_lock, write_lock, un_lock
| [in] | fd | File descriptor |
| [in] | cmd | cmd to fcntl, only F_SETLK is usable here |
| [in] | type | F_RDLCK, F_WRLCK, F_UNLCK |
| [in] | offset | byte offset relative to l_whence |
| [in] | whence | SEEK_SET, SEEK_CUR, SEEK_END |
| [in] | len | no. of bytes (0 means to EOF) |
|
extern |
|
extern |
|
extern |
|
extern |
Something really nasty happened - panic !
|
extern |
symlink safe chdir replacement
Only chdirs to dir if it doesn't contain symlinks or if symlink checking is disabled
|
extern |
chmod() wrapper for symlink and ACL handling
| [in] | path | path |
| [in] | mode | requested mode |
| [in] | st | stat() of path or NULL |
| [in] | options | O_NOFOLLOW | O_NETATALK_ACL |
Option descriptions:
|
extern |
|
extern |
|
extern |
ostat/fsstatat multiplexer
ostatat mulitplexes ostat and fstatat.
| [in] | dirfd | -1 gives AT_FDCWD |
| [in] | path | pathname |
| [in,out] | st | pointer to struct stat |
| [in] | options | file options |
|
extern |
|
extern |
Store n random bytes an buf
|
extern |
non-blocking drop-in replacement for read with timeout using select
| [in] | socket | socket, if in blocking mode, pass "setnonblocking" arg as 1 |
| [in,out] | data | buffer for the read data |
| [in] | length | how many bytes to read |
| [in] | setnonblocking | when non-zero this func will enable and disable non blocking io mode for the socket |
| [in] | timeout | number of seconds to try reading, 0 means no timeout |
|
extern |
realpath() replacement that always allocates storage for returned path
|
extern |
Receive a fd on a suitable socket.
| [in] | fd | PF_UNIX socket to receive on |
| [in] | nonblocking | 0: fd is in blocking mode - 1: fd is nonblocking, poll for 1 sec |
|
extern |
Build path relative to volume root.
path might be:
| [in] | path | path relative to cwd() or absolute |
| [in] | volpath | volume path that path is a subdir of (has been computed in volinfo funcs) |
|
extern |
Run command in a child and wait for it to finish
|
extern |
Send a fd across a suitable socket
|
extern |
this creates an open lock file which hangs around until the program dies. it returns the pid. due to problems w/ solaris, this has been changed to do the kill() thing.
|
extern |
set or unset non-blocking IO on a fd
| [in] | fd | File descriptor |
| [in] | cmd | 0: disable non-blocking IO, i.e. block <>0: enable non-blocking IO |
|
extern |
|
extern |
Takes a buffer with a path, strips slashs, returns basename.
| p | (rw) path |
path may be
or
Result is "file" or "dir"
|
extern |
|
extern |
extended strtok allows the quoted strings
modified strtok.c in glibc 2.0.6
|
extern |
|
extern |
Find a suitable temporary directory for Netatalk.
Creates a subdirectory for current gid if it doesn't exist. The result should be copied immediately as it may be overwritten by a subsequent call.
|
extern |
Tokenize IP(4/6) addresses with an optional port into address and port.
| [in] | ipurl | IP URL string |
| [out] | address | IP address |
| [out] | port | IP port |
Tokenize IPv4, IPv4:port, IPv6, [IPv6] or [IPv6:port] URL into address and port and return two allocated strings with the address and the port.
If the function returns 0, then address point to a newly allocated valid address string, port may either be NULL or point to a newly allocated port number.
If the function returns -1, then the contents of address and port are undefined.
|
extern |
Return allocated UUID string with dashes stripped
|
extern |
non-blocking drop-in replacement for read with timeout using select
| [in] | socket | socket, if in blocking mode, pass "setnonblocking" arg as 1 |
| [in,out] | data | buffer for the read data |
| [in] | length | how many bytes to read |
| [in] | setnonblocking | when non-zero this func will enable and disable non blocking io mode for the socket |
| [in] | timeout | number of seconds to try reading |
|
extern |
| const int _dialowermap[] |