/*===========================================================================* * verify_dentry * *===========================================================================*/ int verify_dentry( struct inode *parent, /* parent inode: the inode to verify */ char name[NAME_MAX+1], /* the given directory entry path component */ char path[PATH_MAX], /* buffer to store the resulting path in */ struct inode **res_ino /* pointer for addressed inode (or NULL) */ ) { /* Given a directory inode and a name, construct a path identifying that * directory entry, check whether the path to the parent is still valid, and * check whether there is an inode pointed to by the full path. Upon success, * res_ino will contain either the inode for the full path, with increased * refcount, or NULL if no such inode exists. */ int r; if ((r = verify_inode(parent, path, NULL)) != OK) return r; dprintf(("%s: verify_dentry: given path is '%s', name '%s'\n", sffs_name, path, name)); if ((r = push_path(path, name)) != OK) return r; dprintf(("%s: verify_dentry: path now '%s'\n", sffs_name, path)); *res_ino = lookup_dentry(parent, name); return OK; }
/*===========================================================================* * go_down * *===========================================================================*/ static int go_down( char path[PATH_MAX], /* path to add the name to */ struct inode *parent, /* inode of the current directory */ char *name, /* name of the directory entry */ struct inode **res_ino, /* place to store resulting inode */ struct sffs_attr *attr /* place to store inode attributes */ ) { /* Given a directory inode and a name, progress into a directory entry. */ struct inode *ino; int r, stale = 0; if ((r = push_path(path, name)) != OK) return r; dprintf(("%s: go_down: name '%s', path now '%s'\n", sffs_name, name, path)); ino = lookup_dentry(parent, name); dprintf(("%s: lookup_dentry('%s') returned %p\n", sffs_name, name, ino)); if (ino != NULL) r = verify_path(path, ino, attr, &stale); else r = sffs_table->t_getattr(path, attr); dprintf(("%s: path query returned %d\n", sffs_name, r)); if (r != OK) { if (ino != NULL) { put_inode(ino); ino = NULL; } if (!stale) return r; } dprintf(("%s: name '%s'\n", sffs_name, name)); if (ino == NULL) { if ((ino = get_free_inode()) == NULL) return ENFILE; dprintf(("%s: inode %p ref %d\n", sffs_name, ino, ino->i_ref)); ino->i_flags = MODE_TO_DIRFLAG(attr->a_mode); add_dentry(parent, name, ino); } *res_ino = ino; return OK; }
int createfile(AFPObj *obj, uint16_t vid, cnid_t did, const char *name) { const int bufsize = 256; char buf[bufsize]; char *p = buf; int len = 0; PUSHVAL(p, uint16_t, htons(128), len); /* hard create */ PUSHVAL(p, uint16_t, vid, len); PUSHVAL(p, cnid_t, did, len); len += push_path(&p, name); return afp_createfile(obj, buf, len, rbuf, &rbuflen); }
int createdir(AFPObj *obj, uint16_t vid, cnid_t did, const char *name) { const int bufsize = 256; char buf[bufsize]; char *p = buf; int len = 0; ADD(p, len , 2); PUSHVAL(p, uint16_t, vid, len); PUSHVAL(p, cnid_t, did, len); len += push_path(&p, name); return afp_createdir(obj, buf, len, rbuf, &rbuflen); }
int getfiledirparms(AFPObj *obj, uint16_t vid, cnid_t did, const char *name) { const int bufsize = 256; char buf[bufsize]; char *p = buf; int len = 0; ADD(p, len , 2); PUSHVAL(p, uint16_t, vid, len); PUSHVAL(p, cnid_t, did, len); PUSHVAL(p, uint16_t, htons(FILPBIT_FNUM | FILPBIT_PDINFO), len); PUSHVAL(p, uint16_t, htons(DIRPBIT_DID | DIRPBIT_PDINFO), len); len += push_path(&p, name); return afp_getfildirparams(obj, buf, len, rbuf, &rbuflen); }
int main(int argc, char *argv[]) { char directory_path[PATH_MAX]; int error; strlcpy(directory_path, "/tmp/unix_bind.XXXXXXX", PATH_MAX); if (mkdtemp(directory_path) == NULL) err(-1, "mkdtemp"); push_path(directory_path); error = bind_test(directory_path); if (error == 0) error = connect_test(directory_path); unwind(); return (error); }
void run_app(t_app *app) { t_p_arg *tmp; t_p_arg *tmp2; read_arg(app); check_invalide(app); print_file(app); tmp = (app->reverse_sort) ? app->last_p_arg : app->first_p_arg; while (tmp) { tmp2 = (app->reverse_sort) ? tmp->previous : tmp->next; push_path(app, tmp->path); parcour(app); pop_path(app); free(tmp); tmp = tmp2; } }
void PredicateChecker::handle_boolean(const std::string &key, const bool value) { push_path(key); Document view(m_document, path_string(m_path), false); if(view.empty() || (view.get_type() != ObjectType::True && view.get_type() != ObjectType::False)) { m_matched = false; } else { bool other = view.as_boolean(); if(other != value) { m_matched = false; } } pop_path(); }
void PredicateChecker::handle_array_start(const std::string &key) { push_path(key); }
void PredicateChecker::handle_float(const std::string &key, const json::float_t value) { push_path(key); if(mode() == predicate_mode::NORMAL) { Document view(m_document, path_string(m_path), false); if(view.empty() || view.get_type() != ObjectType::Float) { m_matched = false; } else { json::float_t other = view.as_float(); if(other != value) { m_matched = false; } } } else if(mode() == predicate_mode::IN) { for(auto &val: m_pred_values) { if(val.type == ObjectType::Float && val.floating == value) { m_pred_matches = true; } else if(val.type == ObjectType::Integer && val.integer == value) { m_pred_matches = true; } } } else if(mode() == predicate_mode::LESS_THAN) { for(auto &val: m_pred_values) { if(val.type == ObjectType::Float && val.floating < value) { m_pred_matches = true; } else if(val.type == ObjectType::Integer && val.integer < value) { m_pred_matches = true; } } } else if(mode() == predicate_mode::LESS_THAN_EQUAL) { for(auto &val: m_pred_values) { if(val.type == ObjectType::Float && val.floating <= value) { m_pred_matches = true; } else if(val.type == ObjectType::Integer && val.integer <= value) { m_pred_matches = true; } } } else if(mode() == predicate_mode::GREATER_THAN) { for(auto &val: m_pred_values) { if(val.type == ObjectType::Float && val.floating > value) { m_pred_matches = true; } else if(val.type == ObjectType::Integer && val.integer > value) { m_pred_matches = true; } } } else if(mode() == predicate_mode::GREATER_THAN_EQUAL) { for(auto &val: m_pred_values) { if(val.type == ObjectType::Float && val.floating >= value) { m_pred_matches = true; } else if(val.type == ObjectType::Integer && val.integer >= value) { m_pred_matches = true; } } } else if(mode() == predicate_mode::EQUAL) { for(auto &val: m_pred_values) { if(val.type == ObjectType::Float && val.floating == value) { m_pred_matches = true; } else if(val.type == ObjectType::Integer && val.integer == value) { m_pred_matches = true; } } } else if(mode() == predicate_mode::NOT_EQUAL) { for(auto &val: m_pred_values) { if(val.type == ObjectType::Float && val.floating != value) { m_pred_matches = true; } else if(val.type == ObjectType::Integer && val.integer != value) { m_pred_matches = true; } } } pop_path(); }
void PredicateChecker::handle_string(const std::string &key, const std::string &value) { push_path(key); if(mode() == predicate_mode::NORMAL) { bool found = false; for(auto &path: path_strings(m_path, m_document)) { Document view(m_document, path, false); if(view.empty() || view.get_type() != ObjectType::String) { continue; } std::string other = view.as_string(); if(other == value) { found = true; } } if(!found) { m_matched = false; } } else { if(mode() == predicate_mode::EQUAL) { for(auto &val: m_pred_values) { if(val.type == ObjectType::String && val.str == value) { m_pred_matches = true; } } } else if(mode() == predicate_mode::IN) { for(auto &val: m_pred_values) { if(val.type == ObjectType::String && val.str == value) { m_pred_matches = true; } } } else if(mode() == predicate_mode::NOT_EQUAL) { for(auto &val: m_pred_values) { if(val.type == ObjectType::String && val.str != value) { m_pred_matches = true; } } } } pop_path(); }
static int bind_test(const char *directory_path) { char socket_path[PATH_MAX]; struct sockaddr_un sun; int sock1, sock2; sock1 = socket(PF_UNIX, SOCK_STREAM, 0); if (sock1 < 0) { warn("bind_test: socket(PF_UNIX, SOCK_STREAM, 0)"); return (-1); } if (snprintf(socket_path, sizeof(socket_path), "%s/%s", directory_path, SOCK_NAME_ONE) >= PATH_MAX) { warn("bind_test: snprintf(socket_path)"); close(sock1); return (-1); } bzero(&sun, sizeof(sun)); sun.sun_len = sizeof(sun); sun.sun_family = AF_UNIX; if (snprintf(sun.sun_path, sizeof(sun.sun_path), "%s", socket_path) >= sizeof(sun.sun_path)) { warn("bind_test: snprintf(sun.sun_path)"); close(sock1); return (-1); } if (bind(sock1, (struct sockaddr *)&sun, sizeof(sun)) < 0) { warn("bind_test: bind(sun) #1"); close(sock1); return (-1); } push_path(socket_path); /* * Once a STREAM UNIX domain socket has been bound, it can't be * rebound. Expected error is EINVAL. */ if (bind(sock1, (struct sockaddr *)&sun, sizeof(sun)) == 0) { warnx("bind_test: bind(sun) #2 succeeded"); close(sock1); return (-1); } if (errno != EINVAL) { warn("bind_test: bind(sun) #2"); close(sock1); return (-1); } sock2 = socket(PF_UNIX, SOCK_STREAM, 0); if (sock2 < 0) { warn("bind_test: socket(PF_UNIX, SOCK_STREAM, 0)"); close(sock1); return (-1); } /* * Since a socket is already bound to the pathname, it can't be bound * to a second socket. Expected error is EADDRINUSE. */ if (bind(sock2, (struct sockaddr *)&sun, sizeof(sun)) == 0) { warnx("bind_test: bind(sun) #3 succeeded"); close(sock1); close(sock2); return (-1); } if (errno != EADDRINUSE) { warn("bind_test: bind(sun) #2"); close(sock1); close(sock2); return (-1); } close(sock1); /* * The socket bound to the pathname has been closed, but the pathname * can't be reused without first being unlinked. Expected error is * EADDRINUSE. */ if (bind(sock2, (struct sockaddr *)&sun, sizeof(sun)) == 0) { warnx("bind_test: bind(sun) #4 succeeded"); close(sock2); return (-1); } if (errno != EADDRINUSE) { warn("bind_test: bind(sun) #4"); close(sock2); return (-1); } unlink(socket_path); /* * The pathname is now free, so the socket should be able to bind to * it. */ if (bind(sock2, (struct sockaddr *)&sun, sizeof(sun)) < 0) { warn("bind_test: bind(sun) #5"); close(sock2); return (-1); } close(sock2); return (0); }
static int connect_test(const char *directory_path) { char socket_path[PATH_MAX]; struct sockaddr_un sun; int sock1, sock2; sock1 = socket(PF_UNIX, SOCK_STREAM, 0); if (sock1 < 0) { warn("connect_test: socket(PF_UNIX, SOCK_STREAM, 0)"); return (-1); } if (snprintf(socket_path, sizeof(socket_path), "%s/%s", directory_path, SOCK_NAME_TWO) >= PATH_MAX) { warn("connect_test: snprintf(socket_path)"); close(sock1); return (-1); } bzero(&sun, sizeof(sun)); sun.sun_len = sizeof(sun); sun.sun_family = AF_UNIX; if (snprintf(sun.sun_path, sizeof(sun.sun_path), "%s", socket_path) >= sizeof(sun.sun_path)) { warn("connect_test: snprintf(sun.sun_path)"); close(sock1); return (-1); } /* * Try connecting to a path that doesn't yet exist. Should fail with * ENOENT. */ if (connect(sock1, (struct sockaddr *)&sun, sizeof(sun)) == 0) { warnx("connect_test: connect(sun) #1 succeeded"); close(sock1); return (-1); } if (errno != ENOENT) { warn("connect_test: connect(sun) #1"); close(sock1); return (-1); } if (bind(sock1, (struct sockaddr *)&sun, sizeof(sun)) < 0) { warn("connect_test: bind(sun) #1"); close(sock1); return (-1); } if (listen(sock1, 3) < 0) { warn("connect_test: listen(sock1)"); close(sock1); return (-1); } push_path(socket_path); sock2 = socket(PF_UNIX, SOCK_STREAM, 0); if (sock2 < 0) { warn("socket(PF_UNIX, SOCK_STREAM, 0)"); close(sock1); return (-1); } /* * Do a simple connect and make sure that works. */ if (connect(sock2, (struct sockaddr *)&sun, sizeof(sun)) < 0) { warn("connect(sun) #2"); close(sock1); return (-1); } close(sock2); close(sock1); sock2 = socket(PF_UNIX, SOCK_STREAM, 0); if (sock2 < 0) { warn("socket(PF_UNIX, SOCK_STREAM, 0)"); return (-1); } /* * Confirm that once the listen socket is closed, we get a * connection refused (ECONNREFUSED) when attempting to connect to * the pathname. */ if (connect(sock2, (struct sockaddr *)&sun, sizeof(sun)) == 0) { warnx("connect(sun) #3 succeeded"); close(sock2); return (-1); } if (errno != ECONNREFUSED) { warn("connect(sun) #3"); close(sock2); return (-1); } close(sock2); unlink(socket_path); return (0); }
void push_cfg_path(const char *new_comp) { push_path(mutable_cfg_path, new_comp); };
////// virtual functions defined in base class // begin path modifiers void push_tmpl_path(const char *new_comp) { push_path(tmpl_path, new_comp); };